integration-test: Prefer system-wide lld over rust-lld on Linux

rust-lld on Linux  is unaware of system libraries and seems like there is
no way to point it to them. That often triggers issues 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
```

More explanation:

https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243/2
https://github.com/rust-lang/rust/issues/130062#issuecomment-2336050640

Fixes #907
pull/908/head
Michal Rostecki 6 months ago
parent 635ed3baed
commit 0107a99b49

@ -55,13 +55,37 @@ pub fn build<F>(target: Option<&str>, f: F) -> Result<Vec<(String, PathBuf)>>
where
F: FnOnce(&mut Command) -> &mut Command,
{
// Always use rust-lld and -Zbuild-std in case we're cross-compiling.
// Always use lld in case we're cross-compiling.
let mut cmd = Command::new("cargo");
cmd.args(["build", "--message-format=json"]);
if let Some(target) = target {
// Using rust-lld directly on Linux does not work, as you are expected
// to invoke a C compiler, which then invokes the linker with necessary
// arguments, like the search path. Invoking linker directly results in
// inability to find the system libraries.
//
// On Rust nightly, the solution is to use `-Zlinker-features=+lld`,
// which tells the C compiler to use rust-lld. However, there is no
// guarantee that the build is going to be performed with nightly
// toolchain, so that's not an option.
//
// On Rust stable, the solution is to invoke lld through clang. That's
// our best bet for now.
//
// https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243/2
// https://github.com/rust-lang/rust/issues/130062#issuecomment-2336050640
#[cfg(target_os = "linux")]
{
let config = format!("target.{target}.rustflags=[\"-C\", \"linker=clang\", \"-C\", \"link-arg=-fuse-ld=lld\"]");
cmd.args(["--target", target, "--config", &config]);
}
#[cfg(not(target_os = "linux"))]
{
// On non-Linux systems, rust-lld should work fine.
let config = format!("target.{target}.linker = \"rust-lld\"");
cmd.args(["--target", target, "--config", &config]);
}
}
f(&mut cmd);
let mut child = cmd

Loading…
Cancel
Save