From b91ceb88de6a9b3465fb1825ead43235909563ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 7 Mar 2024 12:39:13 +0000 Subject: [PATCH 1/2] use file to write llvm linker script --- src/bootstrap/src/core/build_steps/dist.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index 6c7cc3bf6a736..8c9f320e1c9c7 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -2046,7 +2046,8 @@ fn install_llvm_file( // projects like miri link against librustc_driver.so. We don't use a symlink, as // these are not allowed inside rustup components. let link = t!(fs::read_link(source)); - t!(std::fs::write(full_dest, format!("INPUT({})\n", link.display()))); + let mut linker_script = t!(fs::File::create(full_dest)); + t!(write!(linker_script, "INPUT({})\n", link.display())); } } else { builder.install(&source, destination, 0o644); From 1c3fe15f6cb666f59f6ca16d741b4d43442f5b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 7 Mar 2024 12:39:51 +0000 Subject: [PATCH 2/2] record mtime in llvm linker script This will avoid rebuilds due to the script being more recent than the rest of the original files. --- src/bootstrap/src/core/build_steps/dist.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index 8c9f320e1c9c7..2d5e861aa1d1c 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -2048,6 +2048,13 @@ fn install_llvm_file( let link = t!(fs::read_link(source)); let mut linker_script = t!(fs::File::create(full_dest)); t!(write!(linker_script, "INPUT({})\n", link.display())); + + // We also want the linker script to have the same mtime as the source, otherwise it + // can trigger rebuilds. + let meta = t!(fs::metadata(source)); + if let Ok(mtime) = meta.modified() { + t!(linker_script.set_modified(mtime)); + } } } else { builder.install(&source, destination, 0o644);