Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f15261b

Browse files
committedMar 10, 2025
[bootstrap] Distribute split debuginfo if present
If debuginfo has been requested in `config.toml`, it should be packaged alongside the appropriate binary when running `x.py dist`. Currently, this is only implemented for msvc environments where split debuginfo is (basically) the only option. I've tested that this correctly packages the `.pdb` for each binary in the various dist packages.
1 parent 2b285cd commit f15261b

File tree

5 files changed

+139
-49
lines changed

5 files changed

+139
-49
lines changed
 

‎src/bootstrap/src/core/build_steps/compile.rs

+26-17
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ fn copy_llvm_libunwind(builder: &Builder<'_>, target: TargetSelection, libdir: &
334334
let libunwind_path = builder.ensure(llvm::Libunwind { target });
335335
let libunwind_source = libunwind_path.join("libunwind.a");
336336
let libunwind_target = libdir.join("libunwind.a");
337-
builder.copy_link(&libunwind_source, &libunwind_target);
337+
builder.copy_link_binary(&libunwind_source, &libunwind_target, target);
338338
libunwind_target
339339
}
340340

@@ -403,9 +403,9 @@ fn copy_self_contained_objects(
403403
let crt_path = builder.ensure(llvm::CrtBeginEnd { target });
404404
for &obj in &["crtbegin.o", "crtbeginS.o", "crtend.o", "crtendS.o"] {
405405
let src = crt_path.join(obj);
406-
let target = libdir_self_contained.join(obj);
407-
builder.copy_link(&src, &target);
408-
target_deps.push((target, DependencyType::TargetSelfContained));
406+
let dst = libdir_self_contained.join(obj);
407+
builder.copy_link_binary(&src, &dst, target);
408+
target_deps.push((dst, DependencyType::TargetSelfContained));
409409
}
410410

411411
if !target.starts_with("s390x") {
@@ -433,9 +433,9 @@ fn copy_self_contained_objects(
433433
} else if target.is_windows_gnu() {
434434
for obj in ["crt2.o", "dllcrt2.o"].iter() {
435435
let src = compiler_file(builder, &builder.cc(target), target, CLang::C, obj);
436-
let target = libdir_self_contained.join(obj);
437-
builder.copy_link(&src, &target);
438-
target_deps.push((target, DependencyType::TargetSelfContained));
436+
let dst = libdir_self_contained.join(obj);
437+
builder.copy_link_binary(&src, &dst, target);
438+
target_deps.push((dst, DependencyType::TargetSelfContained));
439439
}
440440
}
441441

@@ -819,7 +819,7 @@ fn copy_sanitizers(
819819

820820
for runtime in &runtimes {
821821
let dst = libdir.join(&runtime.name);
822-
builder.copy_link(&runtime.path, &dst);
822+
builder.copy_link_binary(&runtime.path, &dst, target);
823823

824824
// The `aarch64-apple-ios-macabi` and `x86_64-apple-ios-macabi` are also supported for
825825
// sanitizers, but they share a sanitizer runtime with `${arch}-apple-darwin`, so we do
@@ -924,9 +924,9 @@ impl Step for StartupObjects {
924924
.run(builder);
925925
}
926926

927-
let target = sysroot_dir.join((*file).to_string() + ".o");
928-
builder.copy_link(dst_file, &target);
929-
target_deps.push((target, DependencyType::Target));
927+
let obj = sysroot_dir.join((*file).to_string() + ".o");
928+
builder.copy_link_binary(dst_file, &obj, target);
929+
target_deps.push((obj, DependencyType::Target));
930930
}
931931

932932
target_deps
@@ -1697,7 +1697,7 @@ fn copy_codegen_backends_to_sysroot(
16971697
let dot = filename.find('.').unwrap();
16981698
format!("{}-{}{}", &filename[..dash], builder.rust_release(), &filename[dot..])
16991699
};
1700-
builder.copy_link(file, &dst.join(target_filename));
1700+
builder.copy_link_binary(file, &dst.join(target_filename), target);
17011701
}
17021702
}
17031703

@@ -2001,7 +2001,11 @@ impl Step for Assemble {
20012001
extra_features: vec![],
20022002
});
20032003
let tool_exe = exe("llvm-bitcode-linker", target_compiler.host);
2004-
builder.copy_link(&llvm_bitcode_linker.tool_path, &libdir_bin.join(tool_exe));
2004+
builder.copy_link_binary(
2005+
&llvm_bitcode_linker.tool_path,
2006+
&libdir_bin.join(tool_exe),
2007+
target_compiler.host,
2008+
);
20052009
}
20062010
};
20072011

