about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--build_system/src/build.rs49
-rw-r--r--build_system/src/config.rs10
-rw-r--r--build_system/src/test.rs56
3 files changed, 59 insertions, 56 deletions
diff --git a/build_system/src/build.rs b/build_system/src/build.rs
index 308ad346549..0eabd1d8972 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();
@@ -112,34 +108,25 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
     }
     rustflags.push_str(" -Z force-unstable-if-unmarked");
     let mut env = env.clone();
+
+    let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"build", &"--target", &config.target];
+
+    if config.no_default_features {
+        rustflags.push_str(" -Csymbol-mangling-version=v0");
+        args.push(&"--no-default-features");
+    }
+
     let channel = if config.sysroot_release_channel {
-        env.insert(
-            "RUSTFLAGS".to_string(),
-            format!("{} -Zmir-opt-level=3", rustflags),
-        );
-        run_command_with_output_and_env(
-            &[
-                &"cargo",
-                &"build",
-                &"--release",
-                &"--target",
-                &config.target,
-            ],
-            Some(start_dir),
-            Some(&env),
-        )?;
+        rustflags.push_str(" -Zmir-opt-level=3");
+        args.push(&"--release");
         "release"
     } else {
-        env.insert("RUSTFLAGS".to_string(), rustflags);
-
-        run_command_with_output_and_env(
-            &[&"cargo", &"build", &"--target", &config.target],
-            Some(start_dir),
-            Some(&env),
-        )?;
         "debug"
     };
 
+    env.insert("RUSTFLAGS".to_string(), rustflags);
+    run_command_with_output_and_env(&args, Some(start_dir), Some(&env))?;
+
     // Copy files to sysroot
     let sysroot_path = start_dir.join(format!("sysroot/lib/rustlib/{}/lib/", config.target_triple));
     fs::create_dir_all(&sysroot_path).map_err(|error| {
@@ -193,6 +180,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");
@@ -201,6 +195,9 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
     } else {
         env.insert("CHANNEL".to_string(), "debug".to_string());
     }
+    if args.config_info.no_default_features {
+        command.push(&"--no-default-features");
+    }
     let flags = args.flags.iter().map(|s| s.as_str()).collect::<Vec<_>>();
     for flag in &flags {
         command.push(flag);
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(
         &[