Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 263e6e1

Browse files
committedDec 11, 2024·
Add test for musl dynamically linking
1 parent 9c37c14 commit 263e6e1

File tree

1 file changed

+60
-0
lines changed
  • tests/run-make/musl-default-linking

1 file changed

+60
-0
lines changed
 
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use run_make_support::rustc;
2+
use run_make_support::serde_json;
3+
4+
// Please do NOT add more targets to this list!
5+
// Per https://github.com/rust-lang/compiler-team/issues/422,
6+
// we should be trying to move these targets to dynamically link
7+
// musl libc by default.
8+
static LEGACY_STATIC_LINKING_TARGETS: &[&'static str] = &[
9+
"aarch64-unknown-linux-musl",
10+
"arm-unknown-linux-musleabi",
11+
"arm-unknown-linux-musleabihf",
12+
"armv5te-unknown-linux-musleabi",
13+
"armv7-unknown-linux-musleabi",
14+
"armv7-unknown-linux-musleabihf",
15+
"i586-unknown-linux-musl",
16+
"i686-unknown-linux-musl",
17+
"mips64-unknown-linux-musl",
18+
"mips64-unknown-linux-muslabi64",
19+
"mips64el-unknown-linux-muslabi64",
20+
"powerpc-unknown-linux-musl",
21+
"powerpc-unknown-linux-muslspe",
22+
"powerpc64-unknown-linux-musl",
23+
"powerpc64le-unknown-linux-musl",
24+
"riscv32gc-unknown-linux-musl",
25+
"s390x-unknown-linux-musl",
26+
"thumbv7neon-unknown-linux-musleabihf",
27+
"x86_64-unknown-linux-musl",
28+
];
29+
30+
fn main() {
31+
let targets = rustc().print("target-list").run().stdout_utf8();
32+
33+
for target in targets.lines() {
34+
let abi = target.split('-').last().unwrap();
35+
36+
if !abi.starts_with("musl") {
37+
continue;
38+
}
39+
40+
let target_spec_json =
41+
rustc()
42+
.print("target-spec-json")
43+
.target(target)
44+
.arg("-Zunstable-options")
45+
.run()
46+
.stdout_utf8();
47+
48+
let target_spec: serde_json::Value = serde_json::from_str(&target_spec_json).expect("failed to parse target-spec-json");
49+
let default = &target_spec["crt-static-default"];
50+
51+
// If the value is `null`, then the default to dynamically link from musl_base was not overriden.
52+
if default.is_null() {
53+
continue;
54+
}
55+
56+
if default.as_bool().expect("wasn't a boolean") && !LEGACY_STATIC_LINKING_TARGETS.contains(&target) {
57+
panic!("{target} statically links musl libc when it should dynamically link it");
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)
Please sign in to comment.