about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-02-12 14:01:32 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-05-24 17:31:25 +0000
commit134dc334857e453c50f8ea31b13cbda106204f20 (patch)
tree4d23df083aae49715e86ddb2ce4ba4b62aa29670
parent72e67c862f9d81a54850d78804ee0de6d0e413a8 (diff)
downloadrust-134dc334857e453c50f8ea31b13cbda106204f20.tar.gz
rust-134dc334857e453c50f8ea31b13cbda106204f20.zip
Fix testing with unstable features disabled
-rw-r--r--build_system/mod.rs1
-rw-r--r--build_system/tests.rs34
-rw-r--r--example/mini_core_hello_world.rs18
3 files changed, 44 insertions, 9 deletions
diff --git a/build_system/mod.rs b/build_system/mod.rs
index 2ca5316408e..0110011169d 100644
--- a/build_system/mod.rs
+++ b/build_system/mod.rs
@@ -196,6 +196,7 @@ pub(crate) fn main() {
                 &dirs,
                 channel,
                 sysroot_kind,
+                use_unstable_features,
                 &cg_clif_dylib,
                 &bootstrap_host_compiler,
                 rustup_toolchain_name.as_deref(),
diff --git a/build_system/tests.rs b/build_system/tests.rs
index 13bf9c70c3e..7efb960697e 100644
--- a/build_system/tests.rs
+++ b/build_system/tests.rs
@@ -214,6 +214,7 @@ pub(crate) fn run_tests(
     dirs: &Dirs,
     channel: &str,
     sysroot_kind: SysrootKind,
+    use_unstable_features: bool,
     cg_clif_dylib: &CodegenBackend,
     bootstrap_host_compiler: &Compiler,
     rustup_toolchain_name: Option<&str>,
@@ -233,6 +234,7 @@ pub(crate) fn run_tests(
         let runner = TestRunner::new(
             dirs.clone(),
             target_compiler,
+            use_unstable_features,
             bootstrap_host_compiler.triple == target_triple,
         );
 
@@ -262,6 +264,7 @@ pub(crate) fn run_tests(
         let runner = TestRunner::new(
             dirs.clone(),
             target_compiler,
+            use_unstable_features,
             bootstrap_host_compiler.triple == target_triple,
         );
 
@@ -282,12 +285,18 @@ pub(crate) fn run_tests(
 struct TestRunner {
     is_native: bool,
     jit_supported: bool,
+    use_unstable_features: bool,
     dirs: Dirs,
     target_compiler: Compiler,
 }
 
 impl TestRunner {
-    fn new(dirs: Dirs, mut target_compiler: Compiler, is_native: bool) -> Self {
+    fn new(
+        dirs: Dirs,
+        mut target_compiler: Compiler,
+        use_unstable_features: bool,
+        is_native: bool,
+    ) -> Self {
         if let Ok(rustflags) = env::var("RUSTFLAGS") {
             target_compiler.rustflags.push(' ');
             target_compiler.rustflags.push_str(&rustflags);
@@ -302,11 +311,12 @@ impl TestRunner {
             target_compiler.rustflags.push_str(" -Clink-arg=-undefined -Clink-arg=dynamic_lookup");
         }
 
-        let jit_supported = is_native
+        let jit_supported = use_unstable_features
+            && is_native
             && target_compiler.triple.contains("x86_64")
             && !target_compiler.triple.contains("windows");
 
-        Self { is_native, jit_supported, dirs, target_compiler }
+        Self { is_native, jit_supported, use_unstable_features, dirs, target_compiler }
     }
 
     fn run_testsuite(&self, tests: &[TestCase]) {
@@ -325,10 +335,24 @@ impl TestRunner {
             match *cmd {
                 TestCaseCmd::Custom { func } => func(self),
                 TestCaseCmd::BuildLib { source, crate_types } => {
-                    self.run_rustc([source, "--crate-type", crate_types]);
+                    if self.use_unstable_features {
+                        self.run_rustc([source, "--crate-type", crate_types]);
+                    } else {
+                        self.run_rustc([
+                            source,
+                            "--crate-type",
+                            crate_types,
+                            "--cfg",
+                            "no_unstable_features",
+                        ]);
+                    }
                 }
                 TestCaseCmd::BuildBinAndRun { source, args } => {
-                    self.run_rustc([source]);
+                    if self.use_unstable_features {
+                        self.run_rustc([source]);
+                    } else {
+                        self.run_rustc([source, "--cfg", "no_unstable_features"]);
+                    }
                     self.run_out_command(
                         source.split('/').last().unwrap().split('.').next().unwrap(),
                         args,
diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs
index 3232cd503fc..e3452520e7b 100644
--- a/example/mini_core_hello_world.rs
+++ b/example/mini_core_hello_world.rs
@@ -322,7 +322,12 @@ fn main() {
     #[cfg(all(not(jit), not(all(windows, target_env = "gnu"))))]
     test_tls();
 
-    #[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))]
+    #[cfg(all(
+        not(jit),
+        not(no_unstable_features),
+        target_arch = "x86_64",
+        any(target_os = "linux", target_os = "darwin")
+    ))]
     unsafe {
         global_asm_test();
     }
@@ -350,12 +355,17 @@ fn main() {
     let _a = f.0[0];
 }
 
-#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))]
+#[cfg(all(
+    not(jit),
+    not(no_unstable_features),
+    target_arch = "x86_64",
+    any(target_os = "linux", target_os = "darwin")
+))]
 extern "C" {
     fn global_asm_test();
 }
 
-#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))]
+#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "linux"))]
 global_asm! {
     "
     .global global_asm_test
@@ -365,7 +375,7 @@ global_asm! {
     "
 }
 
-#[cfg(all(not(jit), target_arch = "x86_64", target_os = "darwin"))]
+#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "darwin"))]
 global_asm! {
     "
     .global _global_asm_test