@@ -102,7 +102,7 @@ fn get_lib_name(name: &str, aux_type: AuxType) -> Option<String> {
102102 // In this case, the only path we can pass
103103 // with '--extern-meta' is the '.rlib' file
104104 AuxType :: Lib => Some ( format ! ( "lib{name}.rlib" ) ) ,
105- AuxType :: Dylib => Some ( dylib_name ( name) ) ,
105+ AuxType :: Dylib | AuxType :: ProcMacro => Some ( dylib_name ( name) ) ,
106106 }
107107}
108108
@@ -1097,7 +1097,9 @@ impl<'test> TestCx<'test> {
10971097 }
10981098
10991099 fn has_aux_dir ( & self ) -> bool {
1100- !self . props . aux . builds . is_empty ( ) || !self . props . aux . crates . is_empty ( )
1100+ !self . props . aux . builds . is_empty ( )
1101+ || !self . props . aux . crates . is_empty ( )
1102+ || !self . props . aux . proc_macros . is_empty ( )
11011103 }
11021104
11031105 fn aux_output_dir ( & self ) -> PathBuf {
@@ -1118,31 +1120,48 @@ impl<'test> TestCx<'test> {
11181120
11191121 fn build_all_auxiliary ( & self , of : & TestPaths , aux_dir : & Path , rustc : & mut Command ) {
11201122 for rel_ab in & self . props . aux . builds {
1121- self . build_auxiliary ( of, rel_ab, & aux_dir, false /* is_bin */ ) ;
1123+ self . build_auxiliary ( of, rel_ab, & aux_dir, None ) ;
11221124 }
11231125
11241126 for rel_ab in & self . props . aux . bins {
1125- self . build_auxiliary ( of, rel_ab, & aux_dir, true /* is_bin */ ) ;
1127+ self . build_auxiliary ( of, rel_ab, & aux_dir, Some ( AuxType :: Bin ) ) ;
11261128 }
11271129
1130+ let path_to_crate_name = |path : & str | -> String {
1131+ path. rsplit_once ( '/' )
1132+ . map_or ( path, |( _, tail) | tail)
1133+ . trim_end_matches ( ".rs" )
1134+ . replace ( '-' , "_" )
1135+ } ;
1136+
1137+ let add_extern =
1138+ |rustc : & mut Command , aux_name : & str , aux_path : & str , aux_type : AuxType | {
1139+ let lib_name = get_lib_name ( & path_to_crate_name ( aux_path) , aux_type) ;
1140+ if let Some ( lib_name) = lib_name {
1141+ rustc. arg ( "--extern" ) . arg ( format ! (
1142+ "{}={}/{}" ,
1143+ aux_name,
1144+ aux_dir. display( ) ,
1145+ lib_name
1146+ ) ) ;
1147+ }
1148+ } ;
1149+
11281150 for ( aux_name, aux_path) in & self . props . aux . crates {
1129- let aux_type = self . build_auxiliary ( of, & aux_path, & aux_dir, false /* is_bin */ ) ;
1130- let lib_name =
1131- get_lib_name ( & aux_path. trim_end_matches ( ".rs" ) . replace ( '-' , "_" ) , aux_type) ;
1132- if let Some ( lib_name) = lib_name {
1133- rustc. arg ( "--extern" ) . arg ( format ! (
1134- "{}={}/{}" ,
1135- aux_name,
1136- aux_dir. display( ) ,
1137- lib_name
1138- ) ) ;
1139- }
1151+ let aux_type = self . build_auxiliary ( of, & aux_path, & aux_dir, None ) ;
1152+ add_extern ( rustc, aux_name, aux_path, aux_type) ;
1153+ }
1154+
1155+ for proc_macro in & self . props . aux . proc_macros {
1156+ self . build_auxiliary ( of, proc_macro, & aux_dir, Some ( AuxType :: ProcMacro ) ) ;
1157+ let crate_name = path_to_crate_name ( proc_macro) ;
1158+ add_extern ( rustc, & crate_name, proc_macro, AuxType :: ProcMacro ) ;
11401159 }
11411160
11421161 // Build any `//@ aux-codegen-backend`, and pass the resulting library
11431162 // to `-Zcodegen-backend` when compiling the test file.
11441163 if let Some ( aux_file) = & self . props . aux . codegen_backend {
1145- let aux_type = self . build_auxiliary ( of, aux_file, aux_dir, false ) ;
1164+ let aux_type = self . build_auxiliary ( of, aux_file, aux_dir, None ) ;
11461165 if let Some ( lib_name) = get_lib_name ( aux_file. trim_end_matches ( ".rs" ) , aux_type) {
11471166 let lib_path = aux_dir. join ( & lib_name) ;
11481167 rustc. arg ( format ! ( "-Zcodegen-backend={}" , lib_path. display( ) ) ) ;
@@ -1209,17 +1228,23 @@ impl<'test> TestCx<'test> {
12091228 }
12101229
12111230 /// Builds an aux dependency.
1231+ ///
1232+ /// If `aux_type` is `None`, then this will determine the aux-type automatically.
12121233 fn build_auxiliary (
12131234 & self ,
12141235 of : & TestPaths ,
12151236 source_path : & str ,
12161237 aux_dir : & Path ,
1217- is_bin : bool ,
1238+ aux_type : Option < AuxType > ,
12181239 ) -> AuxType {
12191240 let aux_testpaths = self . compute_aux_test_paths ( of, source_path) ;
1220- let aux_props = self . props . from_aux_file ( & aux_testpaths. file , self . revision , self . config ) ;
1241+ let mut aux_props =
1242+ self . props . from_aux_file ( & aux_testpaths. file , self . revision , self . config ) ;
1243+ if aux_type == Some ( AuxType :: ProcMacro ) {
1244+ aux_props. force_host = true ;
1245+ }
12211246 let mut aux_dir = aux_dir. to_path_buf ( ) ;
1222- if is_bin {
1247+ if aux_type == Some ( AuxType :: Bin ) {
12231248 // On unix, the binary of `auxiliary/foo.rs` will be named
12241249 // `auxiliary/foo` which clashes with the _dir_ `auxiliary/foo`, so
12251250 // put bins in a `bin` subfolder.
@@ -1250,8 +1275,12 @@ impl<'test> TestCx<'test> {
12501275 aux_rustc. env_remove ( key) ;
12511276 }
12521277
1253- let ( aux_type, crate_type) = if is_bin {
1278+ let ( aux_type, crate_type) = if aux_type == Some ( AuxType :: Bin ) {
12541279 ( AuxType :: Bin , Some ( "bin" ) )
1280+ } else if aux_type == Some ( AuxType :: ProcMacro ) {
1281+ ( AuxType :: ProcMacro , Some ( "proc-macro" ) )
1282+ } else if aux_type. is_some ( ) {
1283+ panic ! ( "aux_type {aux_type:?} not expected" ) ;
12551284 } else if aux_props. no_prefer_dynamic {
12561285 ( AuxType :: Dylib , None )
12571286 } else if self . config . target . contains ( "emscripten" )
@@ -1287,6 +1316,11 @@ impl<'test> TestCx<'test> {
12871316 aux_rustc. args ( & [ "--crate-type" , crate_type] ) ;
12881317 }
12891318
1319+ if aux_type == AuxType :: ProcMacro {
1320+ // For convenience, but this only works on 2018.
1321+ aux_rustc. args ( & [ "--extern" , "proc_macro" ] ) ;
1322+ }
1323+
12901324 aux_rustc. arg ( "-L" ) . arg ( & aux_dir) ;
12911325
12921326 let auxres = aux_cx. compose_and_run (
@@ -2768,8 +2802,10 @@ enum LinkToAux {
27682802 No ,
27692803}
27702804
2805+ #[ derive( Debug , PartialEq ) ]
27712806enum AuxType {
27722807 Bin ,
27732808 Lib ,
27742809 Dylib ,
2810+ ProcMacro ,
27752811}
0 commit comments