@@ -2062,8 +2066,8 @@ impl Step for Assemble {
20622066
builder.sysroot_target_libdir(target_compiler, target_compiler.host);
20632067
let dst_lib = libdir.join(&libenzyme).with_extension(lib_ext);
20642068
let target_dst_lib = target_libdir.join(&libenzyme).with_extension(lib_ext);
2065-
builder.copy_link(&src_lib, &dst_lib);
2066-
builder.copy_link(&src_lib, &target_dst_lib);
2069+
builder.copy_link_binary(&src_lib, &dst_lib, build_compiler.host);
2070+
builder.copy_link_binary(&src_lib, &target_dst_lib, build_compiler.host);
20672071
}
20682072

20692073
// Build the libraries for this compiler to link to (i.e., the libraries
@@ -2186,7 +2190,11 @@ impl Step for Assemble {
21862190
// See <https://github.com/rust-lang/rust/issues/132719>.
21872191
let src_exe = exe("llvm-objcopy", target_compiler.host);
21882192
let dst_exe = exe("rust-objcopy", target_compiler.host);
2189-
builder.copy_link(&libdir_bin.join(src_exe), &libdir_bin.join(dst_exe));
2193+
builder.copy_link_binary(
2194+
&libdir_bin.join(src_exe),
2195+
&libdir_bin.join(dst_exe),
2196+
target_compiler.host,
2197+
);
21902198
}
21912199

21922200
// In addition to `rust-lld` also install `wasm-component-ld` when
@@ -2199,9 +2207,10 @@ impl Step for Assemble {
21992207
compiler: build_compiler,
22002208
target: target_compiler.host,
22012209
});
2202-
builder.copy_link(
2210+
builder.copy_link_binary(
22032211
&wasm_component.tool_path,
22042212
&libdir_bin.join(wasm_component.tool_path.file_name().unwrap()),
2213+
target_compiler.host,
22052214
);
22062215
}
22072216

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

+72-26
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::utils::helpers::{
3232
exe, is_dylib, move_file, t, target_supports_cranelift_backend, timeit,
3333
};
3434
use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball};
35-
use crate::{Compiler, DependencyType, LLVM_TOOLS, Mode, trace};
35+
use crate::{Compiler, DependencyType, LLVM_TOOLS, Mode, split_debuginfo, trace};
3636

