Skip to content

Commit 03d488b

Browse files
committed
Auto merge of #98843 - Urgau:check-cfg-stage0, r=Mark-Simulacrum
Enable check-cfg in stage0 Now that the bootstrap cargo supports `rustc-check-cfg` we can now enable it with `-Zcheck-cfg=output` and use it in `rustc_llvm` to unblock `--check-cfg` support in stage0. r? `@Mark-Simulacrum`
2 parents f426146 + f818872 commit 03d488b

File tree

2 files changed

+61
-71
lines changed

2 files changed

+61
-71
lines changed

Diff for: compiler/rustc_llvm/build.rs

+29-33
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@ use std::fmt::Display;
44
use std::path::{Path, PathBuf};
55
use std::process::{Command, Stdio};
66

7+
const OPTIONAL_COMPONENTS: &[&str] = &[
8+
"x86",
9+
"arm",
10+
"aarch64",
11+
"amdgpu",
12+
"avr",
13+
"m68k",
14+
"mips",
15+
"powerpc",
16+
"systemz",
17+
"jsbackend",
18+
"webassembly",
19+
"msp430",
20+
"sparc",
21+
"nvptx",
22+
"hexagon",
23+
"riscv",
24+
"bpf",
25+
];
26+
27+
const REQUIRED_COMPONENTS: &[&str] =
28+
&["ipo", "bitreader", "bitwriter", "linker", "asmparser", "lto", "coverage", "instrumentation"];
29+
730
fn detect_llvm_link() -> (&'static str, &'static str) {
831
// Force the link mode we want, preferring static by default, but
932
// possibly overridden by `configure --enable-llvm-link-shared`.
@@ -76,6 +99,10 @@ fn output(cmd: &mut Command) -> String {
7699
}
77100

78101
fn main() {
102+
for component in REQUIRED_COMPONENTS.iter().chain(OPTIONAL_COMPONENTS.iter()) {
103+
println!("cargo:rustc-check-cfg=values(llvm_component,\"{}\")", component);
104+
}
105+
79106
if tracked_env_var_os("RUST_CHECK").is_some() {
80107
// If we're just running `check`, there's no need for LLVM to be built.
81108
return;
@@ -131,42 +158,11 @@ fn main() {
131158
let host = env::var("HOST").expect("HOST was not set");
132159
let is_crossed = target != host;
133160

134-
let optional_components = &[
135-
"x86",
136-
"arm",
137-
"aarch64",
138-
"amdgpu",
139-
"avr",
140-
"m68k",
141-
"mips",
142-
"powerpc",
143-
"systemz",
144-
"jsbackend",
145-
"webassembly",
146-
"msp430",
147-
"sparc",
148-
"nvptx",
149-
"hexagon",
150-
"riscv",
151-
"bpf",
152-
];
153-
154-
let required_components = &[
155-
"ipo",
156-
"bitreader",
157-
"bitwriter",
158-
"linker",
159-
"asmparser",
160-
"lto",
161-
"coverage",
162-
"instrumentation",
163-
];
164-
165161
let components = output(Command::new(&llvm_config).arg("--components"));
166162
let mut components = components.split_whitespace().collect::<Vec<_>>();
167-
components.retain(|c| optional_components.contains(c) || required_components.contains(c));
163+
components.retain(|c| OPTIONAL_COMPONENTS.contains(c) || REQUIRED_COMPONENTS.contains(c));
168164

169-
for component in required_components {
165+
for component in REQUIRED_COMPONENTS {
170166
if !components.contains(component) {
171167
panic!("require llvm component {} but wasn't found", component);
172168
}

Diff for: src/bootstrap/builder.rs

+32-38
Original file line numberDiff line numberDiff line change
@@ -1468,45 +1468,39 @@ impl<'a> Builder<'a> {
14681468
rustflags.arg("-Zunstable-options");
14691469
}
14701470

1471-
// FIXME(Urgau): This a hack as it shouldn't be gated on stage 0 but until `rustc_llvm`
1472-
// is made to work with `--check-cfg` which is currently not easly possible until cargo
1473-
// get some support for setting `--check-cfg` within build script, it's the least invasive
1474-
// hack that still let's us have cfg checking for the vast majority of the codebase.
1475-
if stage != 0 {
1476-
// Enable cfg checking of cargo features for everything but std and also enable cfg
1477-
// checking of names and values.
1478-
//
1479-
// Note: `std`, `alloc` and `core` imports some dependencies by #[path] (like
1480-
// backtrace, core_simd, std_float, ...), those dependencies have their own
1481-
// features but cargo isn't involved in the #[path] process and so cannot pass the
1482-
// complete list of features, so for that reason we don't enable checking of
1483-
// features for std crates.
1484-
cargo.arg(if mode != Mode::Std {
1485-
"-Zcheck-cfg=names,values,features"
1486-
} else {
1487-
"-Zcheck-cfg=names,values"
1488-
});
1471+
// Enable cfg checking of cargo features for everything but std and also enable cfg
1472+
// checking of names and values.
1473+
//
1474+
// Note: `std`, `alloc` and `core` imports some dependencies by #[path] (like
1475+
// backtrace, core_simd, std_float, ...), those dependencies have their own
1476+
// features but cargo isn't involved in the #[path] process and so cannot pass the
1477+
// complete list of features, so for that reason we don't enable checking of
1478+
// features for std crates.
1479+
cargo.arg(if mode != Mode::Std {
1480+
"-Zcheck-cfg=names,values,output,features"
1481+
} else {
1482+
"-Zcheck-cfg=names,values,output"
1483+
});
14891484

1490-
// Add extra cfg not defined in/by rustc
1491-
//
1492-
// Note: Altrough it would seems that "-Zunstable-options" to `rustflags` is useless as
1493-
// cargo would implicitly add it, it was discover that sometimes bootstrap only use
1494-
// `rustflags` without `cargo` making it required.
1495-
rustflags.arg("-Zunstable-options");
1496-
for (restricted_mode, name, values) in EXTRA_CHECK_CFGS {
1497-
if *restricted_mode == None || *restricted_mode == Some(mode) {
1498-
// Creating a string of the values by concatenating each value:
1499-
// ',"tvos","watchos"' or '' (nothing) when there are no values
1500-
let values = match values {
1501-
Some(values) => values
1502-
.iter()
1503-
.map(|val| [",", "\"", val, "\""])
1504-
.flatten()
1505-
.collect::<String>(),
1506-
None => String::new(),
1507-
};
1508-
rustflags.arg(&format!("--check-cfg=values({name}{values})"));
1509-
}
1485+
// Add extra cfg not defined in/by rustc
1486+
//
1487+
// Note: Altrough it would seems that "-Zunstable-options" to `rustflags` is useless as
1488+
// cargo would implicitly add it, it was discover that sometimes bootstrap only use
1489+
// `rustflags` without `cargo` making it required.
1490+
rustflags.arg("-Zunstable-options");
1491+
for (restricted_mode, name, values) in EXTRA_CHECK_CFGS {
1492+
if *restricted_mode == None || *restricted_mode == Some(mode) {
1493+
// Creating a string of the values by concatenating each value:
1494+
// ',"tvos","watchos"' or '' (nothing) when there are no values
1495+
let values = match values {
1496+
Some(values) => values
1497+
.iter()
1498+
.map(|val| [",", "\"", val, "\""])
1499+
.flatten()
1500+
.collect::<String>(),
1501+
None => String::new(),
1502+
};
1503+
rustflags.arg(&format!("--check-cfg=values({name}{values})"));
15101504
}
15111505
}
15121506

0 commit comments

Comments
 (0)