Skip to content

Commit 52045f7

Browse files
committed
integration-test: Set rust-lld as a linker only on macOS
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 ``` Not touching the linker settings is usually the best approach for Linux systems. Native builds pick up the default C toolchain. Cross builds default to GCC cross wrapper, but that's easy to supress with clang and lld using RUSTFLAGS. 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
1 parent 1d272f3 commit 52045f7

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

xtask/src/run.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@ pub fn build<F>(target: Option<&str>, f: F) -> Result<Vec<(String, PathBuf)>>
5555
where
5656
F: FnOnce(&mut Command) -> &mut Command,
5757
{
58-
// Always use rust-lld and -Zbuild-std in case we're cross-compiling.
5958
let mut cmd = Command::new("cargo");
6059
cmd.args(["build", "--message-format=json"]);
6160
if let Some(target) = target {
62-
let config = format!("target.{target}.linker = \"rust-lld\"");
63-
cmd.args(["--target", target, "--config", &config]);
61+
cmd.args(["--target", target]);
62+
// Always use rust-lld on macOS hosts. See
63+
// https://github.com/aya-rs/aya/pull/908#issuecomment-2402813711
64+
#[cfg(target_os = "macos")]
65+
{
66+
let config = format!("target.{target}.linker = \"rust-lld\"");
67+
cmd.args(["--target", target, "--config", &config]);
68+
}
6469
}
6570
f(&mut cmd);
6671

0 commit comments

Comments
 (0)