Skip to content

Commit a737f75

Browse files
committed
compiletest: conditionally build and provide minicore as extern prelude when requested via //@ add-core-stubs directive
`//@ add-core-stubs` will imply `-Cpanic=abort`.
1 parent 95d01fc commit a737f75

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,14 +1150,20 @@ impl<'test> TestCx<'test> {
11501150
}
11511151
}
11521152

1153-
/// `root_testpaths` refers to the path of the original test.
1154-
/// the auxiliary and the test with an aux-build have the same `root_testpaths`.
1153+
/// `root_testpaths` refers to the path of the original test. the auxiliary and the test with an
1154+
/// aux-build have the same `root_testpaths`.
11551155
fn compose_and_run_compiler(
11561156
&self,
11571157
mut rustc: Command,
11581158
input: Option<String>,
11591159
root_testpaths: &TestPaths,
11601160
) -> ProcRes {
1161+
if self.props.add_core_stubs {
1162+
let minicore_path = self.build_minicore();
1163+
rustc.arg("--extern");
1164+
rustc.arg(&format!("minicore={}", minicore_path.to_str().unwrap()));
1165+
}
1166+
11611167
let aux_dir = self.aux_output_dir();
11621168
self.build_all_auxiliary(root_testpaths, &aux_dir, &mut rustc);
11631169

@@ -1171,6 +1177,37 @@ impl<'test> TestCx<'test> {
11711177
)
11721178
}
11731179

1180+
/// Builds `minicore`. Returns the path to the minicore rlib within the base test output
1181+
/// directory.
1182+
fn build_minicore(&self) -> PathBuf {
1183+
let output_file_path = self.output_base_dir().join("libminicore.rlib");
1184+
let mut rustc = self.make_compile_args(
1185+
&self.config.minicore_path,
1186+
TargetLocation::ThisFile(output_file_path.clone()),
1187+
Emit::None,
1188+
AllowUnused::Yes,
1189+
LinkToAux::No,
1190+
vec![],
1191+
);
1192+
1193+
rustc.args(&["--crate-type", "rlib"]);
1194+
rustc.arg("-Cpanic=abort");
1195+
1196+
let res =
1197+
self.compose_and_run(rustc, self.config.compile_lib_path.to_str().unwrap(), None, None);
1198+
if !res.status.success() {
1199+
self.fatal_proc_rec(
1200+
&format!(
1201+
"auxiliary build of {:?} failed to compile: ",
1202+
self.config.minicore_path.display()
1203+
),
1204+
&res,
1205+
);
1206+
}
1207+
1208+
output_file_path
1209+
}
1210+
11741211
/// Builds an aux dependency.
11751212
fn build_auxiliary(
11761213
&self,
@@ -1662,6 +1699,15 @@ impl<'test> TestCx<'test> {
16621699

16631700
rustc.args(&self.props.compile_flags);
16641701

1702+
// FIXME(jieyouxu): we should report a fatal error or warning if user wrote `-Cpanic=` with
1703+
// something that's not `abort`, however, by moving this last we should override previous
1704+
// `-Cpanic=`s
1705+
//
1706+
// `minicore` requires `#![no_std]` and `#![no_core]`, which means no unwinding panics.
1707+
if self.props.add_core_stubs {
1708+
rustc.arg("-Cpanic=abort");
1709+
}
1710+
16651711
rustc
16661712
}
16671713

0 commit comments

Comments
 (0)