@@ -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
203206mod 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,
0 commit comments