@@ -82,22 +82,21 @@ fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
8282}
8383
8484/// The platform-specific library name
85- fn get_lib_name ( lib : & str , aux_type : AuxType ) -> String {
85+ fn get_lib_name ( lib : & str , aux_type : AuxType ) -> Option < String > {
8686 match aux_type {
87+ AuxType :: Bin => None ,
8788 // In some casess (e.g. MUSL), we build a static
8889 // library, rather than a dynamic library.
8990 // In this case, the only path we can pass
9091 // with '--extern-meta' is the '.rlib' file
91- AuxType :: Lib => format ! ( "lib{}.rlib" , lib) ,
92- AuxType :: Dylib => {
93- if cfg ! ( windows) {
94- format ! ( "{}.dll" , lib)
95- } else if cfg ! ( target_os = "macos" ) {
96- format ! ( "lib{}.dylib" , lib)
97- } else {
98- format ! ( "lib{}.so" , lib)
99- }
100- }
92+ AuxType :: Lib => Some ( format ! ( "lib{}.rlib" , lib) ) ,
93+ AuxType :: Dylib => Some ( if cfg ! ( windows) {
94+ format ! ( "{}.dll" , lib)
95+ } else if cfg ! ( target_os = "macos" ) {
96+ format ! ( "lib{}.dylib" , lib)
97+ } else {
98+ format ! ( "lib{}.so" , lib)
99+ } ) ,
101100 }
102101}
103102
@@ -2152,7 +2151,14 @@ impl<'test> TestCx<'test> {
21522151 let aux_type = self . build_auxiliary ( of, & aux_path, & aux_dir) ;
21532152 let lib_name =
21542153 get_lib_name ( & aux_path. trim_end_matches ( ".rs" ) . replace ( '-' , "_" ) , aux_type) ;
2155- rustc. arg ( "--extern" ) . arg ( format ! ( "{}={}/{}" , aux_name, aux_dir. display( ) , lib_name) ) ;
2154+ if let Some ( lib_name) = lib_name {
2155+ rustc. arg ( "--extern" ) . arg ( format ! (
2156+ "{}={}/{}" ,
2157+ aux_name,
2158+ aux_dir. display( ) ,
2159+ lib_name
2160+ ) ) ;
2161+ }
21562162 }
21572163 }
21582164
@@ -2201,7 +2207,15 @@ impl<'test> TestCx<'test> {
22012207 }
22022208 aux_rustc. envs ( aux_props. rustc_env . clone ( ) ) ;
22032209
2204- let ( aux_type, crate_type) = if aux_props. no_prefer_dynamic {
2210+ // Obviously a hack, but should work OK for now.
2211+ let is_bin = std:: fs:: read_to_string ( input_file)
2212+ . unwrap ( )
2213+ . lines ( )
2214+ . any ( |l| l == "#![crate_type = \" bin\" ]" ) ;
2215+
2216+ let ( aux_type, crate_type) = if is_bin {
2217+ ( AuxType :: Bin , None )
2218+ } else if aux_props. no_prefer_dynamic {
22052219 ( AuxType :: Dylib , None )
22062220 } else if self . config . target . contains ( "emscripten" )
22072221 || ( self . config . target . contains ( "musl" )
@@ -4913,6 +4927,7 @@ enum LinkToAux {
49134927}
49144928
49154929enum AuxType {
4930+ Bin ,
49164931 Lib ,
49174932 Dylib ,
49184933}
0 commit comments