Skip to content

Commit 1d6a85f

Browse files
Rollup merge of rust-lang#110122 - jyn514:check-stage1-llvm, r=ozkanonur
Fix x check --stage 1 when download-ci-llvm=false Bootstrap tries to avoid building LLVM unless it needs to; in particular we only build it for `x build`, not `x check`. Unfortunately, the check forgot about existence of stages - it would break if you used `x check --stage 1`: ``` = note: /usr/bin/ld: cannot find -lPolly: No such file or directory /usr/bin/ld: cannot find -lPollyISL: No such file or directory ``` Fix it to work for stage 1. I recommend reading this commit-by-commit; the first one makes a bunch of whitespace changes but otherwise doesn't change the logic.
2 parents fefd04a + ca3daa0 commit 1d6a85f

File tree

4 files changed

+82
-74
lines changed

4 files changed

+82
-74
lines changed

src/bootstrap/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl Step for Rustc {
237237
target,
238238
cargo_subcommand(builder.kind),
239239
);
240-
rustc_cargo(builder, &mut cargo, target);
240+
rustc_cargo(builder, &mut cargo, target, compiler.stage);
241241

242242
// For ./x.py clippy, don't run with --all-targets because
243243
// linting tests and benchmarks can produce very noisy results
@@ -323,7 +323,7 @@ impl Step for CodegenBackend {
323323
cargo
324324
.arg("--manifest-path")
325325
.arg(builder.src.join(format!("compiler/rustc_codegen_{}/Cargo.toml", backend)));
326-
rustc_cargo_env(builder, &mut cargo, target);
326+
rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
327327

328328
let msg = if compiler.host == target {
329329
format!("Checking stage{} {} artifacts ({target})", builder.top_stage, backend)

src/bootstrap/compile.rs

+78-70
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ impl Step for Rustc {
696696
));
697697

698698
let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "build");
699-
rustc_cargo(builder, &mut cargo, target);
699+
rustc_cargo(builder, &mut cargo, target, compiler.stage);
700700

701701
if builder.config.rust_profile_use.is_some()
702702
&& builder.config.rust_profile_generate.is_some()
@@ -813,16 +813,21 @@ impl Step for Rustc {
813813
}
814814
}
815815

