Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions cargo-auditable/tests/fixtures/bare_linker/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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"]
8 changes: 8 additions & 0 deletions cargo-auditable/tests/fixtures/bare_linker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "bare_linker"
version = "0.1.0"
edition = "2024"

[dependencies]

[workspace]
3 changes: 3 additions & 0 deletions cargo-auditable/tests/fixtures/bare_linker/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
32 changes: 32 additions & 0 deletions cargo-auditable/tests/it.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Loading