@@ -174,36 +174,12 @@ fn find_files(files: &[&str], path: &[PathBuf]) -> Vec<PathBuf> {
174
174
found
175
175
}
176
176
177
- fn make_win_dist (
178
- rust_root : & Path ,
179
- plat_root : & Path ,
180
- target : TargetSelection ,
181
- builder : & Builder < ' _ > ,
182
- ) {
177
+ fn make_win_dist ( plat_root : & Path , target : TargetSelection , builder : & Builder < ' _ > ) {
183
178
if builder. config . dry_run ( ) {
184
179
return ;
185
180
}
186
181
187
- //Ask gcc where it keeps its stuff
188
- let mut cmd = command ( builder. cc ( target) ) ;
189
- cmd. arg ( "-print-search-dirs" ) ;
190
- let gcc_out = cmd. run_capture_stdout ( builder) . stdout ( ) ;
191
-
192
- let mut bin_path: Vec < _ > = env:: split_paths ( & env:: var_os ( "PATH" ) . unwrap_or_default ( ) ) . collect ( ) ;
193
- let mut lib_path = Vec :: new ( ) ;
194
-
195
- for line in gcc_out. lines ( ) {
196
- let idx = line. find ( ':' ) . unwrap ( ) ;
197
- let key = & line[ ..idx] ;
198
- let trim_chars: & [ _ ] = & [ ' ' , '=' ] ;
199
- let value = env:: split_paths ( line[ ( idx + 1 ) ..] . trim_start_matches ( trim_chars) ) ;
200
-
201
- if key == "programs" {
202
- bin_path. extend ( value) ;
203
- } else if key == "libraries" {
204
- lib_path. extend ( value) ;
205
- }
206
- }
182
+ let ( bin_path, lib_path) = get_cc_search_dirs ( target, builder) ;
207
183
208
184
let compiler = if target == "i686-pc-windows-gnu" {
209
185
"i686-w64-mingw32-gcc.exe"
@@ -213,12 +189,6 @@ fn make_win_dist(
213
189
"gcc.exe"
214
190
} ;
215
191
let target_tools = [ compiler, "ld.exe" , "dlltool.exe" , "libwinpthread-1.dll" ] ;
216
- let mut rustc_dlls = vec ! [ "libwinpthread-1.dll" ] ;
217
- if target. starts_with ( "i686-" ) {
218
- rustc_dlls. push ( "libgcc_s_dw2-1.dll" ) ;
219
- } else {
220
- rustc_dlls. push ( "libgcc_s_seh-1.dll" ) ;
221
- }
222
192
223
193
// Libraries necessary to link the windows-gnu toolchains.
224
194
// System libraries will be preferred if they are available (see #67429).
@@ -274,25 +244,8 @@ fn make_win_dist(
274
244
275
245
//Find mingw artifacts we want to bundle
276
246
let target_tools = find_files ( & target_tools, & bin_path) ;
277
- let rustc_dlls = find_files ( & rustc_dlls, & bin_path) ;
278
247
let target_libs = find_files ( & target_libs, & lib_path) ;
279
248
280
- // Copy runtime dlls next to rustc.exe
281
- let rust_bin_dir = rust_root. join ( "bin/" ) ;
282
- fs:: create_dir_all ( & rust_bin_dir) . expect ( "creating rust_bin_dir failed" ) ;
283
- for src in & rustc_dlls {
284
- builder. copy_link_to_folder ( src, & rust_bin_dir) ;
285
- }
286
-
287
- if builder. config . lld_enabled {
288
- // rust-lld.exe also needs runtime dlls
289
- let rust_target_bin_dir = rust_root. join ( "lib/rustlib" ) . join ( target) . join ( "bin" ) ;
290
- fs:: create_dir_all ( & rust_target_bin_dir) . expect ( "creating rust_target_bin_dir failed" ) ;
291
- for src in & rustc_dlls {
292
- builder. copy_link_to_folder ( src, & rust_target_bin_dir) ;
293
- }
294
- }
295
-
296
249
//Copy platform tools to platform-specific bin directory
297
250
let plat_target_bin_self_contained_dir =
298
251
plat_root. join ( "lib/rustlib" ) . join ( target) . join ( "bin/self-contained" ) ;
@@ -320,6 +273,80 @@ fn make_win_dist(
320
273
}
321
274
}
322
275
276
+ fn runtime_dll_dist ( rust_root : & Path , target : TargetSelection , builder : & Builder < ' _ > ) {
277
+ if builder. config . dry_run ( ) {
278
+ return ;
279
+ }
280
+
281
+ let ( bin_path, libs_path) = get_cc_search_dirs ( target, builder) ;
282
+
283
+ let mut rustc_dlls = vec ! [ ] ;
284
+ // windows-gnu and windows-gnullvm require different runtime libs
285
+ if target. ends_with ( "windows-gnu" ) {
286
+ rustc_dlls. push ( "libwinpthread-1.dll" ) ;
287
+ if target. starts_with ( "i686-" ) {
288
+ rustc_dlls. push ( "libgcc_s_dw2-1.dll" ) ;
289
+ } else {
290
+ rustc_dlls. push ( "libgcc_s_seh-1.dll" ) ;
291
+ }
292
+ } else {
293
+ rustc_dlls. push ( "libunwind.dll" ) ;
294
+ }
295
+ // TODO(#144565): Remove this whole `let ...`
296
+ let bin_path = if target. ends_with ( "windows-gnullvm" ) && builder. host_target != target {
297
+ bin_path
298
+ . into_iter ( )
299
+ . chain ( libs_path. iter ( ) . map ( |path| path. with_file_name ( "bin" ) ) )
300
+ . collect ( )
301
+ } else {
302
+ bin_path
303
+ } ;
304
+ let rustc_dlls = find_files ( & rustc_dlls, & bin_path) ;
305
+
306
+ // Copy runtime dlls next to rustc.exe
307
+ let rust_bin_dir = rust_root. join ( "bin/" ) ;
308
+ fs:: create_dir_all ( & rust_bin_dir) . expect ( "creating rust_bin_dir failed" ) ;
309
+ for src in & rustc_dlls {
310
+ builder. copy_link_to_folder ( src, & rust_bin_dir) ;
311
+ }
312
+
313
+ if builder. config . lld_enabled {
314
+ // rust-lld.exe also needs runtime dlls
315
+ let rust_target_bin_dir = rust_root. join ( "lib/rustlib" ) . join ( target) . join ( "bin" ) ;
316
+ fs:: create_dir_all ( & rust_target_bin_dir) . expect ( "creating rust_target_bin_dir failed" ) ;
317
+ for src in & rustc_dlls {
318
+ builder. copy_link_to_folder ( src, & rust_target_bin_dir) ;
319
+ }
320
+ }
321
+ }
322
+
323
+ fn get_cc_search_dirs (
324
+ target : TargetSelection ,
325
+ builder : & Builder < ' _ > ,
326
+ ) -> ( Vec < PathBuf > , Vec < PathBuf > ) {
327
+ //Ask gcc where it keeps its stuff
328
+ let mut cmd = command ( builder. cc ( target) ) ;
329
+ cmd. arg ( "-print-search-dirs" ) ;
330
+ let gcc_out = cmd. run_capture_stdout ( builder) . stdout ( ) ;
331
+
332
+ let mut bin_path: Vec < _ > = env:: split_paths ( & env:: var_os ( "PATH" ) . unwrap_or_default ( ) ) . collect ( ) ;
333
+ let mut lib_path = Vec :: new ( ) ;
334
+
335
+ for line in gcc_out. lines ( ) {
336
+ let idx = line. find ( ':' ) . unwrap ( ) ;
337
+ let key = & line[ ..idx] ;
338
+ let trim_chars: & [ _ ] = & [ ' ' , '=' ] ;
339
+ let value = env:: split_paths ( line[ ( idx + 1 ) ..] . trim_start_matches ( trim_chars) ) ;
340
+
341
+ if key == "programs" {
342
+ bin_path. extend ( value) ;
343
+ } else if key == "libraries" {
344
+ lib_path. extend ( value) ;
345
+ }
346
+ }
347
+ ( bin_path, lib_path)
348
+ }
349
+
323
350
#[ derive( Debug , PartialOrd , Ord , Clone , Hash , PartialEq , Eq ) ]
324
351
pub struct Mingw {
325
352
pub host : TargetSelection ,
@@ -350,11 +377,7 @@ impl Step for Mingw {
350
377
let mut tarball = Tarball :: new ( builder, "rust-mingw" , & host. triple ) ;
351
378
tarball. set_product_name ( "Rust MinGW" ) ;
352
379
353
- // The first argument is a "temporary directory" which is just
354
- // thrown away (this contains the runtime DLLs included in the rustc package
355
- // above) and the second argument is where to place all the MinGW components
356
- // (which is what we want).
357
- make_win_dist ( & tmpdir ( builder) , tarball. image_dir ( ) , host, builder) ;
380
+ make_win_dist ( tarball. image_dir ( ) , host, builder) ;
358
381
359
382
Some ( tarball. generate ( ) )
360
383
}
@@ -394,17 +417,14 @@ impl Step for Rustc {
394
417
prepare_image ( builder, compiler, tarball. image_dir ( ) ) ;
395
418
396
419
// On MinGW we've got a few runtime DLL dependencies that we need to
397
- // include. The first argument to this script is where to put these DLLs
398
- // (the image we're creating), and the second argument is a junk directory
399
- // to ignore all other MinGW stuff the script creates.
400
- //
420
+ // include.
401
421
// On 32-bit MinGW we're always including a DLL which needs some extra
402
422
// licenses to distribute. On 64-bit MinGW we don't actually distribute
403
423
// anything requiring us to distribute a license, but it's likely the
404
424
// install will *also* include the rust-mingw package, which also needs
405
425
// licenses, so to be safe we just include it here in all MinGW packages.
406
- if host. ends_with ( "pc-windows-gnu" ) && builder. config . dist_include_mingw_linker {
407
- make_win_dist ( tarball. image_dir ( ) , & tmpdir ( builder ) , host, builder) ;
426
+ if host. contains ( "pc-windows-gnu" ) && builder. config . dist_include_mingw_linker {
427
+ runtime_dll_dist ( tarball. image_dir ( ) , host, builder) ;
408
428
tarball. add_dir ( builder. src . join ( "src/etc/third-party" ) , "share/doc" ) ;
409
429
}
410
430
0 commit comments