Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify LLVM submodule handling #130918

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,8 @@ pub fn rustc_cargo_env(
// busting caches (e.g. like #71152).
if builder.config.llvm_enabled(target) {
let building_is_expensive =
crate::core::build_steps::llvm::prebuilt_llvm_config(builder, target).should_build();
crate::core::build_steps::llvm::prebuilt_llvm_config(builder, target, false)
.should_build();
// `top_stage == stage` might be false for `check --stage 1`, if we are building the stage 1 compiler
let can_skip_build = builder.kind == Kind::Check && builder.top_stage == stage;
let should_skip_build = building_is_expensive && can_skip_build;
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,7 @@ fn maybe_install_llvm(
}
!builder.config.dry_run()
} else if let llvm::LlvmBuildStatus::AlreadyBuilt(llvm::LlvmResult { llvm_config, .. }) =
llvm::prebuilt_llvm_config(builder, target)
llvm::prebuilt_llvm_config(builder, target, true)
{
let mut cmd = command(llvm_config);
cmd.arg("--libfiles");
Expand Down
21 changes: 13 additions & 8 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ impl LdFlags {
///
/// This will return the llvm-config if it can get it (but it will not build it
/// if not).
pub fn prebuilt_llvm_config(builder: &Builder<'_>, target: TargetSelection) -> LlvmBuildStatus {
// If we have llvm submodule initialized already, sync it.
builder.update_existing_submodule("src/llvm-project");
Kobzol marked this conversation as resolved.
Show resolved Hide resolved

pub fn prebuilt_llvm_config(
builder: &Builder<'_>,
target: TargetSelection,
// Certain commands (like `x test mir-opt --bless`) may call this function with different targets,
// which could bypass the CI LLVM early-return even if `builder.config.llvm_from_ci` is true.
// This flag should be `true` only if the caller needs the LLVM sources (e.g., if it will build LLVM).
handle_submodule_when_needed: bool,
) -> LlvmBuildStatus {
builder.config.maybe_download_ci_llvm();

// If we're using a custom LLVM bail out here, but we can only use a
Expand All @@ -109,9 +113,10 @@ pub fn prebuilt_llvm_config(builder: &Builder<'_>, target: TargetSelection) -> L
}
}

// Initialize the llvm submodule if not initialized already.
// If submodules are disabled, this does nothing.
builder.config.update_submodule("src/llvm-project");
if handle_submodule_when_needed {
// If submodules are disabled, this does nothing.
builder.config.update_submodule("src/llvm-project");
}

let root = "src/llvm-project/llvm";
let out_dir = builder.llvm_out(target);
Expand Down Expand Up @@ -284,7 +289,7 @@ impl Step for Llvm {
};

// If LLVM has already been built or been downloaded through download-ci-llvm, we avoid building it again.
let Meta { stamp, res, out_dir, root } = match prebuilt_llvm_config(builder, target) {
let Meta { stamp, res, out_dir, root } = match prebuilt_llvm_config(builder, target, true) {
LlvmBuildStatus::AlreadyBuilt(p) => return p,
LlvmBuildStatus::ShouldBuild(m) => m,
};
Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,9 @@ impl<'a> Builder<'a> {
// rustc_llvm. But if LLVM is stale, that'll be a tiny amount
// of work comparatively, and we'd likely need to rebuild it anyway,
// so that's okay.
if crate::core::build_steps::llvm::prebuilt_llvm_config(self, target).should_build() {
if crate::core::build_steps::llvm::prebuilt_llvm_config(self, target, false)
.should_build()
{
cargo.env("RUST_CHECK", "1");
}
}
Expand Down
Loading