Skip to content

Commit 45ded3b

Browse files
committed
Fix testing with unstable features disabled
1 parent c87dfd9 commit 45ded3b

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

build_system/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ pub(crate) fn main() {
179179
&dirs,
180180
channel,
181181
sysroot_kind,
182+
use_unstable_features,
182183
&cg_clif_dylib,
183184
&bootstrap_host_compiler,
184185
rustup_toolchain_name.as_deref(),

build_system/tests.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ pub(crate) fn run_tests(
215215
dirs: &Dirs,
216216
channel: &str,
217217
sysroot_kind: SysrootKind,
218+
use_unstable_features: bool,
218219
cg_clif_dylib: &Path,
219220
bootstrap_host_compiler: &Compiler,
220221
rustup_toolchain_name: Option<&str>,
@@ -234,6 +235,7 @@ pub(crate) fn run_tests(
234235
let runner = TestRunner::new(
235236
dirs.clone(),
236237
target_compiler,
238+
use_unstable_features,
237239
bootstrap_host_compiler.triple == target_triple,
238240
);
239241

@@ -263,6 +265,7 @@ pub(crate) fn run_tests(
263265
let runner = TestRunner::new(
264266
dirs.clone(),
265267
target_compiler,
268+
use_unstable_features,
266269
bootstrap_host_compiler.triple == target_triple,
267270
);
268271

@@ -283,12 +286,18 @@ pub(crate) fn run_tests(
283286
struct TestRunner {
284287
is_native: bool,
285288
jit_supported: bool,
289+
use_unstable_features: bool,
286290
dirs: Dirs,
287291
target_compiler: Compiler,
288292
}
289293

290294
impl TestRunner {
291-
fn new(dirs: Dirs, mut target_compiler: Compiler, is_native: bool) -> Self {
295+
fn new(
296+
dirs: Dirs,
297+
mut target_compiler: Compiler,
298+
use_unstable_features: bool,
299+
is_native: bool,
300+
) -> Self {
292301
if let Ok(rustflags) = env::var("RUSTFLAGS") {
293302
target_compiler.rustflags.push(' ');
294303
target_compiler.rustflags.push_str(&rustflags);
@@ -303,11 +312,12 @@ impl TestRunner {
303312
target_compiler.rustflags.push_str(" -Clink-arg=-undefined -Clink-arg=dynamic_lookup");
304313
}
305314

306-
let jit_supported = is_native
315+
let jit_supported = use_unstable_features
316+
&& is_native
307317
&& target_compiler.triple.contains("x86_64")
308318
&& !target_compiler.triple.contains("windows");
309319

310-
Self { is_native, jit_supported, dirs, target_compiler }
320+
Self { is_native, jit_supported, use_unstable_features, dirs, target_compiler }
311321
}
312322

313323
fn run_testsuite(&self, tests: &[TestCase]) {
@@ -326,10 +336,24 @@ impl TestRunner {
326336
match *cmd {
327337
TestCaseCmd::Custom { func } => func(self),
328338
TestCaseCmd::BuildLib { source, crate_types } => {
329-
self.run_rustc([source, "--crate-type", crate_types]);
339+
if self.use_unstable_features {
340+
self.run_rustc([source, "--crate-type", crate_types]);
341+
} else {
342+
self.run_rustc([
343+
source,
344+
"--crate-type",
345+
crate_types,
346+
"--cfg",
347+
"no_unstable_features",
348+
]);
349+
}
330350
}
331351
TestCaseCmd::BuildBinAndRun { source, args } => {
332-
self.run_rustc([source]);
352+
if self.use_unstable_features {
353+
self.run_rustc([source]);
354+
} else {
355+
self.run_rustc([source, "--cfg", "no_unstable_features"]);
356+
}
333357
self.run_out_command(
334358
source.split('/').last().unwrap().split('.').next().unwrap(),
335359
args,

example/mini_core_hello_world.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,12 @@ fn main() {
322322
#[cfg(all(not(jit), not(all(windows, target_env = "gnu"))))]
323323
test_tls();
324324

325-
#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))]
325+
#[cfg(all(
326+
not(jit),
327+
not(no_unstable_features),
328+
target_arch = "x86_64",
329+
any(target_os = "linux", target_os = "darwin")
330+
))]
326331
unsafe {
327332
global_asm_test();
328333
}
@@ -350,12 +355,17 @@ fn main() {
350355
let _a = f.0[0];
351356
}
352357

353-
#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))]
358+
#[cfg(all(
359+
not(jit),
360+
not(no_unstable_features),
361+
target_arch = "x86_64",
362+
any(target_os = "linux", target_os = "darwin")
363+
))]
354364
extern "C" {
355365
fn global_asm_test();
356366
}
357367

358-
#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))]
368+
#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "linux"))]
359369
global_asm! {
360370
"
361371
.global global_asm_test
@@ -365,7 +375,7 @@ global_asm! {
365375
"
366376
}
367377

368-
#[cfg(all(not(jit), target_arch = "x86_64", target_os = "darwin"))]
378+
#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "darwin"))]
369379
global_asm! {
370380
"
371381
.global _global_asm_test

0 commit comments

Comments
 (0)