816-
pub fn rustc_cargo(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelection) {
816+
pub fn rustc_cargo(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelection, stage: u32) {
817817
cargo
818818
.arg("--features")
819819
.arg(builder.rustc_features(builder.kind))
820820
.arg("--manifest-path")
821821
.arg(builder.src.join("compiler/rustc/Cargo.toml"));
822-
rustc_cargo_env(builder, cargo, target);
822+
rustc_cargo_env(builder, cargo, target, stage);
823823
}
824824

825-
pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelection) {
825+
pub fn rustc_cargo_env(
826+
builder: &Builder<'_>,
827+
cargo: &mut Cargo,
828+
target: TargetSelection,
829+
stage: u32,
830+
) {
826831
// Set some configuration variables picked up by build scripts and
827832
// the compiler alike
828833
cargo
@@ -867,83 +872,86 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
867872
cargo.env("RUSTC_VERIFY_LLVM_IR", "1");
868873
}
869874

870-
// Pass down configuration from the LLVM build into the build of
871-
// rustc_llvm and rustc_codegen_llvm.
872-
//
873875
// Note that this is disabled if LLVM itself is disabled or we're in a check
874876
// build. If we are in a check build we still go ahead here presuming we've
875877
// detected that LLVM is already built and good to go which helps prevent
876878
// busting caches (e.g. like #71152).
877-
if builder.config.llvm_enabled()
878-
&& (builder.kind != Kind::Check
879-
|| crate::llvm::prebuilt_llvm_config(builder, target).is_ok())
880-
{
881-
if builder.is_rust_llvm(target) {
882-
cargo.env("LLVM_RUSTLLVM", "1");
883-
}
884-
let llvm::LlvmResult { llvm_config, .. } = builder.ensure(llvm::Llvm { target });
885-
cargo.env("LLVM_CONFIG", &llvm_config);
886-
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
887-
cargo.env("CFG_LLVM_ROOT", s);
879+
if builder.config.llvm_enabled() {
880+
let building_is_expensive = crate::llvm::prebuilt_llvm_config(builder, target).is_err();
881+
// `top_stage == stage` might be false for `check --stage 1`, if we are building the stage 1 compiler
882+
let can_skip_build = builder.kind == Kind::Check && builder.top_stage == stage;
883+
let should_skip_build = building_is_expensive && can_skip_build;
884+
if !should_skip_build {
885+
rustc_llvm_env(builder, cargo, target)
888886
}
887+
}
888+
}
889889

890-
// Some LLVM linker flags (-L and -l) may be needed to link `rustc_llvm`. Its build script
891-
// expects these to be passed via the `LLVM_LINKER_FLAGS` env variable, separated by
892-
// whitespace.
893-
//
894-
// For example:
895-
// - on windows, when `clang-cl` is used with instrumentation, we need to manually add
896-
// clang's runtime library resource directory so that the profiler runtime library can be
897-
// found. This is to avoid the linker errors about undefined references to
898-
// `__llvm_profile_instrument_memop` when linking `rustc_driver`.
899-
let mut llvm_linker_flags = String::new();
900-
if builder.config.llvm_profile_generate && target.contains("msvc") {
901-
if let Some(ref clang_cl_path) = builder.config.llvm_clang_cl {
902-
// Add clang's runtime library directory to the search path
903-
let clang_rt_dir = get_clang_cl_resource_dir(clang_cl_path);
904-
llvm_linker_flags.push_str(&format!("-L{}", clang_rt_dir.display()));
905-
}
906-
}
890+
/// Pass down configuration from the LLVM build into the build of
891+
/// rustc_llvm and rustc_codegen_llvm.
892+
fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelection) {
893+
let target_config = builder.config.target_config.get(&target);
907894

908-
// The config can also specify its own llvm linker flags.
909-
if let Some(ref s) = builder.config.llvm_ldflags {
910-
if !llvm_linker_flags.is_empty() {
911-
llvm_linker_flags.push_str(" ");
912-
}
913-
llvm_linker_flags.push_str(s);
895+
if builder.is_rust_llvm(target) {
896+
cargo.env("LLVM_RUSTLLVM", "1");
897+
}
898+
let llvm::LlvmResult { llvm_config, .. } = builder.ensure(llvm::Llvm { target });
899+
cargo.env("LLVM_CONFIG", &llvm_config);
900+
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
901+
cargo.env("CFG_LLVM_ROOT", s);
902+
}
903+
904+
// Some LLVM linker flags (-L and -l) may be needed to link `rustc_llvm`. Its build script
905+
// expects these to be passed via the `LLVM_LINKER_FLAGS` env variable, separated by
906+
// whitespace.
907+
//
908+
// For example:
909+
// - on windows, when `clang-cl` is used with instrumentation, we need to manually add
910+
// clang's runtime library resource directory so that the profiler runtime library can be
911+
// found. This is to avoid the linker errors about undefined references to
912+
// `__llvm_profile_instrument_memop` when linking `rustc_driver`.
913+
let mut llvm_linker_flags = String::new();
914+
if builder.config.llvm_profile_generate && target.contains("msvc") {
915+
if let Some(ref clang_cl_path) = builder.config.llvm_clang_cl {
916+
// Add clang's runtime library directory to the search path
917+
let clang_rt_dir = get_clang_cl_resource_dir(clang_cl_path);
918+
llvm_linker_flags.push_str(&format!("-L{}", clang_rt_dir.display()));
914919
}
920+
}
915921

916-
// Set the linker flags via the env var that `rustc_llvm`'s build script will read.
922+
// The config can also specify its own llvm linker flags.
923+
if let Some(ref s) = builder.config.llvm_ldflags {
917924
if !llvm_linker_flags.is_empty() {
918-
cargo.env("LLVM_LINKER_FLAGS", llvm_linker_flags);
925+
llvm_linker_flags.push_str(" ");
919926
}
927+
llvm_linker_flags.push_str(s);
928+
}
920929

921-
// Building with a static libstdc++ is only supported on linux right now,
922-
// not for MSVC or macOS
923-
if builder.config.llvm_static_stdcpp
924-
&& !target.contains("freebsd")
925-
&& !target.contains("msvc")
926-
&& !target.contains("apple")
927-
&& !target.contains("solaris")
928-
{
929-
let file = compiler_file(
930-
builder,
931-
builder.cxx(target).unwrap(),
932-
target,
933-
CLang::Cxx,
934-
"libstdc++.a",
935-
);
936-
cargo.env("LLVM_STATIC_STDCPP", file);
937-
}
938-
if builder.llvm_link_shared() {
939-
cargo.env("LLVM_LINK_SHARED", "1");
940-
}
941-
if builder.config.llvm_use_libcxx {
942-
cargo.env("LLVM_USE_LIBCXX", "1");
943-
}
944-
if builder.config.llvm_optimize && !builder.config.llvm_release_debuginfo {
945-
cargo.env("LLVM_NDEBUG", "1");
946-
}
930+
// Set the linker flags via the env var that `rustc_llvm`'s build script will read.
931+
if !llvm_linker_flags.is_empty() {
932+
cargo.env("LLVM_LINKER_FLAGS", llvm_linker_flags);
933+
}
934+
935+
// Building with a static libstdc++ is only supported on linux right now,
936+
// not for MSVC or macOS
937+
if builder.config.llvm_static_stdcpp
938+
&& !target.contains("freebsd")
939+
&& !target.contains("msvc")
940+
&& !target.contains("apple")
941+
&& !target.contains("solaris")
942+
{
943+
let file =
944+
compiler_file(builder, builder.cxx(target).unwrap(), target, CLang::Cxx, "libstdc++.a");
945+
cargo.env("LLVM_STATIC_STDCPP", file);
946+
}
947+
if builder.llvm_link_shared() {
948+
cargo.env("LLVM_LINK_SHARED", "1");
949+
}
950+
if builder.config.llvm_use_libcxx {
951+
cargo.env("LLVM_USE_LIBCXX", "1");
952+
}
953+
if builder.config.llvm_optimize && !builder.config.llvm_release_debuginfo {
954+
cargo.env("LLVM_NDEBUG", "1");
947955
}
948956
}
949957

