Skip to content

Commit 25bfa15

Browse files
committed
Manually code-sign after running install_name_tool
1 parent d517333 commit 25bfa15

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/bootstrap/compile.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,11 @@ fn copy_sanitizers(
356356
builder.copy(&runtime.path, &dst);
357357

358358
if target == "x86_64-apple-darwin" || target == "aarch64-apple-darwin" {
359-
// Update the library install name reflect the fact it has been renamed.
360-
let status = Command::new("install_name_tool")
361-
.arg("-id")
362-
.arg(format!("@rpath/{}", runtime.name))
363-
.arg(&dst)
364-
.status()
365-
.expect("failed to execute `install_name_tool`");
366-
assert!(status.success());
359+
// Update the library’s install name to reflect that it has has been renamed.
360+
apple_darwin_update_library_name(&dst, &format!("@rpath/{}", &runtime.name));
361+
// Upon renaming the install name, the code signature of the file will invalidate,
362+
// so we will sign it again.
363+
apple_darwin_sign_file(&dst);
367364
}
368365

369366
target_deps.push(dst);
@@ -372,6 +369,27 @@ fn copy_sanitizers(
372369
target_deps
373370
}
374371

372+
fn apple_darwin_update_library_name(library_path: &Path, new_name: &str) {
373+
let status = Command::new("install_name_tool")
374+
.arg("-id")
375+
.arg(new_name)
376+
.arg(library_path)
377+
.status()
378+
.expect("failed to execute `install_name_tool`");
379+
assert!(status.success());
380+
}
381+
382+
fn apple_darwin_sign_file(file_path: &Path) {
383+
let status = Command::new("codesign")
384+
.arg("-f") // Force to rewrite the existing signature
385+
.arg("-s")
386+
.arg("-")
387+
.arg(file_path)
388+
.status()
389+
.expect("failed to execute `codesign`");
390+
assert!(status.success());
391+
}
392+
375393
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
376394
pub struct StartupObjects {
377395
pub compiler: Compiler,

0 commit comments

Comments
 (0)