Skip to content

Commit 8528b5d

Browse files
committed
Add a test for bare linker configuration
1 parent caa964b commit 8528b5d

4 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# copied from https://github.com/EFForg/rayhunter/blob/adeeb751667d3b44ba6ad215a1bc0ac73d90ae72/.cargo/config.toml#L1
2+
# as a motivating example for bare linker support
3+
4+
[target.aarch64-apple-darwin]
5+
linker = "rust-lld"
6+
rustflags = ["-C", "target-feature=+crt-static"]
7+
8+
[target.aarch64-unknown-linux-musl]
9+
linker = "rust-lld"
10+
rustflags = ["-C", "target-feature=+crt-static"]
11+
12+
# apt install build-essential libc6-armhf-cross libc6-dev-armhf-cross gcc-arm-linux-gnueabihf
13+
[target.armv7-unknown-linux-gnueabihf]
14+
linker = "arm-linux-gnueabihf-gcc"
15+
rustflags = ["-C", "target-feature=+crt-static"]
16+
17+
[target.armv7-unknown-linux-musleabihf]
18+
linker = "rust-lld"
19+
rustflags = ["-C", "target-feature=+crt-static"]
20+
21+
[target.armv7-unknown-linux-musleabi]
22+
linker = "rust-lld"
23+
rustflags = ["-C", "target-feature=+crt-static"]
24+
25+
# Disable rust-lld for x86 macOS because the linker crashers when compiling
26+
# the installer in release mode with debug info on.
27+
# [target.x86_64-apple-darwin]
28+
# linker = "rust-lld"
29+
# rustflags = ["-C", "target-feature=+crt-static"]
30+
31+
[target.x86_64-unknown-linux-musl]
32+
linker = "rust-lld"
33+
rustflags = ["-C", "target-feature=+crt-static"]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "bare_linker"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
8+
[workspace]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

cargo-auditable/tests/it.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,3 +585,28 @@ fn test_proc_macro_inner(sbom: bool) {
585585
.expect("Could not find 'syn' in the embedded dependency list!");
586586
assert_eq!(syn_info.kind, DependencyKind::Build);
587587
}
588+
589+
#[test]
590+
fn test_bare_linker() {
591+
test_bare_linker_inner(false);
592+
test_bare_linker_inner(true);
593+
}
594+
fn test_bare_linker_inner(sbom: bool) {
595+
// Path to workspace fixture Cargo.toml. See that file for overview of workspace members and their dependencies.
596+
let workspace_cargo_toml =
597+
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/bare_linker/Cargo.toml");
598+
599+
// The motivating example is https://github.com/EFForg/rayhunter/blob/main/.cargo/config.toml
600+
// There doesn't seem to be a way to build with a bare linker for GNU targets, only Apple and Musl,
601+
// so this tests really only does anything on those.
602+
603+
let bins = run_cargo_auditable(workspace_cargo_toml, &[], &[], sbom);
604+
eprintln!("Test fixture binary map: {bins:?}");
605+
606+
// bare_linker should only depend on itself
607+
let bare_linker_bin = &bins.get("bare_linker").unwrap()[0];
608+
let dep_info = get_dependency_info(bare_linker_bin);
609+
eprintln!("{bare_linker_bin} dependency info: {dep_info:?}");
610+
assert!(dep_info.packages.len() == 1);
611+
assert!(dep_info.packages.iter().any(|p| p.name == "bare_linker"));
612+
}

0 commit comments

Comments
 (0)