@@ -1150,14 +1150,20 @@ impl<'test> TestCx<'test> {
1150
1150
}
1151
1151
}
1152
1152
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`.
1155
1155
fn compose_and_run_compiler (
1156
1156
& self ,
1157
1157
mut rustc : Command ,
1158
1158
input : Option < String > ,
1159
1159
root_testpaths : & TestPaths ,
1160
1160
) -> 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
+
1161
1167
let aux_dir = self . aux_output_dir ( ) ;
1162
1168
self . build_all_auxiliary ( root_testpaths, & aux_dir, & mut rustc) ;
1163
1169
@@ -1171,6 +1177,37 @@ impl<'test> TestCx<'test> {
1171
1177
)
1172
1178
}
1173
1179
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
+
1174
1211
/// Builds an aux dependency.
1175
1212
fn build_auxiliary (
1176
1213
& self ,
@@ -1662,6 +1699,15 @@ impl<'test> TestCx<'test> {
1662
1699
1663
1700
rustc. args ( & self . props . compile_flags ) ;
1664
1701
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
+
1665
1711
rustc
1666
1712
}
1667
1713
@@ -1848,34 +1894,6 @@ impl<'test> TestCx<'test> {
1848
1894
( proc_res, output_path)
1849
1895
}
1850
1896
1851
- fn compile_test_and_save_assembly ( & self ) -> ( ProcRes , PathBuf ) {
1852
- // This works with both `--emit asm` (as default output name for the assembly)
1853
- // and `ptx-linker` because the latter can write output at requested location.
1854
- let output_path = self . output_base_name ( ) . with_extension ( "s" ) ;
1855
- let input_file = & self . testpaths . file ;
1856
-
1857
- // Use the `//@ assembly-output:` directive to determine how to emit assembly.
1858
- let emit = match self . props . assembly_output . as_deref ( ) {
1859
- Some ( "emit-asm" ) => Emit :: Asm ,
1860
- Some ( "bpf-linker" ) => Emit :: LinkArgsAsm ,
1861
- Some ( "ptx-linker" ) => Emit :: None , // No extra flags needed.
1862
- Some ( other) => self . fatal ( & format ! ( "unknown 'assembly-output' directive: {other}" ) ) ,
1863
- None => self . fatal ( "missing 'assembly-output' directive" ) ,
1864
- } ;
1865
-
1866
- let rustc = self . make_compile_args (
1867
- input_file,
1868
- TargetLocation :: ThisFile ( output_path. clone ( ) ) ,
1869
- emit,
1870
- AllowUnused :: No ,
1871
- LinkToAux :: Yes ,
1872
- Vec :: new ( ) ,
1873
- ) ;
1874
-
1875
- let proc_res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
1876
- ( proc_res, output_path)
1877
- }
1878
-
1879
1897
fn verify_with_filecheck ( & self , output : & Path ) -> ProcRes {
1880
1898
let mut filecheck = Command :: new ( self . config . llvm_filecheck . as_ref ( ) . unwrap ( ) ) ;
1881
1899
filecheck. arg ( "--input-file" ) . arg ( output) . arg ( & self . testpaths . file ) ;
0 commit comments