@@ -82,22 +82,21 @@ fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
82
82
}
83
83
84
84
/// 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 > {
86
86
match aux_type {
87
+ AuxType :: Bin => None ,
87
88
// In some casess (e.g. MUSL), we build a static
88
89
// library, rather than a dynamic library.
89
90
// In this case, the only path we can pass
90
91
// 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
+ } ) ,
101
100
}
102
101
}
103
102
@@ -2152,7 +2151,14 @@ impl<'test> TestCx<'test> {
2152
2151
let aux_type = self . build_auxiliary ( of, & aux_path, & aux_dir) ;
2153
2152
let lib_name =
2154
2153
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
+ }
2156
2162
}
2157
2163
}
2158
2164
@@ -2201,7 +2207,15 @@ impl<'test> TestCx<'test> {
2201
2207
}
2202
2208
aux_rustc. envs ( aux_props. rustc_env . clone ( ) ) ;
2203
2209
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 {
2205
2219
( AuxType :: Dylib , None )
2206
2220
} else if self . config . target . contains ( "emscripten" )
2207
2221
|| ( self . config . target . contains ( "musl" )
@@ -4913,6 +4927,7 @@ enum LinkToAux {
4913
4927
}
4914
4928
4915
4929
enum AuxType {
4930
+ Bin ,
4916
4931
Lib ,
4917
4932
Dylib ,
4918
4933
}
0 commit comments