Skip to content

Commit

Permalink
integration-test: Prefer system-wide lld over rust-lld
Browse files Browse the repository at this point in the history
rust-lld 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
```

Using system-wide LLD makes the issue disappear.

Fixes aya-rs#907
  • Loading branch information
vadorovsky committed Sep 7, 2024
1 parent 635ed3b commit b3842e3
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions xtask/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::{
use anyhow::{anyhow, bail, Context as _, Result};
use cargo_metadata::{Artifact, CompilerMessage, Message, Target};
use clap::Parser;
use which::which;
use xtask::{exec, Errors, AYA_BUILD_INTEGRATION_BPF};

#[derive(Parser)]
Expand Down Expand Up @@ -55,11 +56,30 @@ 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 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\"");
#[cfg(target_os = "linux")]
let linker = if which("clang").is_ok() && which("lld").is_ok() {
// If clang and lld are available in the system, use them.
"clang"
} else {
// Otherwise, fall back to rust-lld. However, it's unaware of
// system library paths and therefore it might throw "unable to
// find library" errors. When experiencing that, better install an
// LLVM toolchain.
//
// See: https://github.com/rust-lang/rust/issues/130062
//
// If the linked issue gets ever fixed, we could use rust-lld by
// default.
"rust-lld"
};
#[cfg(not(target_os = "linux"))]
// On non-Linux systems, rust-lld should work fine.
let linker = "rust-lld";
let config = format!("target.{target}.linker = \"{linker}\"");
cmd.args(["--target", target, "--config", &config]);
}
f(&mut cmd);
Expand Down

0 comments on commit b3842e3

Please sign in to comment.