about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2024-02-21 13:30:04 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2024-02-21 14:31:34 +0100
commitb87de7325f60af4072f85ecb22b5b4582e51742b (patch)
treebfa8dfd1d7bd29fdc95d4334ee7d106247854138
parente7850933822618255b0bca10f220d77e599d537e (diff)
downloadrust-b87de7325f60af4072f85ecb22b5b4582e51742b.tar.gz
rust-b87de7325f60af4072f85ecb22b5b4582e51742b.zip
Correctly handle "master" feature
-rw-r--r--build_system/src/build.rs14
-rw-r--r--build_system/src/config.rs10
-rw-r--r--build_system/src/test.rs56
3 files changed, 46 insertions, 34 deletions
diff --git a/build_system/src/build.rs b/build_system/src/build.rs
index 308ad346549..7ec8b8de62a 100644
--- a/build_system/src/build.rs
+++ b/build_system/src/build.rs
@@ -19,9 +19,6 @@ impl BuildArg {
 
         while let Some(arg) = args.next() {
             match arg.as_str() {
-                "--no-default-features" => {
-                    build_arg.flags.push("--no-default-features".to_string());
-                }
                 "--features" => {
                     if let Some(arg) = args.next() {
                         build_arg.flags.push("--features".to_string());
@@ -51,7 +48,6 @@ impl BuildArg {
             r#"
 `build` command help:
 
-    --no-default-features  : Add `--no-default-features` flag
     --features [arg]       : Add a new feature [arg]"#
         );
         ConfigInfo::show_usage();
@@ -111,6 +107,9 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
         rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests");
     }
     rustflags.push_str(" -Z force-unstable-if-unmarked");
+    if config.no_default_features {
+        rustflags.push_str(" -Csymbol-mangling-version=v0");
+    }
     let mut env = env.clone();
     let channel = if config.sysroot_release_channel {
         env.insert(
@@ -193,6 +192,13 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
         args.config_info.gcc_path.clone(),
     );
 
+    if args.config_info.no_default_features {
+        env.insert(
+            "RUSTFLAGS".to_string(),
+            "-Csymbol-mangling-version=v0".to_string(),
+        );
+    }
+
     let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"];
     if args.config_info.channel == Channel::Release {
         command.push(&"--release");
diff --git a/build_system/src/config.rs b/build_system/src/config.rs
index ddfc0e4a925..f6f03937018 100644
--- a/build_system/src/config.rs
+++ b/build_system/src/config.rs
@@ -127,6 +127,7 @@ pub struct ConfigInfo {
     // Needed for the `info` command which doesn't want to actually download the lib if needed,
     // just to set the `gcc_path` field to display it.
     pub no_download: bool,
+    pub no_default_features: bool,
 }
 
 impl ConfigInfo {
@@ -177,6 +178,7 @@ impl ConfigInfo {
                     return Err("Expected a value after `--cg_gcc-path`, found nothing".to_string())
                 }
             },
+            "--no-default-features" => self.no_default_features = true,
             _ => return Ok(false),
         }
         Ok(true)
@@ -416,8 +418,9 @@ impl ConfigInfo {
             rustflags.push(linker.to_string());
         }
 
-        #[cfg(not(feature="master"))]
-        rustflags.push("-Csymbol-mangling-version=v0".to_string());
+        if self.no_default_features {
+            rustflags.push("-Csymbol-mangling-version=v0".to_string());
+        }
 
         rustflags.extend_from_slice(&[
             "-Cdebuginfo=2".to_string(),
@@ -495,7 +498,8 @@ impl ConfigInfo {
     --sysroot-panic-abort  : Build the sysroot without unwinding support
     --config-file          : Location of the config file to be used
     --cg_gcc-path          : Location of the rustc_codegen_gcc root folder (used
-                             when ran from another directory)"
+                             when ran from another directory)
+    --no-default-features  : Add `--no-default-features` flag to cargo commands"
         );
     }
 }
diff --git a/build_system/src/test.rs b/build_system/src/test.rs
index ab65fed0f75..17b1868502a 100644
--- a/build_system/src/test.rs
+++ b/build_system/src/test.rs
@@ -90,7 +90,6 @@ fn show_usage() {
 
     --release              : Build codegen in release mode
     --sysroot-panic-abort  : Build the sysroot without unwinding support.
-    --no-default-features  : Add `--no-default-features` flag
     --features [arg]       : Add a new feature [arg]
     --use-system-gcc       : Use system installed libgccjit
     --build-only           : Only build rustc_codegen_gcc then exits
@@ -110,7 +109,6 @@ fn show_usage() {
 
 #[derive(Default, Debug)]
 struct TestArg {
-    no_default_features: bool,
     build_only: bool,
     use_system_gcc: bool,
     runners: BTreeSet<String>,
@@ -132,13 +130,6 @@ impl TestArg {
 
         while let Some(arg) = args.next() {
             match arg.as_str() {
-                "--no-default-features" => {
-                    // To prevent adding it more than once.
-                    if !test_arg.no_default_features {
-                        test_arg.flags.push("--no-default-features".into());
-                    }
-                    test_arg.no_default_features = true;
-                }
                 "--features" => match args.next() {
                     Some(feature) if !feature.is_empty() => {
                         test_arg
@@ -196,11 +187,14 @@ impl TestArg {
                 );
             }
         }
+        if test_arg.config_info.no_default_features {
+            test_arg.flags.push("--no-default-features".into());
+        }
         Ok(Some(test_arg))
     }
 
     pub fn is_using_gcc_master_branch(&self) -> bool {
-        !self.no_default_features
+        !self.config_info.no_default_features
     }
 }
 
@@ -612,20 +606,23 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
 
     env.insert("COMPILETEST_FORCE_STAGE0".to_string(), "1".to_string());
 
-    let rustc_args =
-        &format!(
-            r#"-Zpanic-abort-tests \
-            -Zcodegen-backend="{pwd}/target/{channel}/librustc_codegen_gcc.{dylib_ext}" \
-            --sysroot "{pwd}/build_sysroot/sysroot" -Cpanic=abort"#,
-            pwd = std::env::current_dir()
-                .map_err(|error| format!("`current_dir` failed: {:?}", error))?
-                .display(),
-            channel = args.config_info.channel.as_str(),
-            dylib_ext = args.config_info.dylib_ext,
-        );
+    let extra = if args.is_using_gcc_master_branch() {
+        ""
+    } else {
+        " -Csymbol-mangling-version=v0"
+    };
 
-    #[cfg(not(feature="master"))]
-    let rustc_args = format!("{} -Csymbol-mangling-version=v0", rustc_args);
+    let rustc_args = &format!(
+        r#"-Zpanic-abort-tests \
+            -Zcodegen-backend="{pwd}/target/{channel}/librustc_codegen_gcc.{dylib_ext}" \
+            --sysroot "{pwd}/build_sysroot/sysroot" -Cpanic=abort{extra}"#,
+        pwd = std::env::current_dir()
+            .map_err(|error| format!("`current_dir` failed: {:?}", error))?
+            .display(),
+        channel = args.config_info.channel.as_str(),
+        dylib_ext = args.config_info.dylib_ext,
+        extra = extra,
+    );
 
     run_command_with_env(
         &[
@@ -1069,16 +1066,21 @@ where
     // FIXME: create a function "display_if_not_quiet" or something along the line.
     println!("[TEST] rustc test suite");
     env.insert("COMPILETEST_FORCE_STAGE0".to_string(), "1".to_string());
+
+    let extra = if args.is_using_gcc_master_branch() {
+        ""
+    } else {
+        " -Csymbol-mangling-version=v0"
+    };
+
     let rustc_args = format!(
-        "{} -Zcodegen-backend={} --sysroot {}",
+        "{} -Zcodegen-backend={} --sysroot {}{}",
         env.get("TEST_FLAGS").unwrap_or(&String::new()),
         args.config_info.cg_backend_path,
         args.config_info.sysroot_path,
+        extra,
     );
 
-    #[cfg(not(feature="master"))]
-    let rustc_args = format!("{} -Csymbol-mangling-version=v0", rustc_args);
-
     env.get_mut("RUSTFLAGS").unwrap().clear();
     run_command_with_output_and_env(
         &[