Skip to content

Commit c6224c6

Browse files
authored
Unrolled build for rust-lang#130302
Rollup merge of rust-lang#130302 - onur-ozkan:130040-with-fixes, r=Kobzol add llvm-bitcode-linker and llvm-tools bins to ci-rustc's sysroot rust-lang#130040 is [reverted](rust-lang#130292) because adding component binaries directly to the dist tarball of the compiler caused conflicts (see rust-lang#130291 and rust-lang/rustup#4019). This PR solves the original problem without touching the dist tarball. r? Kobzol
2 parents 23b04c0 + af33be5 commit c6224c6

File tree

1 file changed

+47
-39
lines changed

1 file changed

+47
-39
lines changed

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

+47-39
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,49 @@ impl Step for Assemble {
17601760
return target_compiler;
17611761
}
17621762

1763+
// We prepend this bin directory to the user PATH when linking Rust binaries. To
1764+
// avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
1765+
let libdir = builder.sysroot_libdir(target_compiler, target_compiler.host);
1766+
let libdir_bin = libdir.parent().unwrap().join("bin");
1767+
t!(fs::create_dir_all(&libdir_bin));
1768+
1769+
if builder.config.llvm_enabled(target_compiler.host) {
1770+
let llvm::LlvmResult { llvm_config, .. } =
1771+
builder.ensure(llvm::Llvm { target: target_compiler.host });
1772+
if !builder.config.dry_run() && builder.config.llvm_tools_enabled {
1773+
let llvm_bin_dir =
1774+
command(llvm_config).arg("--bindir").run_capture_stdout(builder).stdout();
1775+
let llvm_bin_dir = Path::new(llvm_bin_dir.trim());
1776+
1777+
// Since we've already built the LLVM tools, install them to the sysroot.
1778+
// This is the equivalent of installing the `llvm-tools-preview` component via
1779+
// rustup, and lets developers use a locally built toolchain to
1780+
// build projects that expect llvm tools to be present in the sysroot
1781+
// (e.g. the `bootimage` crate).
1782+
for tool in LLVM_TOOLS {
1783+
let tool_exe = exe(tool, target_compiler.host);
1784+
let src_path = llvm_bin_dir.join(&tool_exe);
1785+
// When using `download-ci-llvm`, some of the tools
1786+
// may not exist, so skip trying to copy them.
1787+
if src_path.exists() {
1788+
builder.copy_link(&src_path, &libdir_bin.join(&tool_exe));
1789+
}
1790+
}
1791+
}
1792+
}
1793+
1794+
let maybe_install_llvm_bitcode_linker = |compiler| {
1795+
if builder.config.llvm_bitcode_linker_enabled {
1796+
let src_path = builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker {
1797+
compiler,
1798+
target: target_compiler.host,
1799+
extra_features: vec![],
1800+
});
1801+
let tool_exe = exe("llvm-bitcode-linker", target_compiler.host);
1802+
builder.copy_link(&src_path, &libdir_bin.join(tool_exe));
1803+
}
1804+
};
1805+
17631806
// If we're downloading a compiler from CI, we can use the same compiler for all stages other than 0.
17641807
if builder.download_rustc() {
17651808
builder.ensure(Std::new(target_compiler, target_compiler.host));
@@ -1772,6 +1815,9 @@ impl Step for Assemble {
17721815
if target_compiler.stage == builder.top_stage {
17731816
builder.info(&format!("Creating a sysroot for stage{stage} compiler (use `rustup toolchain link 'name' build/host/stage{stage}`)", stage=target_compiler.stage));
17741817
}
1818+
1819+
maybe_install_llvm_bitcode_linker(target_compiler);
1820+
17751821
return target_compiler;
17761822
}
17771823

@@ -1880,11 +1926,6 @@ impl Step for Assemble {
18801926

18811927
copy_codegen_backends_to_sysroot(builder, build_compiler, target_compiler);
18821928

1883-
// We prepend this bin directory to the user PATH when linking Rust binaries. To
1884-
// avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
1885-
let libdir = builder.sysroot_libdir(target_compiler, target_compiler.host);
1886-
let libdir_bin = libdir.parent().unwrap().join("bin");
1887-
t!(fs::create_dir_all(&libdir_bin));
18881929
if let Some(lld_install) = lld_install {
18891930
let src_exe = exe("lld", target_compiler.host);
18901931
let dst_exe = exe("rust-lld", target_compiler.host);
@@ -1920,40 +1961,7 @@ impl Step for Assemble {
19201961
);
19211962
}
19221963

1923-
if builder.config.llvm_enabled(target_compiler.host) {
1924-
let llvm::LlvmResult { llvm_config, .. } =
1925-
builder.ensure(llvm::Llvm { target: target_compiler.host });
1926-
if !builder.config.dry_run() && builder.config.llvm_tools_enabled {
1927-
let llvm_bin_dir =
1928-
command(llvm_config).arg("--bindir").run_capture_stdout(builder).stdout();
1929-
let llvm_bin_dir = Path::new(llvm_bin_dir.trim());
1930-
1931-
// Since we've already built the LLVM tools, install them to the sysroot.
1932-
// This is the equivalent of installing the `llvm-tools-preview` component via
1933-
// rustup, and lets developers use a locally built toolchain to
1934-
// build projects that expect llvm tools to be present in the sysroot
1935-
// (e.g. the `bootimage` crate).
1936-
for tool in LLVM_TOOLS {
1937-
let tool_exe = exe(tool, target_compiler.host);
1938-
let src_path = llvm_bin_dir.join(&tool_exe);
1939-
// When using `download-ci-llvm`, some of the tools
1940-
// may not exist, so skip trying to copy them.
1941-
if src_path.exists() {
1942-
builder.copy_link(&src_path, &libdir_bin.join(&tool_exe));
1943-
}
1944-
}
1945-
}
1946-
}
1947-
1948-
if builder.config.llvm_bitcode_linker_enabled {
1949-
let src_path = builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker {
1950-
compiler: build_compiler,
1951-
target: target_compiler.host,
1952-
extra_features: vec![],
1953-
});
1954-
let tool_exe = exe("llvm-bitcode-linker", target_compiler.host);
1955-
builder.copy_link(&src_path, &libdir_bin.join(tool_exe));
1956-
}
1964+
maybe_install_llvm_bitcode_linker(build_compiler);
19571965

19581966
// Ensure that `libLLVM.so` ends up in the newly build compiler directory,
19591967
// so that it can be found when the newly built `rustc` is run.

0 commit comments

Comments
 (0)