Skip to content

Commit adaff53

Browse files
committed
Auto merge of rust-lang#130040 - onur-ozkan:llvm-tools-with-ci-rustc, r=Kobzol
unify `llvm-bitcode-linker`, `wasm-component-ld` and llvm-tools logics To use the precompiled `ci-rustc` in CI, we need to install `llvm-bitcode-linker` and LLVM tools into ci-rustc's sysroot. Without them some CI pipelines may fail, as shown [here](rust-lang#122709 (comment)). Blocker for rust-lang#122709
2 parents 2e8db5e + 4967093 commit adaff53

File tree

2 files changed

+121
-50
lines changed

2 files changed

+121
-50
lines changed

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

+19-45
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::utils::exec::command;
2929
use crate::utils::helpers::{
3030
self, exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
3131
};
32-
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode, LLVM_TOOLS};
32+
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode};
3333

3434
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3535
pub struct Std {
@@ -1908,52 +1908,26 @@ impl Step for Assemble {
19081908
// delegates to the `rust-lld` binary for linking and then runs
19091909
// logic to create the final binary. This is used by the
19101910
// `wasm32-wasip2` target of Rust.
1911-
if builder.tool_enabled("wasm-component-ld") {
1912-
let wasm_component_ld_exe =
1913-
builder.ensure(crate::core::build_steps::tool::WasmComponentLd {
1914-
compiler: build_compiler,
1915-
target: target_compiler.host,
1916-
});
1917-
builder.copy_link(
1918-
&wasm_component_ld_exe,
1919-
&libdir_bin.join(wasm_component_ld_exe.file_name().unwrap()),
1920-
);
1921-
}
1911+
dist::maybe_install_wasm_component_ld(
1912+
builder,
1913+
build_compiler,
1914+
target_compiler.host,
1915+
&libdir_bin,
1916+
false,
1917+
);
19221918

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-
}
1919+
dist::maybe_install_llvm_tools(builder, target_compiler.host, &libdir_bin, false);
19471920

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-
}
1921+
let self_contained_bin_dir = libdir_bin.join("self-contained");
1922+
t!(fs::create_dir_all(&self_contained_bin_dir));
1923+
1924+
dist::maybe_install_llvm_bitcode_linker(
1925+
builder,
1926+
build_compiler,
1927+
target_compiler.host,
1928+
&self_contained_bin_dir,
1929+
false,
1930+
);
19571931

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

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

+102-5
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,29 @@ impl Step for Rustc {
473473
);
474474
}
475475
}
476-
if builder.tool_enabled("wasm-component-ld") {
477-
let src_dir = builder.sysroot_libdir(compiler, host).parent().unwrap().join("bin");
478-
let ld = exe("wasm-component-ld", compiler.host);
479-
builder.copy_link(&src_dir.join(&ld), &dst_dir.join(&ld));
480-
}
476+
477+
let builder_compiler =
478+
builder.compiler_for(builder.top_stage, builder.config.build, compiler.host);
479+
480+
maybe_install_wasm_component_ld(
481+
builder,
482+
builder_compiler,
483+
compiler.host,
484+
&dst_dir,
485+
true,
486+
);
487+
488+
let self_contained_bin_dir = dst_dir.join("self-contained");
489+
t!(fs::create_dir_all(&self_contained_bin_dir));
490+
maybe_install_llvm_bitcode_linker(
491+
builder,
492+
builder_compiler,
493+
compiler.host,
494+
&self_contained_bin_dir,
495+
true,
496+
);
497+
498+
maybe_install_llvm_tools(builder, compiler.host, &dst_dir, true);
481499

482500
// Man pages
483501
t!(fs::create_dir_all(image.join("share/man/man1")));
@@ -2086,6 +2104,85 @@ pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection
20862104
}
20872105
}
20882106

2107+
/// Maybe add LLVM tools to the rustc sysroot.
2108+
pub fn maybe_install_llvm_tools(
2109+
builder: &Builder<'_>,
2110+
target: TargetSelection,
2111+
dst_dir: &Path,
2112+
dereference_symlinks: bool,
2113+
) {
2114+
if builder.config.llvm_enabled(target) {
2115+
let llvm::LlvmResult { llvm_config, .. } = builder.ensure(llvm::Llvm { target });
2116+
if !builder.config.dry_run() && builder.config.llvm_tools_enabled {
2117+
let llvm_bin_dir =
2118+
command(llvm_config).arg("--bindir").run_capture_stdout(builder).stdout();
2119+
let llvm_bin_dir = Path::new(llvm_bin_dir.trim());
2120+
2121+
// Since we've already built the LLVM tools, install them to the sysroot.
2122+
// This is the equivalent of installing the `llvm-tools-preview` component via
2123+
// rustup, and lets developers use a locally built toolchain to
2124+
// build projects that expect llvm tools to be present in the sysroot
2125+
// (e.g. the `bootimage` crate).
2126+
for tool in LLVM_TOOLS {
2127+
let tool_exe = exe(tool, target);
2128+
let src_path = llvm_bin_dir.join(&tool_exe);
2129+
// When using `download-ci-llvm`, some of the tools
2130+
// may not exist, so skip trying to copy them.
2131+
if src_path.exists() {
2132+
builder.copy_link_internal(
2133+
&src_path,
2134+
&dst_dir.join(&tool_exe),
2135+
dereference_symlinks,
2136+
);
2137+
}
2138+
}
2139+
}
2140+
}
2141+
}
2142+
2143+
/// Maybe add `llvm-bitcode-linker` to the rustc sysroot.
2144+
pub fn maybe_install_llvm_bitcode_linker(
2145+
builder: &Builder<'_>,
2146+
builder_compiler: Compiler,
2147+
target: TargetSelection,
2148+
dst_dir: &Path,
2149+
dereference_symlinks: bool,
2150+
) {
2151+
if builder.config.llvm_bitcode_linker_enabled {
2152+
let llvm_bitcode_linker_exe = builder.ensure(tool::LlvmBitcodeLinker {
2153+
compiler: builder_compiler,
2154+
target,
2155+
extra_features: vec![],
2156+
});
2157+
2158+
builder.copy_link_internal(
2159+
&llvm_bitcode_linker_exe,
2160+
&dst_dir.join(llvm_bitcode_linker_exe.file_name().unwrap()),
2161+
dereference_symlinks,
2162+
);
2163+
}
2164+
}
2165+
2166+
/// Maybe add `wasm-component-ld` to the rustc sysroot.
2167+
pub fn maybe_install_wasm_component_ld(
2168+
builder: &Builder<'_>,
2169+
builder_compiler: Compiler,
2170+
target: TargetSelection,
2171+
dst_dir: &Path,
2172+
dereference_symlinks: bool,
2173+
) {
2174+
if builder.tool_enabled("wasm-component-ld") {
2175+
let wasm_component_ld_exe =
2176+
builder.ensure(tool::WasmComponentLd { compiler: builder_compiler, target });
2177+
2178+
builder.copy_link_internal(
2179+
&wasm_component_ld_exe,
2180+
&dst_dir.join(wasm_component_ld_exe.file_name().unwrap()),
2181+
dereference_symlinks,
2182+
);
2183+
}
2184+
}
2185+
20892186
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
20902187
pub struct LlvmTools {
20912188
pub target: TargetSelection,

0 commit comments

Comments
 (0)