@@ -1090,7 +1098,7 @@ impl Step for CodegenBackend {
10901098
cargo
10911099
.arg("--manifest-path")
10921100
.arg(builder.src.join(format!("compiler/rustc_codegen_{}/Cargo.toml", backend)));
1093-
rustc_cargo_env(builder, &mut cargo, target);
1101+
rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
10941102

10951103
let tmp_stamp = out_dir.join(".tmp.stamp");
10961104

src/bootstrap/doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ impl Step for Rustc {
696696
cargo.rustdocflag("-Znormalize-docs");
697697
cargo.rustdocflag("--show-type-layout");
698698
cargo.rustdocflag("--generate-link-to-definition");
699-
compile::rustc_cargo(builder, &mut cargo, target);
699+
compile::rustc_cargo(builder, &mut cargo, target, compiler.stage);
700700
cargo.arg("-Zunstable-options");
701701
cargo.arg("-Zskip-rustdoc-fingerprint");
702702

src/bootstrap/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ impl Step for Crate {
21432143
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
21442144
}
21452145
Mode::Rustc => {
2146-
compile::rustc_cargo(builder, &mut cargo, target);
2146+
compile::rustc_cargo(builder, &mut cargo, target, compiler.stage);
21472147
}
21482148
_ => panic!("can only test libraries"),
21492149
};

0 commit comments

Comments
 (0)