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`
This commit is contained in:
commit
03d488b48a
2 changed files with 61 additions and 71 deletions
|
@ -4,6 +4,29 @@ use std::fmt::Display;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
|
const OPTIONAL_COMPONENTS: &[&str] = &[
|
||||||
|
"x86",
|
||||||
|
"arm",
|
||||||
|
"aarch64",
|
||||||
|
"amdgpu",
|
||||||
|
"avr",
|
||||||
|
"m68k",
|
||||||
|
"mips",
|
||||||
|
"powerpc",
|
||||||
|
"systemz",
|
||||||
|
"jsbackend",
|
||||||
|
"webassembly",
|
||||||
|
"msp430",
|
||||||
|
"sparc",
|
||||||
|
"nvptx",
|
||||||
|
"hexagon",
|
||||||
|
"riscv",
|
||||||
|
"bpf",
|
||||||
|
];
|
||||||
|
|
||||||
|
const REQUIRED_COMPONENTS: &[&str] =
|
||||||
|
&["ipo", "bitreader", "bitwriter", "linker", "asmparser", "lto", "coverage", "instrumentation"];
|
||||||
|
|
||||||
fn detect_llvm_link() -> (&'static str, &'static str) {
|
fn detect_llvm_link() -> (&'static str, &'static str) {
|
||||||
// Force the link mode we want, preferring static by default, but
|
// Force the link mode we want, preferring static by default, but
|
||||||
// possibly overridden by `configure --enable-llvm-link-shared`.
|
// possibly overridden by `configure --enable-llvm-link-shared`.
|
||||||
|
@ -76,6 +99,10 @@ fn output(cmd: &mut Command) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
for component in REQUIRED_COMPONENTS.iter().chain(OPTIONAL_COMPONENTS.iter()) {
|
||||||
|
println!("cargo:rustc-check-cfg=values(llvm_component,\"{}\")", component);
|
||||||
|
}
|
||||||
|
|
||||||
if tracked_env_var_os("RUST_CHECK").is_some() {
|
if tracked_env_var_os("RUST_CHECK").is_some() {
|
||||||
// If we're just running `check`, there's no need for LLVM to be built.
|
// If we're just running `check`, there's no need for LLVM to be built.
|
||||||
return;
|
return;
|
||||||
|
@ -131,42 +158,11 @@ fn main() {
|
||||||
let host = env::var("HOST").expect("HOST was not set");
|
let host = env::var("HOST").expect("HOST was not set");
|
||||||
let is_crossed = target != host;
|
let is_crossed = target != host;
|
||||||
|
|
||||||
let optional_components = &[
|
|
||||||
"x86",
|
|
||||||
"arm",
|
|
||||||
"aarch64",
|
|
||||||
"amdgpu",
|
|
||||||
"avr",
|
|
||||||
"m68k",
|
|
||||||
"mips",
|
|
||||||
"powerpc",
|
|
||||||
"systemz",
|
|
||||||
"jsbackend",
|
|
||||||
"webassembly",
|
|
||||||
"msp430",
|
|
||||||
"sparc",
|
|
||||||
"nvptx",
|
|
||||||
"hexagon",
|
|
||||||
"riscv",
|
|
||||||
"bpf",
|
|
||||||
];
|
|
||||||
|
|
||||||
let required_components = &[
|
|
||||||
"ipo",
|
|
||||||
"bitreader",
|
|
||||||
"bitwriter",
|
|
||||||
"linker",
|
|
||||||
"asmparser",
|
|
||||||
"lto",
|
|
||||||
"coverage",
|
|
||||||
"instrumentation",
|
|
||||||
];
|
|
||||||
|
|
||||||
let components = output(Command::new(&llvm_config).arg("--components"));
|
let components = output(Command::new(&llvm_config).arg("--components"));
|
||||||
let mut components = components.split_whitespace().collect::<Vec<_>>();
|
let mut components = components.split_whitespace().collect::<Vec<_>>();
|
||||||
components.retain(|c| optional_components.contains(c) || required_components.contains(c));
|
components.retain(|c| OPTIONAL_COMPONENTS.contains(c) || REQUIRED_COMPONENTS.contains(c));
|
||||||
|
|
||||||
for component in required_components {
|
for component in REQUIRED_COMPONENTS {
|
||||||
if !components.contains(component) {
|
if !components.contains(component) {
|
||||||
panic!("require llvm component {} but wasn't found", component);
|
panic!("require llvm component {} but wasn't found", component);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1468,11 +1468,6 @@ impl<'a> Builder<'a> {
|
||||||
rustflags.arg("-Zunstable-options");
|
rustflags.arg("-Zunstable-options");
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(Urgau): This a hack as it shouldn't be gated on stage 0 but until `rustc_llvm`
|
|
||||||
// is made to work with `--check-cfg` which is currently not easly possible until cargo
|
|
||||||
// get some support for setting `--check-cfg` within build script, it's the least invasive
|
|
||||||
// hack that still let's us have cfg checking for the vast majority of the codebase.
|
|
||||||
if stage != 0 {
|
|
||||||
// Enable cfg checking of cargo features for everything but std and also enable cfg
|
// Enable cfg checking of cargo features for everything but std and also enable cfg
|
||||||
// checking of names and values.
|
// checking of names and values.
|
||||||
//
|
//
|
||||||
|
@ -1482,9 +1477,9 @@ impl<'a> Builder<'a> {
|
||||||
// complete list of features, so for that reason we don't enable checking of
|
// complete list of features, so for that reason we don't enable checking of
|
||||||
// features for std crates.
|
// features for std crates.
|
||||||
cargo.arg(if mode != Mode::Std {
|
cargo.arg(if mode != Mode::Std {
|
||||||
"-Zcheck-cfg=names,values,features"
|
"-Zcheck-cfg=names,values,output,features"
|
||||||
} else {
|
} else {
|
||||||
"-Zcheck-cfg=names,values"
|
"-Zcheck-cfg=names,values,output"
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add extra cfg not defined in/by rustc
|
// Add extra cfg not defined in/by rustc
|
||||||
|
@ -1508,7 +1503,6 @@ impl<'a> Builder<'a> {
|
||||||
rustflags.arg(&format!("--check-cfg=values({name}{values})"));
|
rustflags.arg(&format!("--check-cfg=values({name}{values})"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: It might be better to use the same value for both `RUSTFLAGS` and `RUSTDOCFLAGS`,
|
// FIXME: It might be better to use the same value for both `RUSTFLAGS` and `RUSTDOCFLAGS`,
|
||||||
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
|
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue