From ce23f2e4a672ceda9d3d30e750c6109ac33f5eb7 Mon Sep 17 00:00:00 2001 From: Michal Rostecki Date: Wed, 13 Mar 2024 20:22:18 +0100 Subject: [PATCH] integration-test: Don't set `rust-lld` as a linker on Linux The recommendation (coming from rust-lang/rust#130062) for Linux hosts is using C compiler driver as a linker, which is able to find system-wide libraries. Using linker binaries directly in `-C linker` (e.g. `-C linker=rust-lld`) often results in errors like: ``` cargo:warning=error: linking with `rust-lld` failed: exit status: 1ger, ppv-lite86, libc... cargo:warning= | cargo:warning= = note: LC_ALL="C" PATH="/home/vadorovsky/.rustup/toolchains/stable-x86_64-un cargo:warning= = note: rust-lld: error: unable to find library -lgcc_s cargo:warning= rust-lld: error: unable to find library -lc cargo:warning= cargo:warning= cargo:warning= cargo:warning=error: aborting due to 1 previous error ``` However, `-C linker=rust-lld` still works the best on macOS, where Rust toolchains come with unwinder and runtime and there is usually no need to link system libraries. Keep setting it only for macOS. Fixes #907 --- xtask/src/run.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/xtask/src/run.rs b/xtask/src/run.rs index 8bba7a532..3ed49c779 100644 --- a/xtask/src/run.rs +++ b/xtask/src/run.rs @@ -55,12 +55,17 @@ pub fn build(target: Option<&str>, f: F) -> Result> where F: FnOnce(&mut Command) -> &mut Command, { - // Always use rust-lld and -Zbuild-std in case we're cross-compiling. let mut cmd = Command::new("cargo"); cmd.args(["build", "--message-format=json"]); if let Some(target) = target { - let config = format!("target.{target}.linker = \"rust-lld\""); - cmd.args(["--target", target, "--config", &config]); + cmd.args(["--target", target]); + // Always use rust-lld on macOS hosts. See + // https://github.com/aya-rs/aya/pull/908#issuecomment-2402813711 + #[cfg(target_os = "macos")] + { + let config = format!("target.{target}.linker = \"rust-lld\""); + cmd.args(["--target", target, "--config", &config]); + } } f(&mut cmd);