Skip to content

Commit 95d01fc

Browse files
committed
compiletest: register --minicore-path flag and //@ add-core-stubs directive
1 parent 74c0c48 commit 95d01fc

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ pub struct Config {
392392

393393
/// Command for visual diff display, e.g. `diff-tool --color=always`.
394394
pub diff_command: Option<String>,
395+
396+
/// Path to minicore aux library, used for `no_core` tests that need `core` stubs in
397+
/// cross-compilation scenarios that do not otherwise want/need to `-Zbuild-std`. Used in e.g.
398+
/// ABI tests.
399+
pub minicore_path: PathBuf,
395400
}
396401

397402
impl Config {

src/tools/compiletest/src/directive-list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// a best-effort approximation for diagnostics. Add new headers to this list when needed.
44
const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
55
// tidy-alphabetical-start
6+
"add-core-stubs",
67
"assembly-output",
78
"aux-bin",
89
"aux-build",

src/tools/compiletest/src/header.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ pub struct TestProps {
198198
pub no_auto_check_cfg: bool,
199199
/// Run tests which require enzyme being build
200200
pub has_enzyme: bool,
201+
/// Build and use `minicore` as `core` stub for `no_core` tests in cross-compilation scenarios
202+
/// that don't otherwise want/need `-Z build-std`.
203+
pub add_core_stubs: bool,
201204
}
202205

203206
mod directives {
@@ -243,6 +246,7 @@ mod directives {
243246
pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags";
244247
pub const FILECHECK_FLAGS: &'static str = "filecheck-flags";
245248
pub const NO_AUTO_CHECK_CFG: &'static str = "no-auto-check-cfg";
249+
pub const ADD_CORE_STUBS: &'static str = "add-core-stubs";
246250
// This isn't a real directive, just one that is probably mistyped often
247251
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
248252
}
@@ -300,6 +304,7 @@ impl TestProps {
300304
filecheck_flags: vec![],
301305
no_auto_check_cfg: false,
302306
has_enzyme: false,
307+
add_core_stubs: false,
303308
}
304309
}
305310

@@ -564,6 +569,8 @@ impl TestProps {
564569
}
565570

566571
config.set_name_directive(ln, NO_AUTO_CHECK_CFG, &mut self.no_auto_check_cfg);
572+
573+
self.update_add_core_stubs(ln, config);
567574
},
568575
);
569576

@@ -677,6 +684,27 @@ impl TestProps {
677684
pub fn local_pass_mode(&self) -> Option<PassMode> {
678685
self.pass_mode
679686
}
687+
688+
pub fn update_add_core_stubs(&mut self, ln: &str, config: &Config) {
689+
let add_core_stubs = config.parse_name_directive(ln, directives::ADD_CORE_STUBS);
690+
if add_core_stubs {
691+
if !matches!(config.mode, Mode::Ui | Mode::Codegen | Mode::Assembly) {
692+
panic!(
693+
"`add-core-stubs` is currently only supported for ui, codegen and assembly test modes"
694+
);
695+
}
696+
697+
// FIXME(jieyouxu): this check is currently order-dependent, but we should probably
698+
// collect all directives in one go then perform a validation pass after that.
699+
if self.local_pass_mode().is_some_and(|pm| pm == PassMode::Run) {
700+
// `minicore` can only be used with non-run modes, because it's `core` prelude stubs
701+
// and can't run.
702+
panic!("`add-core-stubs` cannot be used to run the test binary");
703+
}
704+
705+
self.add_core_stubs = add_core_stubs;
706+
}
707+
}
680708
}
681709

682710
/// If the given line begins with the appropriate comment prefix for a directive,

src/tools/compiletest/src/header/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ impl ConfigBuilder {
152152
"--git-repository=",
153153
"--nightly-branch=",
154154
"--git-merge-commit-email=",
155+
"--minicore-path=",
155156
];
156157
let mut args: Vec<String> = args.iter().map(ToString::to_string).collect();
157158

src/tools/compiletest/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
181181
"compiletest-diff-tool",
182182
"What custom diff tool to use for displaying compiletest tests.",
183183
"COMMAND",
184-
);
184+
)
185+
.reqopt("", "minicore-path", "path to minicore aux library", "PATH");
185186

186187
let (argv0, args_) = args.split_first().unwrap();
187188
if args.len() == 1 || args[1] == "-h" || args[1] == "--help" {
@@ -371,7 +372,10 @@ pub fn parse_config(args: Vec<String>) -> Config {
371372
git_merge_commit_email: matches.opt_str("git-merge-commit-email").unwrap(),
372373

373374
profiler_runtime: matches.opt_present("profiler-runtime"),
375+
374376
diff_command: matches.opt_str("compiletest-diff-tool"),
377+
378+
minicore_path: opt_path(matches, "minicore-path"),
375379
}
376380
}
377381

@@ -409,6 +413,7 @@ pub fn log_config(config: &Config) {
409413
logv(c, format!("host-linker: {:?}", config.host_linker));
410414
logv(c, format!("verbose: {}", config.verbose));
411415
logv(c, format!("format: {:?}", config.format));
416+
logv(c, format!("minicore_path: {:?}", config.minicore_path.display()));
412417
logv(c, "\n".to_string());
413418
}
414419

0 commit comments

Comments
 (0)