From 0e82c5302819abd65e7cf238e1b269673eb91d99 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 3 Jul 2022 16:02:20 +0200 Subject: [PATCH 1/2] Add cargo:rustc-check-cfg to rustc_llvm build script --- compiler/rustc_llvm/build.rs | 62 +++++++++++++++++------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index 7729ec6bef4a7..62ef5804dce6d 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -4,6 +4,29 @@ use std::fmt::Display; use std::path::{Path, PathBuf}; 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) { // Force the link mode we want, preferring static by default, but // possibly overridden by `configure --enable-llvm-link-shared`. @@ -76,6 +99,10 @@ fn output(cmd: &mut Command) -> String { } 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 we're just running `check`, there's no need for LLVM to be built. return; @@ -131,42 +158,11 @@ fn main() { let host = env::var("HOST").expect("HOST was not set"); 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 mut components = components.split_whitespace().collect::>(); - 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) { panic!("require llvm component {} but wasn't found", component); } From f818872ecb924fd5cf388a19a2119b0c1f5b7872 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 3 Jul 2022 15:14:22 +0200 Subject: [PATCH 2/2] Enable check-cfg in stage0 --- src/bootstrap/builder.rs | 70 ++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 755c532ab3260..7f3625947e721 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1462,45 +1462,39 @@ impl<'a> Builder<'a> { 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 - // checking of names and values. - // - // Note: `std`, `alloc` and `core` imports some dependencies by #[path] (like - // backtrace, core_simd, std_float, ...), those dependencies have their own - // features but cargo isn't involved in the #[path] process and so cannot pass the - // complete list of features, so for that reason we don't enable checking of - // features for std crates. - cargo.arg(if mode != Mode::Std { - "-Zcheck-cfg=names,values,features" - } else { - "-Zcheck-cfg=names,values" - }); + // Enable cfg checking of cargo features for everything but std and also enable cfg + // checking of names and values. + // + // Note: `std`, `alloc` and `core` imports some dependencies by #[path] (like + // backtrace, core_simd, std_float, ...), those dependencies have their own + // features but cargo isn't involved in the #[path] process and so cannot pass the + // complete list of features, so for that reason we don't enable checking of + // features for std crates. + cargo.arg(if mode != Mode::Std { + "-Zcheck-cfg=names,values,output,features" + } else { + "-Zcheck-cfg=names,values,output" + }); - // Add extra cfg not defined in/by rustc - // - // Note: Altrough it would seems that "-Zunstable-options" to `rustflags` is useless as - // cargo would implicitly add it, it was discover that sometimes bootstrap only use - // `rustflags` without `cargo` making it required. - rustflags.arg("-Zunstable-options"); - for (restricted_mode, name, values) in EXTRA_CHECK_CFGS { - if *restricted_mode == None || *restricted_mode == Some(mode) { - // Creating a string of the values by concatenating each value: - // ',"tvos","watchos"' or '' (nothing) when there are no values - let values = match values { - Some(values) => values - .iter() - .map(|val| [",", "\"", val, "\""]) - .flatten() - .collect::(), - None => String::new(), - }; - rustflags.arg(&format!("--check-cfg=values({name}{values})")); - } + // Add extra cfg not defined in/by rustc + // + // Note: Altrough it would seems that "-Zunstable-options" to `rustflags` is useless as + // cargo would implicitly add it, it was discover that sometimes bootstrap only use + // `rustflags` without `cargo` making it required. + rustflags.arg("-Zunstable-options"); + for (restricted_mode, name, values) in EXTRA_CHECK_CFGS { + if *restricted_mode == None || *restricted_mode == Some(mode) { + // Creating a string of the values by concatenating each value: + // ',"tvos","watchos"' or '' (nothing) when there are no values + let values = match values { + Some(values) => values + .iter() + .map(|val| [",", "\"", val, "\""]) + .flatten() + .collect::(), + None => String::new(), + }; + rustflags.arg(&format!("--check-cfg=values({name}{values})")); } }