about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-10-26 08:54:42 +0000
committerbors <bors@rust-lang.org>2023-10-26 08:54:42 +0000
commit056f5b0f138fa9556027251fb27e8929350d6191 (patch)
tree0ad21337e7a4f4b8319561a72fb6cc558785921b /src
parent104ac7bb6a17aee95fed2f70f2100e9236c11710 (diff)
parent0691c06d9401649644dc26acc9285a156ff8d12d (diff)
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](https://github.com/rust-lang/rust/pull/111072) as well as the according [changes to Cargo](https://github.com/rust-lang/cargo/pull/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
Diffstat (limited to 'src')
-rw-r--r--src/bootstrap/src/bin/rustdoc.rs2
-rw-r--r--src/bootstrap/src/core/builder.rs34
-rw-r--r--src/tools/opt-dist/src/tests.rs7
3 files changed, 34 insertions, 9 deletions
diff --git a/src/bootstrap/src/bin/rustdoc.rs b/src/bootstrap/src/bin/rustdoc.rs
index f5f80ba2a0b..dbbce6fe220 100644
--- a/src/bootstrap/src/bin/rustdoc.rs
+++ b/src/bootstrap/src/bin/rustdoc.rs
@@ -70,7 +70,9 @@ fn main() {
         cmd.arg("--cfg=bootstrap");
     }
     cmd.arg("-Zunstable-options");
+    // #[cfg(bootstrap)]
     cmd.arg("--check-cfg=values(bootstrap)");
+    // cmd.arg("--check-cfg=cfg(bootstrap)");
 
     if verbose > 1 {
         eprintln!(
diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs
index 7ce24c3812d..36653dcfb20 100644
--- a/src/bootstrap/src/core/builder.rs
+++ b/src/bootstrap/src/core/builder.rs
@@ -1401,19 +1401,28 @@ impl<'a> Builder<'a> {
             rustflags.arg("-Zunstable-options");
         }
 
-        // Enable cfg checking of cargo features for everything but std and also enable cfg
-        // checking of names and values.
+        // #[cfg(bootstrap)]
+        let use_new_check_cfg_syntax = self.local_rebuild;
+
+        // Enable compile-time checking of `cfg` names, values and Cargo `features`.
         //
         // 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"
+        if use_new_check_cfg_syntax {
+            cargo.arg("-Zcheck-cfg");
+            if mode == Mode::Std {
+                rustflags.arg("--check-cfg=cfg(feature,values(any()))");
+            }
         } else {
-            "-Zcheck-cfg=names,values,output"
-        });
+            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
         //
@@ -1433,7 +1442,12 @@ impl<'a> Builder<'a> {
                         .collect::<String>(),
                     None => String::new(),
                 };
-                rustflags.arg(&format!("--check-cfg=values({name}{values})"));
+                if use_new_check_cfg_syntax {
+                    let values = values.strip_prefix(",").unwrap_or(&values); // remove the first `,`
+                    rustflags.arg(&format!("--check-cfg=cfg({name},values({values}))"));
+                } else {
+                    rustflags.arg(&format!("--check-cfg=values({name}{values})"));
+                }
             }
         }
 
@@ -1449,7 +1463,11 @@ impl<'a> Builder<'a> {
         // We also declare that the flag is expected, which we need to do to not
         // get warnings about it being unexpected.
         hostflags.arg("-Zunstable-options");
-        hostflags.arg("--check-cfg=values(bootstrap)");
+        if use_new_check_cfg_syntax {
+            hostflags.arg("--check-cfg=cfg(bootstrap)");
+        } else {
+            hostflags.arg("--check-cfg=values(bootstrap)");
+        }
 
         // 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
diff --git a/src/tools/opt-dist/src/tests.rs b/src/tools/opt-dist/src/tests.rs
index 3c33cfe985d..8a8f98a5eda 100644
--- a/src/tools/opt-dist/src/tests.rs
+++ b/src/tools/opt-dist/src/tests.rs
@@ -24,10 +24,11 @@ pub fn run_tests(env: &Environment) -> anyhow::Result<()> {
     let host_triple = env.host_triple();
     let version = find_dist_version(&dist_dir)?;
 
-    // Extract rustc, libstd and src archives to create the optimized sysroot
+    // Extract rustc, libstd, cargo and src archives to create the optimized sysroot
     let rustc_dir = extract_dist_dir(&format!("rustc-{version}-{host_triple}"))?.join("rustc");
     let libstd_dir = extract_dist_dir(&format!("rust-std-{version}-{host_triple}"))?
         .join(format!("rust-std-{host_triple}"));
+    let cargo_dir = extract_dist_dir(&format!("cargo-{version}-{host_triple}"))?.join("cargo");
     let extracted_src_dir = extract_dist_dir(&format!("rust-src-{version}"))?.join("rust-src");
 
     // We need to manually copy libstd to the extracted rustc sysroot
@@ -46,6 +47,8 @@ pub fn run_tests(env: &Environment) -> anyhow::Result<()> {
 
     let rustc_path = rustc_dir.join("bin").join(format!("rustc{}", executable_extension()));
     assert!(rustc_path.is_file());
+    let cargo_path = cargo_dir.join("bin").join(format!("cargo{}", executable_extension()));
+    assert!(cargo_path.is_file());
 
     // Specify path to a LLVM config so that LLVM is not rebuilt.
     // It doesn't really matter which LLVM config we choose, because no sysroot will be compiled.
@@ -62,11 +65,13 @@ change-id = 115898
 
 [build]
 rustc = "{rustc}"
+cargo = "{cargo}"
 
 [target.{host_triple}]
 llvm-config = "{llvm_config}"
 "#,
         rustc = rustc_path.to_string().replace('\\', "/"),
+        cargo = cargo_path.to_string().replace('\\', "/"),
         llvm_config = llvm_config.to_string().replace('\\', "/")
     );
     log::info!("Using following `config.toml` for running tests:\n{config_content}");