diff --git a/cargo-auditable/tests/fixtures/bare_linker/.cargo/config.toml b/cargo-auditable/tests/fixtures/bare_linker/.cargo/config.toml new file mode 100644 index 0000000..1287e6b --- /dev/null +++ b/cargo-auditable/tests/fixtures/bare_linker/.cargo/config.toml @@ -0,0 +1,33 @@ +# copied from https://github.com/EFForg/rayhunter/blob/adeeb751667d3b44ba6ad215a1bc0ac73d90ae72/.cargo/config.toml#L1 +# as a motivating example for bare linker support + +[target.aarch64-apple-darwin] +linker = "rust-lld" +rustflags = ["-C", "target-feature=+crt-static"] + +[target.aarch64-unknown-linux-musl] +linker = "rust-lld" +rustflags = ["-C", "target-feature=+crt-static"] + +# apt install build-essential libc6-armhf-cross libc6-dev-armhf-cross gcc-arm-linux-gnueabihf +[target.armv7-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc" +rustflags = ["-C", "target-feature=+crt-static"] + +[target.armv7-unknown-linux-musleabihf] +linker = "rust-lld" +rustflags = ["-C", "target-feature=+crt-static"] + +[target.armv7-unknown-linux-musleabi] +linker = "rust-lld" +rustflags = ["-C", "target-feature=+crt-static"] + +# Disable rust-lld for x86 macOS because the linker crashers when compiling +# the installer in release mode with debug info on. +# [target.x86_64-apple-darwin] +# linker = "rust-lld" +# rustflags = ["-C", "target-feature=+crt-static"] + +[target.x86_64-unknown-linux-musl] +linker = "rust-lld" +rustflags = ["-C", "target-feature=+crt-static"] diff --git a/cargo-auditable/tests/fixtures/bare_linker/Cargo.toml b/cargo-auditable/tests/fixtures/bare_linker/Cargo.toml new file mode 100644 index 0000000..af15949 --- /dev/null +++ b/cargo-auditable/tests/fixtures/bare_linker/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "bare_linker" +version = "0.1.0" +edition = "2024" + +[dependencies] + +[workspace] diff --git a/cargo-auditable/tests/fixtures/bare_linker/src/main.rs b/cargo-auditable/tests/fixtures/bare_linker/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/cargo-auditable/tests/fixtures/bare_linker/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/cargo-auditable/tests/it.rs b/cargo-auditable/tests/it.rs index 960427f..bf3a9ae 100644 --- a/cargo-auditable/tests/it.rs +++ b/cargo-auditable/tests/it.rs @@ -585,3 +585,35 @@ fn test_proc_macro_inner(sbom: bool) { .expect("Could not find 'syn' in the embedded dependency list!"); assert_eq!(syn_info.kind, DependencyKind::Build); } + +#[test] +fn test_bare_linker() { + test_bare_linker_inner(false); + test_bare_linker_inner(true); +} +fn test_bare_linker_inner(sbom: bool) { + // Path to workspace fixture Cargo.toml + let cargo_toml = + PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/bare_linker/Cargo.toml"); + // The motivating example is https://github.com/EFForg/rayhunter/blob/main/.cargo/config.toml + // and the config file fixture is based on that. + // There doesn't seem to be a way to build with a bare linker for GNU targets, only Apple and Musl, + // so this tests really only does anything on those. + let config_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("tests/fixtures/bare_linker/.cargo/config.toml"); + + let bins = run_cargo_auditable( + cargo_toml, + &["--config", config_path.to_str().unwrap()], + &[], + sbom, + ); + eprintln!("Test fixture binary map: {bins:?}"); + + // bare_linker should only depend on itself + let bare_linker_bin = &bins.get("bare_linker").unwrap()[0]; + let dep_info = get_dependency_info(bare_linker_bin); + eprintln!("{bare_linker_bin} dependency info: {dep_info:?}"); + assert!(dep_info.packages.len() == 1); + assert!(dep_info.packages.iter().any(|p| p.name == "bare_linker")); +}