Skip to content

Commit ad66eae

Browse files
authored
Rollup merge of rust-lang#144659 - mati865:gnullvm-vendor-libunwind, r=Kobzol
bootstrap: refactor mingw dist and fix gnullvm Fixes rust-lang#144533 The first two commits are NFC and only clean up the code, paving the way for the third commit. That said, I think they are worthwhile even without that fix - reusing the same function for two different outcomes was confusing. The third commit is the fix for rust-lang#144533, but due to the cross-compilation dance it requires a workaround to find the DLL since that logic really was meant only for Windows builders. That workaround is short-lived and will be removed as soon as gnullvm bootstraps itself.
2 parents f9de0ac + d2e3ea9 commit ad66eae

File tree

1 file changed

+82
-60
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+82
-60
lines changed

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

Lines changed: 82 additions & 60 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,82 @@ 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, 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 if target.ends_with("windows-gnullvm") {
293+
rustc_dlls.push("libunwind.dll");
294+
} else {
295+
panic!("Vendoring of runtime DLLs for `{target}` is not supported`");
296+
}
297+
// FIXME(#144656): Remove this whole `let ...`
298+
let bin_path = if target.ends_with("windows-gnullvm") && builder.host_target != target {
299+
bin_path
300+
.into_iter()
301+
.chain(libs_path.iter().map(|path| path.with_file_name("bin")))
302+
.collect()
303+
} else {
304+
bin_path
305+
};
306+
let rustc_dlls = find_files(&rustc_dlls, &bin_path);
307+
308+
// Copy runtime dlls next to rustc.exe
309+
let rust_bin_dir = rust_root.join("bin/");
310+
fs::create_dir_all(&rust_bin_dir).expect("creating rust_bin_dir failed");
311+
for src in &rustc_dlls {
312+
builder.copy_link_to_folder(src, &rust_bin_dir);
313+
}
314+
315+
if builder.config.lld_enabled {
316+
// rust-lld.exe also needs runtime dlls
317+
let rust_target_bin_dir = rust_root.join("lib/rustlib").join(target).join("bin");
318+
fs::create_dir_all(&rust_target_bin_dir).expect("creating rust_target_bin_dir failed");
319+
for src in &rustc_dlls {
320+
builder.copy_link_to_folder(src, &rust_target_bin_dir);
321+
}
322+
}
323+
}
324+
325+
fn get_cc_search_dirs(
326+
target: TargetSelection,
327+
builder: &Builder<'_>,
328+
) -> (Vec<PathBuf>, Vec<PathBuf>) {
329+
//Ask gcc where it keeps its stuff
330+
let mut cmd = command(builder.cc(target));
331+
cmd.arg("-print-search-dirs");
332+
let gcc_out = cmd.run_capture_stdout(builder).stdout();
333+
334+
let mut bin_path: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect();
335+
let mut lib_path = Vec::new();
336+
337+
for line in gcc_out.lines() {
338+
let idx = line.find(':').unwrap();
339+
let key = &line[..idx];
340+
let trim_chars: &[_] = &[' ', '='];
341+
let value = env::split_paths(line[(idx + 1)..].trim_start_matches(trim_chars));
342+
343+
if key == "programs" {
344+
bin_path.extend(value);
345+
} else if key == "libraries" {
346+
lib_path.extend(value);
347+
}
348+
}
349+
(bin_path, lib_path)
350+
}
351+
323352
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
324353
pub struct Mingw {
325354
pub host: TargetSelection,
@@ -350,11 +379,7 @@ impl Step for Mingw {
350379
let mut tarball = Tarball::new(builder, "rust-mingw", &host.triple);
351380
tarball.set_product_name("Rust MinGW");
352381

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

359384
Some(tarball.generate())
360385
}
@@ -394,17 +419,14 @@ impl Step for Rustc {
394419
prepare_image(builder, compiler, tarball.image_dir());
395420

396421
// 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-
//
422+
// include.
401423
// On 32-bit MinGW we're always including a DLL which needs some extra
402424
// licenses to distribute. On 64-bit MinGW we don't actually distribute
403425
// anything requiring us to distribute a license, but it's likely the
404426
// install will *also* include the rust-mingw package, which also needs
405427
// 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);
428+
if host.contains("pc-windows-gnu") && builder.config.dist_include_mingw_linker {
429+
runtime_dll_dist(tarball.image_dir(), host, builder);
408430
tarball.add_dir(builder.src.join("src/etc/third-party"), "share/doc");
409431
}
410432

0 commit comments

Comments
 (0)