Skip to content

Commit 056f5b0

Browse files
committed
Auto merge of #116983 - Urgau:prepare-bootstrap-for-new-check-cfg, r=Kobzol
Prepare the `bootstrap` tool for the new check-cfg syntax This PR prepare the `bootstrap` tool for the [new check-cfg syntax](#111072) as well as the according [changes to Cargo](rust-lang/cargo#12845). ~~Note that while the new syntax can technically available on stage > 2, we actually cannot use it since we need a cargo version that supports the new syntax which won't happen until the next beta bump (if I understand everything correctly).~~ r? bootstrap
2 parents 104ac7b + 0691c06 commit 056f5b0

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/bootstrap/src/bin/rustdoc.rs

+2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ fn main() {
7070
cmd.arg("--cfg=bootstrap");
7171
}
7272
cmd.arg("-Zunstable-options");
73+
// #[cfg(bootstrap)]
7374
cmd.arg("--check-cfg=values(bootstrap)");
75+
// cmd.arg("--check-cfg=cfg(bootstrap)");
7476

7577
if verbose > 1 {
7678
eprintln!(

src/bootstrap/src/core/builder.rs

+26-8
Original file line numberDiff line numberDiff line change
@@ -1401,19 +1401,28 @@ impl<'a> Builder<'a> {
14011401
rustflags.arg("-Zunstable-options");
14021402
}
14031403

1404-
// Enable cfg checking of cargo features for everything but std and also enable cfg
1405-
// checking of names and values.
1404+
// #[cfg(bootstrap)]
1405+
let use_new_check_cfg_syntax = self.local_rebuild;
1406+
1407+
// Enable compile-time checking of `cfg` names, values and Cargo `features`.
14061408
//
14071409
// Note: `std`, `alloc` and `core` imports some dependencies by #[path] (like
14081410
// backtrace, core_simd, std_float, ...), those dependencies have their own
14091411
// features but cargo isn't involved in the #[path] process and so cannot pass the
14101412
// complete list of features, so for that reason we don't enable checking of
14111413
// features for std crates.
1412-
cargo.arg(if mode != Mode::Std {
1413-
"-Zcheck-cfg=names,values,output,features"
1414+
if use_new_check_cfg_syntax {
1415+
cargo.arg("-Zcheck-cfg");
1416+
if mode == Mode::Std {
1417+
rustflags.arg("--check-cfg=cfg(feature,values(any()))");
1418+
}
14141419
} else {
1415-
"-Zcheck-cfg=names,values,output"
1416-
});
1420+
cargo.arg(if mode != Mode::Std {
1421+
"-Zcheck-cfg=names,values,output,features"
1422+
} else {
1423+
"-Zcheck-cfg=names,values,output"
1424+
});
1425+
}
14171426

14181427
// Add extra cfg not defined in/by rustc
14191428
//
@@ -1433,7 +1442,12 @@ impl<'a> Builder<'a> {
14331442
.collect::<String>(),
14341443
None => String::new(),
14351444
};
1436-
rustflags.arg(&format!("--check-cfg=values({name}{values})"));
1445+
if use_new_check_cfg_syntax {
1446+
let values = values.strip_prefix(",").unwrap_or(&values); // remove the first `,`
1447+
rustflags.arg(&format!("--check-cfg=cfg({name},values({values}))"));
1448+
} else {
1449+
rustflags.arg(&format!("--check-cfg=values({name}{values})"));
1450+
}
14371451
}
14381452
}
14391453

@@ -1449,7 +1463,11 @@ impl<'a> Builder<'a> {
14491463
// We also declare that the flag is expected, which we need to do to not
14501464
// get warnings about it being unexpected.
14511465
hostflags.arg("-Zunstable-options");
1452-
hostflags.arg("--check-cfg=values(bootstrap)");
1466+
if use_new_check_cfg_syntax {
1467+
hostflags.arg("--check-cfg=cfg(bootstrap)");
1468+
} else {
1469+
hostflags.arg("--check-cfg=values(bootstrap)");
1470+
}
14531471

14541472
// FIXME: It might be better to use the same value for both `RUSTFLAGS` and `RUSTDOCFLAGS`,
14551473
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See

src/tools/opt-dist/src/tests.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ pub fn run_tests(env: &Environment) -> anyhow::Result<()> {
2424
let host_triple = env.host_triple();
2525
let version = find_dist_version(&dist_dir)?;
2626

27-
// Extract rustc, libstd and src archives to create the optimized sysroot
27+
// Extract rustc, libstd, cargo and src archives to create the optimized sysroot
2828
let rustc_dir = extract_dist_dir(&format!("rustc-{version}-{host_triple}"))?.join("rustc");
2929
let libstd_dir = extract_dist_dir(&format!("rust-std-{version}-{host_triple}"))?
3030
.join(format!("rust-std-{host_triple}"));
31+
let cargo_dir = extract_dist_dir(&format!("cargo-{version}-{host_triple}"))?.join("cargo");
3132
let extracted_src_dir = extract_dist_dir(&format!("rust-src-{version}"))?.join("rust-src");
3233

3334
// We need to manually copy libstd to the extracted rustc sysroot
@@ -46,6 +47,8 @@ pub fn run_tests(env: &Environment) -> anyhow::Result<()> {
4647

4748
let rustc_path = rustc_dir.join("bin").join(format!("rustc{}", executable_extension()));
4849
assert!(rustc_path.is_file());
50+
let cargo_path = cargo_dir.join("bin").join(format!("cargo{}", executable_extension()));
51+
assert!(cargo_path.is_file());
4952

5053
// Specify path to a LLVM config so that LLVM is not rebuilt.
5154
// It doesn't really matter which LLVM config we choose, because no sysroot will be compiled.
@@ -62,11 +65,13 @@ change-id = 115898
6265
6366
[build]
6467
rustc = "{rustc}"
68+
cargo = "{cargo}"
6569
6670
[target.{host_triple}]
6771
llvm-config = "{llvm_config}"
6872
"#,
6973
rustc = rustc_path.to_string().replace('\\', "/"),
74+
cargo = cargo_path.to_string().replace('\\', "/"),
7075
llvm_config = llvm_config.to_string().replace('\\', "/")
7176
);
7277
log::info!("Using following `config.toml` for running tests:\n{config_content}");

0 commit comments

Comments
 (0)