From 134dc334857e453c50f8ea31b13cbda106204f20 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 12 Feb 2023 14:01:32 +0000 Subject: [PATCH] Fix testing with unstable features disabled --- build_system/mod.rs | 1 + build_system/tests.rs | 34 +++++++++++++++++++++++++++----- example/mini_core_hello_world.rs | 18 +++++++++++++---- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/build_system/mod.rs b/build_system/mod.rs index 2ca531640..011001116 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 13bf9c70c..7efb96069 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 3232cd503..e3452520e 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