@@ -82,21 +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
- pub fn get_lib_name ( lib : & str , dylib : bool ) -> String {
86
- // In some casess (e.g. MUSL), we build a static
87
- // library, rather than a dynamic library.
88
- // In this case, the only path we can pass
89
- // with '--extern-meta' is the '.lib' file
90
- if !dylib {
91
- return format ! ( "lib{} .rlib" , lib ) ;
92
- }
93
-
94
- if cfg ! ( windows ) {
95
- format ! ( "{}.dll" , lib )
96
- } else if cfg ! ( target_os = "macos" ) {
97
- format ! ( "lib{}.dylib" , lib )
98
- } else {
99
- format ! ( "lib{}.so" , lib )
85
+ fn get_lib_name ( lib : & str , aux_type : AuxType ) -> Option < String > {
86
+ match aux_type {
87
+ AuxType :: Bin => None ,
88
+ // In some cases (e.g. MUSL), we build a static
89
+ // library, rather than a dynamic library.
90
+ // In this case, the only path we can pass
91
+ // with '--extern-meta' is the ' .rlib' file
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
+ } ) ,
100
100
}
101
101
}
102
102
@@ -2098,19 +2098,36 @@ impl<'test> TestCx<'test> {
2098
2098
create_dir_all ( & aux_dir) . unwrap ( ) ;
2099
2099
}
2100
2100
2101
+ if !self . props . aux_bins . is_empty ( ) {
2102
+ let aux_bin_dir = self . aux_bin_output_dir_name ( ) ;
2103
+ let _ = fs:: remove_dir_all ( & aux_bin_dir) ;
2104
+ create_dir_all ( & aux_bin_dir) . unwrap ( ) ;
2105
+ }
2106
+
2101
2107
aux_dir
2102
2108
}
2103
2109
2104
2110
fn build_all_auxiliary ( & self , of : & TestPaths , aux_dir : & Path , rustc : & mut Command ) {
2105
2111
for rel_ab in & self . props . aux_builds {
2106
- self . build_auxiliary ( of, rel_ab, & aux_dir) ;
2112
+ self . build_auxiliary ( of, rel_ab, & aux_dir, false /* is_bin */ ) ;
2113
+ }
2114
+
2115
+ for rel_ab in & self . props . aux_bins {
2116
+ self . build_auxiliary ( of, rel_ab, & aux_dir, true /* is_bin */ ) ;
2107
2117
}
2108
2118
2109
2119
for ( aux_name, aux_path) in & self . props . aux_crates {
2110
- let is_dylib = self . build_auxiliary ( of, & aux_path, & aux_dir) ;
2120
+ let aux_type = self . build_auxiliary ( of, & aux_path, & aux_dir, false /* is_bin */ ) ;
2111
2121
let lib_name =
2112
- get_lib_name ( & aux_path. trim_end_matches ( ".rs" ) . replace ( '-' , "_" ) , is_dylib) ;
2113
- rustc. arg ( "--extern" ) . arg ( format ! ( "{}={}/{}" , aux_name, aux_dir. display( ) , lib_name) ) ;
2122
+ get_lib_name ( & aux_path. trim_end_matches ( ".rs" ) . replace ( '-' , "_" ) , aux_type) ;
2123
+ if let Some ( lib_name) = lib_name {
2124
+ rustc. arg ( "--extern" ) . arg ( format ! (
2125
+ "{}={}/{}" ,
2126
+ aux_name,
2127
+ aux_dir. display( ) ,
2128
+ lib_name
2129
+ ) ) ;
2130
+ }
2114
2131
}
2115
2132
}
2116
2133
@@ -2129,12 +2146,23 @@ impl<'test> TestCx<'test> {
2129
2146
}
2130
2147
2131
2148
/// Builds an aux dependency.
2132
- ///
2133
- /// Returns whether or not it is a dylib.
2134
- fn build_auxiliary ( & self , of : & TestPaths , source_path : & str , aux_dir : & Path ) -> bool {
2149
+ fn build_auxiliary (
2150
+ & self ,
2151
+ of : & TestPaths ,
2152
+ source_path : & str ,
2153
+ aux_dir : & Path ,
2154
+ is_bin : bool ,
2155
+ ) -> AuxType {
2135
2156
let aux_testpaths = self . compute_aux_test_paths ( of, source_path) ;
2136
2157
let aux_props = self . props . from_aux_file ( & aux_testpaths. file , self . revision , self . config ) ;
2137
- let aux_output = TargetLocation :: ThisDirectory ( aux_dir. to_path_buf ( ) ) ;
2158
+ let mut aux_dir = aux_dir. to_path_buf ( ) ;
2159
+ if is_bin {
2160
+ // On unix, the binary of `auxiliary/foo.rs` will be named
2161
+ // `auxiliary/foo` which clashes with the _dir_ `auxiliary/foo`, so
2162
+ // put bins in a `bin` subfolder.
2163
+ aux_dir. push ( "bin" ) ;
2164
+ }
2165
+ let aux_output = TargetLocation :: ThisDirectory ( aux_dir. clone ( ) ) ;
2138
2166
let aux_cx = TestCx {
2139
2167
config : self . config ,
2140
2168
props : & aux_props,
@@ -2152,15 +2180,17 @@ impl<'test> TestCx<'test> {
2152
2180
LinkToAux :: No ,
2153
2181
Vec :: new ( ) ,
2154
2182
) ;
2155
- aux_cx. build_all_auxiliary ( of, aux_dir, & mut aux_rustc) ;
2183
+ aux_cx. build_all_auxiliary ( of, & aux_dir, & mut aux_rustc) ;
2156
2184
2157
2185
for key in & aux_props. unset_rustc_env {
2158
2186
aux_rustc. env_remove ( key) ;
2159
2187
}
2160
2188
aux_rustc. envs ( aux_props. rustc_env . clone ( ) ) ;
2161
2189
2162
- let ( dylib, crate_type) = if aux_props. no_prefer_dynamic {
2163
- ( true , None )
2190
+ let ( aux_type, crate_type) = if is_bin {
2191
+ ( AuxType :: Bin , Some ( "bin" ) )
2192
+ } else if aux_props. no_prefer_dynamic {
2193
+ ( AuxType :: Dylib , None )
2164
2194
} else if self . config . target . contains ( "emscripten" )
2165
2195
|| ( self . config . target . contains ( "musl" )
2166
2196
&& !aux_props. force_host
@@ -2185,9 +2215,9 @@ impl<'test> TestCx<'test> {
2185
2215
// Coverage tests want static linking by default so that coverage
2186
2216
// mappings in auxiliary libraries can be merged into the final
2187
2217
// executable.
2188
- ( false , Some ( "lib" ) )
2218
+ ( AuxType :: Lib , Some ( "lib" ) )
2189
2219
} else {
2190
- ( true , Some ( "dylib" ) )
2220
+ ( AuxType :: Dylib , Some ( "dylib" ) )
2191
2221
} ;
2192
2222
2193
2223
if let Some ( crate_type) = crate_type {
@@ -2211,7 +2241,7 @@ impl<'test> TestCx<'test> {
2211
2241
& auxres,
2212
2242
) ;
2213
2243
}
2214
- dylib
2244
+ aux_type
2215
2245
}
2216
2246
2217
2247
fn read2_abbreviated ( & self , child : Child ) -> ( Output , Truncated ) {
@@ -2677,6 +2707,12 @@ impl<'test> TestCx<'test> {
2677
2707
. with_extra_extension ( self . config . mode . aux_dir_disambiguator ( ) )
2678
2708
}
2679
2709
2710
+ /// Gets the directory where auxiliary binaries are written.
2711
+ /// E.g., `/.../testname.revision.mode/auxiliary/bin`.
2712
+ fn aux_bin_output_dir_name ( & self ) -> PathBuf {
2713
+ self . aux_output_dir_name ( ) . join ( "bin" )
2714
+ }
2715
+
2680
2716
/// Generates a unique name for the test, such as `testname.revision.mode`.
2681
2717
fn output_testname_unique ( & self ) -> PathBuf {
2682
2718
output_testname_unique ( self . config , self . testpaths , self . safe_revision ( ) )
@@ -4826,3 +4862,9 @@ enum LinkToAux {
4826
4862
Yes ,
4827
4863
No ,
4828
4864
}
4865
+
4866
+ enum AuxType {
4867
+ Bin ,
4868
+ Lib ,
4869
+ Dylib ,
4870
+ }
0 commit comments