From 3c4f45c2516f1620913a3f2971250a8534165e67 Mon Sep 17 00:00:00 2001 From: Michal Rostecki Date: Wed, 13 Mar 2024 20:22:18 +0100 Subject: [PATCH] integration-test: Prefer system-wide lld over rust-lld 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 #907 --- xtask/src/run.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/xtask/src/run.rs b/xtask/src/run.rs index 8bba7a532..ef96825c5 100644 --- a/xtask/src/run.rs +++ b/xtask/src/run.rs @@ -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)] @@ -55,11 +56,21 @@ 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. + // 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\""); + 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. + "rust-lld" + }; + let config = format!("target.{target}.linker = \"{linker}\""); cmd.args(["--target", target, "--config", &config]); } f(&mut cmd);