3737
pub fn pkgname(builder: &Builder<'_>, component: &str) -> String {
3838
format!("{}-{}", component, builder.rust_package_vers())
@@ -53,6 +53,22 @@ fn should_build_extended_tool(builder: &Builder<'_>, tool: &str) -> bool {
5353
builder.config.tools.as_ref().is_none_or(|tools| tools.contains(tool))
5454
}
5555

56+
/// Add a binary file to the tarball with the appropriate permissions set.
57+
/// If split debuginfo for the binary is present, it is also added to the tarball.
58+
fn tarball_add_binary(
59+
tarball: &Tarball<'_>,
60+
binary: &Path,
61+
dst: impl AsRef<Path>,
62+
target: TargetSelection,
63+
) {
64+
let dst = dst.as_ref();
65+
tarball.add_file(binary, dst, 0o755);
66+
67+
if let Some(debuginfo) = split_debuginfo(binary, target) {
68+
tarball.add_file(debuginfo, dst, 0o644);
69+
}
70+
}
71+
5672
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
5773
pub struct Docs {
5874
pub host: TargetSelection,
@@ -432,7 +448,14 @@ impl Step for Rustc {
432448
},
433449
builder.kind,
434450
) {
435-
builder.install(&ra_proc_macro_srv.tool_path, &image.join("libexec"), 0o755);
451+
let dst = image.join("libexec");
452+
builder.install(&ra_proc_macro_srv.tool_path, &dst, 0o755);
453+
454+
if let Some(debuginfo) =
455+
split_debuginfo(&ra_proc_macro_srv.tool_path, compiler.host)
456+
{
457+
builder.install(&debuginfo, &dst, 0o644);
458+
}
436459
}
437460

438461
let libdir_relative = builder.libdir_relative(compiler);
@@ -463,15 +486,20 @@ impl Step for Rustc {
463486
if builder.config.lld_enabled {
464487
let src_dir = builder.sysroot_target_bindir(compiler, host);
465488
let rust_lld = exe("rust-lld", compiler.host);
466-
builder.copy_link(&src_dir.join(&rust_lld), &dst_dir.join(&rust_lld));
489+
builder.copy_link_binary(
490+
&src_dir.join(&rust_lld),
491+
&dst_dir.join(&rust_lld),
492+
compiler.host,
493+
);
467494
let self_contained_lld_src_dir = src_dir.join("gcc-ld");
468495
let self_contained_lld_dst_dir = dst_dir.join("gcc-ld");
469496
t!(fs::create_dir(&self_contained_lld_dst_dir));
470497
for name in crate::LLD_FILE_NAMES {
471498
let exe_name = exe(name, compiler.host);
472-
builder.copy_link(
499+
builder.copy_link_binary(
473500
&self_contained_lld_src_dir.join(&exe_name),
474501
&self_contained_lld_dst_dir.join(&exe_name),
502+
host,
475503
);
476504
}
477505
}
@@ -480,13 +508,17 @@ impl Step for Rustc {
480508
let src_dir = builder.sysroot_target_bindir(compiler, host);
481509
let llvm_objcopy = exe("llvm-objcopy", compiler.host);
482510
let rust_objcopy = exe("rust-objcopy", compiler.host);
483-
builder.copy_link(&src_dir.join(&llvm_objcopy), &dst_dir.join(&rust_objcopy));
511+
builder.copy_link_binary(
512+
&src_dir.join(&llvm_objcopy),
513+
&dst_dir.join(&rust_objcopy),
514+
host,
515+
);
484516
}
485517

486518
if builder.tool_enabled("wasm-component-ld") {
487519
let src_dir = builder.sysroot_target_bindir(compiler, host);
488520
let ld = exe("wasm-component-ld", compiler.host);
489-
builder.copy_link(&src_dir.join(&ld), &dst_dir.join(&ld));
521+
builder.copy_link_binary(&src_dir.join(&ld), &dst_dir.join(&ld), host);
490522
}
491523

492524
// Man pages
@@ -640,9 +672,13 @@ fn copy_target_libs(
640672
t!(fs::create_dir_all(&self_contained_dst));
641673
for (path, dependency_type) in builder.read_stamp_file(stamp) {
642674
if dependency_type == DependencyType::TargetSelfContained {
643-
builder.copy_link(&path, &self_contained_dst.join(path.file_name().unwrap()));
675+
builder.copy_link_binary(
676+
&path,
677+
&self_contained_dst.join(path.file_name().unwrap()),
678+
target,
679+
);
644680
} else if dependency_type == DependencyType::Target || builder.is_builder_target(target) {
645-
builder.copy_link(&path, &dst.join(path.file_name().unwrap()));
681+
builder.copy_link_binary(&path, &dst.join(path.file_name().unwrap()), target);
646682
}
647683
}
648684
}
@@ -1147,7 +1183,7 @@ impl Step for Cargo {
11471183
let mut tarball = Tarball::new(builder, "cargo", &target.triple);
11481184
tarball.set_overlay(OverlayKind::Cargo);
11491185

1150-
tarball.add_file(cargo.tool_path, "bin", 0o755);
1186+
tarball_add_binary(&tarball, &cargo.tool_path, "bin", target);
11511187
tarball.add_file(etc.join("_cargo"), "share/zsh/site-functions", 0o644);
11521188
tarball.add_renamed_file(etc.join("cargo.bashcomp.sh"), "etc/bash_completion.d", "cargo");
11531189
tarball.add_dir(etc.join("man"), "share/man/man1");
@@ -1193,7 +1229,7 @@ impl Step for Rls {
11931229
let mut tarball = Tarball::new(builder, "rls", &target.triple);
11941230
tarball.set_overlay(OverlayKind::Rls);
11951231
tarball.is_preview(true);
1196-
tarball.add_file(rls.tool_path, "bin", 0o755);
1232+
tarball_add_binary(&tarball, &rls.tool_path, "bin", target);
11971233
tarball.add_legal_and_readme_to("share/doc/rls");
11981234
Some(tarball.generate())
11991235
}
@@ -1235,7 +1271,7 @@ impl Step for RustAnalyzer {
12351271
let mut tarball = Tarball::new(builder, "rust-analyzer", &target.triple);
12361272
tarball.set_overlay(OverlayKind::RustAnalyzer);
12371273
tarball.is_preview(true);
1238-
tarball.add_file(rust_analyzer.tool_path, "bin", 0o755);
1274+
tarball_add_binary(&tarball, &rust_analyzer.tool_path, "bin", target);
12391275
tarball.add_legal_and_readme_to("share/doc/rust-analyzer");
12401276
Some(tarball.generate())
12411277
}
@@ -1281,8 +1317,8 @@ impl Step for Clippy {
12811317
let mut tarball = Tarball::new(builder, "clippy", &target.triple);
12821318
tarball.set_overlay(OverlayKind::Clippy);
12831319
tarball.is_preview(true);
1284-
tarball.add_file(clippy.tool_path, "bin", 0o755);
1285-
tarball.add_file(cargoclippy.tool_path, "bin", 0o755);
1320+
tarball_add_binary(&tarball, &clippy.tool_path, "bin", target);
1321+
tarball_add_binary(&tarball, &cargoclippy.tool_path, "bin", target);
12861322
tarball.add_legal_and_readme_to("share/doc/clippy");
12871323
Some(tarball.generate())
12881324
}
@@ -1331,8 +1367,8 @@ impl Step for Miri {
13311367
let mut tarball = Tarball::new(builder, "miri", &target.triple);
13321368
tarball.set_overlay(OverlayKind::Miri);
13331369
tarball.is_preview(true);
1334-
tarball.add_file(miri.tool_path, "bin", 0o755);
1335-
tarball.add_file(cargomiri.tool_path, "bin", 0o755);
1370+
tarball_add_binary(&tarball, &miri.tool_path, "bin", target);
1371+
tarball_add_binary(&tarball, &cargomiri.tool_path, "bin", target);
13361372
tarball.add_legal_and_readme_to("share/doc/miri");
13371373
Some(tarball.generate())
13381374
}
@@ -1416,7 +1452,12 @@ impl Step for CodegenBackend {
14161452
for backend in fs::read_dir(&backends_src).unwrap() {
14171453
let file_name = backend.unwrap().file_name();
14181454
if file_name.to_str().unwrap().contains(&backend_name) {
1419-
tarball.add_file(backends_src.join(file_name), &backends_dst, 0o644);
1455+
tarball_add_binary(
1456+
&tarball,
1457+
&backends_src.join(file_name),
1458+
&backends_dst,
1459+
compiler.host,
1460+
);
14201461
found_backend = true;
14211462
}
14221463
}
@@ -1462,8 +1503,8 @@ impl Step for Rustfmt {
14621503
let mut tarball = Tarball::new(builder, "rustfmt", &target.triple);
14631504
tarball.set_overlay(OverlayKind::Rustfmt);
14641505
tarball.is_preview(true);
1465-
tarball.add_file(rustfmt.tool_path, "bin", 0o755);
1466-
tarball.add_file(cargofmt.tool_path, "bin", 0o755);
1506+
tarball_add_binary(&tarball, &rustfmt.tool_path, "bin", target);
1507+
tarball_add_binary(&tarball, &cargofmt.tool_path, "bin", target);
14671508
tarball.add_legal_and_readme_to("share/doc/rustfmt");
14681509
Some(tarball.generate())
14691510
}
@@ -2229,7 +2270,7 @@ impl Step for LlvmTools {
22292270
let dst_bindir = format!("lib/rustlib/{}/bin", target.triple);
22302271
for tool in tools_to_install(&builder.paths) {
22312272
let exe = src_bindir.join(exe(tool, target));
2232-
tarball.add_file(&exe, &dst_bindir, 0o755);
2273+
tarball_add_binary(&tarball, &exe, &dst_bindir, target);
22332274
}
22342275
}
22352276

@@ -2284,7 +2325,7 @@ impl Step for LlvmBitcodeLinker {
22842325
tarball.set_overlay(OverlayKind::LlvmBitcodeLinker);
22852326
tarball.is_preview(true);
22862327

2287-
tarball.add_file(llbc_linker.tool_path, self_contained_bin_dir, 0o755);
2328+
tarball_add_binary(&tarball, &llbc_linker.tool_path, self_contained_bin_dir, target);
22882329

22892330
Some(tarball.generate())
22902331
}
@@ -2345,7 +2386,7 @@ impl Step for RustDev {
23452386
let entry = t!(entry);
23462387
if entry.file_type().is_file() && !entry.path_is_symlink() {
23472388
let name = entry.file_name().to_str().unwrap();
2348-
tarball.add_file(src_bindir.join(name), "bin", 0o755);
2389+
tarball_add_binary(&tarball, &src_bindir.join(name), "bin", target);
23492390
}
23502391
}
23512392
}
@@ -2357,11 +2398,11 @@ impl Step for RustDev {
23572398
// We don't build LLD on some platforms, so only add it if it exists
23582399
let lld_path = lld_out.join("bin").join(exe("lld", target));
23592400
if lld_path.exists() {
2360-
tarball.add_file(lld_path, "bin", 0o755);
2401+
tarball_add_binary(&tarball, &lld_path, "bin", target);
23612402
}
23622403
}
23632404

2364-
tarball.add_file(builder.llvm_filecheck(target), "bin", 0o755);
2405+
tarball_add_binary(&tarball, &builder.llvm_filecheck(target), "bin", target);
23652406

23662407
// Copy the include directory as well; needed mostly to build
23672408
// librustc_llvm properly (e.g., llvm-config.h is in here). But also
@@ -2422,7 +2463,12 @@ impl Step for Bootstrap {
24222463

24232464
let bootstrap_outdir = &builder.bootstrap_out;
24242465
for file in &["bootstrap", "rustc", "rustdoc", "sccache-plus-cl"] {
2425-
tarball.add_file(bootstrap_outdir.join(exe(file, target)), "bootstrap/bin", 0o755);
2466+
tarball_add_binary(
2467+
&tarball,
2468+
&bootstrap_outdir.join(exe(file, target)),
2469+
"bootstrap/bin",
2470+
target,
2471+
);
24262472
}
24272473

24282474
Some(tarball.generate())
@@ -2455,7 +2501,7 @@ impl Step for BuildManifest {
24552501
let build_manifest = builder.tool_exe(Tool::BuildManifest);
24562502

24572503
let tarball = Tarball::new(builder, "build-manifest", &self.target.triple);
2458-
tarball.add_file(build_manifest, "bin", 0o755);
2504+
tarball_add_binary(&tarball, &build_manifest, "bin", self.target);
24592505
tarball.generate()
24602506
}
24612507
}
@@ -2524,7 +2570,7 @@ impl Step for Gcc {
25242570
fn run(self, builder: &Builder<'_>) -> Self::Output {
25252571
let tarball = Tarball::new(builder, "gcc", &self.target.triple);
25262572
let output = builder.ensure(super::gcc::Gcc { target: self.target });
2527-
tarball.add_file(output.libgccjit, ".", 0o644);
2573+
tarball_add_binary(&tarball, &output.libgccjit, ".", self.target);
25282574
tarball.generate()
25292575
}
25302576
}
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.