Skip to content

Commit a052a82

Browse files
committed
bootstrap: split runtime DLL part out of make_win_dist
1 parent c8a5ba5 commit a052a82

File tree

1 file changed

+64
-59
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+64
-59
lines changed

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 64 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -174,36 +174,12 @@ fn find_files(files: &[&str], path: &[PathBuf]) -> Vec<PathBuf> {
174174
found
175175
}
176176

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<'_>) {
183178
if builder.config.dry_run() {
184179
return;
185180
}
186181

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);
207183

208184
let compiler = if target == "i686-pc-windows-gnu" {
209185
"i686-w64-mingw32-gcc.exe"
@@ -213,12 +189,6 @@ fn make_win_dist(
213189
"gcc.exe"
214190
};
215191
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-
}
222192

223193
// Libraries necessary to link the windows-gnu toolchains.
224194
// System libraries will be preferred if they are available (see #67429).
@@ -274,25 +244,8 @@ fn make_win_dist(
274244

275245
//Find mingw artifacts we want to bundle
276246
let target_tools = find_files(&target_tools, &bin_path);
277-
let rustc_dlls = find_files(&rustc_dlls, &bin_path);
278247
let target_libs = find_files(&target_libs, &lib_path);
279248

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-
296249
//Copy platform tools to platform-specific bin directory
297250
let plat_target_bin_self_contained_dir =
298251
plat_root.join("lib/rustlib").join(target).join("bin/self-contained");
@@ -320,6 +273,65 @@ fn make_win_dist(
320273
}
321274
}
322275

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, _) = get_cc_search_dirs(target, builder);
282+
283+
let mut rustc_dlls = vec!["libwinpthread-1.dll"];
284+
if target.starts_with("i686-") {
285+
rustc_dlls.push("libgcc_s_dw2-1.dll");
286+
} else {
287+
rustc_dlls.push("libgcc_s_seh-1.dll");
288+
}
289+
let rustc_dlls = find_files(&rustc_dlls, &bin_path);
290+
291+
// Copy runtime dlls next to rustc.exe
292+
let rust_bin_dir = rust_root.join("bin/");
293+
fs::create_dir_all(&rust_bin_dir).expect("creating rust_bin_dir failed");
294+
for src in &rustc_dlls {
295+
builder.copy_link_to_folder(src, &rust_bin_dir);
296+
}
297+
298+
if builder.config.lld_enabled {
299+
// rust-lld.exe also needs runtime dlls
300+
let rust_target_bin_dir = rust_root.join("lib/rustlib").join(target).join("bin");
301+
fs::create_dir_all(&rust_target_bin_dir).expect("creating rust_target_bin_dir failed");
302+
for src in &rustc_dlls {
303+
builder.copy_link_to_folder(src, &rust_target_bin_dir);
304+
}
305+
}
306+
}
307+
308+
fn get_cc_search_dirs(
309+
target: TargetSelection,
310+
builder: &Builder<'_>,
311+
) -> (Vec<PathBuf>, Vec<PathBuf>) {
312+
//Ask gcc where it keeps its stuff
313+
let mut cmd = command(builder.cc(target));
314+
cmd.arg("-print-search-dirs");
315+
let gcc_out = cmd.run_capture_stdout(builder).stdout();
316+
317+
let mut bin_path: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect();
318+
let mut lib_path = Vec::new();
319+
320+
for line in gcc_out.lines() {
321+
let idx = line.find(':').unwrap();
322+
let key = &line[..idx];
323+
let trim_chars: &[_] = &[' ', '='];
324+
let value = env::split_paths(line[(idx + 1)..].trim_start_matches(trim_chars));
325+
326+
if key == "programs" {
327+
bin_path.extend(value);
328+
} else if key == "libraries" {
329+
lib_path.extend(value);
330+
}
331+
}
332+
(bin_path, lib_path)
333+
}
334+
323335
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
324336
pub struct Mingw {
325337
pub host: TargetSelection,
@@ -350,11 +362,7 @@ impl Step for Mingw {
350362
let mut tarball = Tarball::new(builder, "rust-mingw", &host.triple);
351363
tarball.set_product_name("Rust MinGW");
352364

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);
365+
make_win_dist(tarball.image_dir(), host, builder);
358366

359367
Some(tarball.generate())
360368
}
@@ -394,17 +402,14 @@ impl Step for Rustc {
394402
prepare_image(builder, compiler, tarball.image_dir());
395403

396404
// 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-
//
405+
// include.
401406
// On 32-bit MinGW we're always including a DLL which needs some extra
402407
// licenses to distribute. On 64-bit MinGW we don't actually distribute
403408
// anything requiring us to distribute a license, but it's likely the
404409
// install will *also* include the rust-mingw package, which also needs
405410
// licenses, so to be safe we just include it here in all MinGW packages.
406411
if host.ends_with("pc-windows-gnu") && builder.config.dist_include_mingw_linker {
407-
make_win_dist(tarball.image_dir(), &tmpdir(builder), host, builder);
412+
runtime_dll_dist(tarball.image_dir(), host, builder);
408413
tarball.add_dir(builder.src.join("src/etc/third-party"), "share/doc");
409414
}
410415

0 commit comments

Comments
 (0)