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