Skip to content

Assorted bootstrap LLVM refactors (part 4/N) - #161290

Open
Kobzol wants to merge 3 commits into
rust-lang:mainfrom
Kobzol:bootstrap-llvm-4
Open

Assorted bootstrap LLVM refactors (part 4/N)#161290
Kobzol wants to merge 3 commits into
rust-lang:mainfrom
Kobzol:bootstrap-llvm-4

Conversation

@Kobzol

@Kobzol Kobzol commented Aug 18, 2026

Copy link
Copy Markdown
Member

View all comments

Continuation on #161247.

This PR completely removes handling of git changes or LLVM downloads from config parsing, and moves it into the LlvmFromCi step. Thanks to that, we now also allow downloading LLVM for non-host targets.

There is one annoyance related to that, and that is that download-ci-llvm now applies to all targets for which you try to build LLVM (d'uh), but that also means that if (for whatever reason) LLVM fails to be downloaded from CI, the build will fail. So if you build for target T2 from target T1:

  • If you want to download T1, but build T2, that's not possible to express.
  • If T2 fails to be downloaded, the build fails, even if it could be built locally.

I think that we mostly have four options how to deal with this:

  1. Just ignore it and wait to see if someone complains.
  2. Revert the change and always download only for the host target. Worked so far. However, downloading LLVM for non-host targets would be quite useful for further bootstrap improvements and refactorings, because the current logic around sysroots and libdirs is.. convoluted, to say the last, and making cross-compilation easier would help with that a lot.
  3. Allow specifying download-ci-llvm per target in the target config section. So that you can say that you want to download for T1, but build for T2.
  4. Make download failures non-fatal, and cause them to trigger a local build. This would also help with removing the hacky is_ci_llvm_available_for_target logic, which hard-codes a bunch of targets to "know" which ones offer LLVM and which don't. We could just try to download, and if the result is 404, then we print a warning and continue with building (but this is slightly orthogonal, we can do this even if we don't make LLVM build failures non-fatal).

I think that 3 or 4 would be the best solution, perhaps slightly opting for 4. If we get a 404, there's no way we can download, so we build instead. If we get a different error, we still make the failed download fail the build. And only if someone has a use-case for 3, we'd add the new config.

Already before this PR, we did this:

// If download-ci-llvm=true we also want to check that CI llvm is available
b && llvm::is_ci_llvm_available_for_target(&dwn_ctx.host_target, asserts)

so if LLVM wasn't available, we just silently reverted from download-ci-llvm=true to download-ci-llvm=false. The 4. proposal would just generalize that, to actually check whether the LLVM files are present on the CDN or not.

The problem with 4. is that you can't really set any custom build options for LLVM though, because if you also enable download-ci-llvm, the config sanity check will tell you to GTFO :( So we would probably need to make some changes there.

r? jieyouxu

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Aug 18, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@Kobzol
Kobzol marked this pull request as ready for review August 24, 2026 19:23
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 24, 2026
@rustbot

rustbot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

This PR modifies src/bootstrap/src/core/config.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp.

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 24, 2026
@Kobzol

Kobzol commented Aug 24, 2026

Copy link
Copy Markdown
Member Author

Ok, should be ready for a review now.

@jieyouxu jieyouxu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one annoyance related to that, and that is that download-ci-llvm now applies to all targets for which you try to build LLVM (d'uh), but that also means that if (for whatever reason) LLVM fails to be downloaded from CI, the build will fail. So if you build for target T2 from target T1:

  • If you want to download T1, but build T2, that's not possible to express.
  • If T2 fails to be downloaded, the build fails, even if it could be built locally.

I think that we mostly have four options how to deal with this:

  1. Just ignore it and wait to see if someone complains.
  2. Revert the change and always download only for the host target. Worked so far. However, downloading LLVM for non-host targets would be quite useful for further bootstrap improvements and refactorings, because the current logic around sysroots and libdirs is.. convoluted, to say the last, and making cross-compilation easier would help with that a lot.
  3. Allow specifying download-ci-llvm per target in the target config section. So that you can say that you want to download for T1, but build for T2.
  4. Make download failures non-fatal, and cause them to trigger a local build. This would also help with removing the hacky is_ci_llvm_available_for_target logic, which hard-codes a bunch of targets to "know" which ones offer LLVM and which don't. We could just try to download, and if the result is 404, then we print a warning and continue with building (but this is slightly orthogonal, we can do this even if we don't make LLVM build failures non-fatal).

I think that 3 or 4 would be the best solution, perhaps slightly opting for 4. If we get a 404, there's no way we can download, so we build instead. If we get a different error, we still make the failed download fail the build. And only if someone has a use-case for 3, we'd add the new config.

I'm on board with option (4) but with a caveat:

  • If user did not specify their preference (so getting a cascading default to download-ci-llvm = "if-unchanged") or if they explicitly specified download-ci-llvm = "if-unchanged", then "try to download, build if missing" fallback feels reasonable.
  • If user specified download-ci-llvm = true, we should fail the build if no CI LLVM is available.

I think this matches what currently download-ci-llvm = "if-unchanged" for host targets do?

To clarify, I think what you mean here is for download-ci-llvm = "if-unchanged"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this matches what currently download-ci-llvm = "if-unchanged" for host targets do?

Actualy, it doesn't :) true and if-unchanged are not different in this behavior currently. If you use either of them, and the given target is unavailable on CI, bootstrap will just build LLVM locally. It would seem surprising to me if those two modes had a different behavior in this specific aspect.

(By the way, I'm considering merging those two modes together, same as we do for gcc. So that you only say true, and if there are local changes, you would build. But if the LLVM submodule is checked out, you wouldn't check git changes, ofc.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... I guess that sometimes I do want to download-ci-llvm to fail the build if CI LLVM cannot be used for whatever reason and never checkout the llvm submodule. (In that, for specific cases like testing in-tree tools I prefer to fail the build rather than trying to recover.)

But yeah if this matches existing behavior then we can consider revisiting this behavior later.

Comment on lines +1767 to +1768
// CI-rustc can't be used without CI-LLVM. If LLVM Ci is requested, but the
// LLVM submodule has changes, it is an error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"LLVM Ci" => "CI LLVM"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

"setting dictionary value"
);
assert!(!config.llvm_ci_mode.download_from_ci());
assert!(matches!(config.llvm_ci_mode, LlvmCiMode::BuildLocally));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert_matches!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I always forget it's already stable :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

Comment on lines 428 to +431
// Sanity check
check_llvm_version(builder, llvm_ci.output.llvm_config());
if builder.host_target == self.target {
check_llvm_version(builder, llvm_ci.output.llvm_config());
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we only check host LLVM version via host llvm-config here? Since target LLVM's llvm-config on cross-compile isn't guaranteed to be runnable on host? Maybe worth a comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can't execute the binary if it's not built for the proper target. I'll add a comment.

Comment thread src/bootstrap/src/core/builder/cargo.rs Outdated
// Set a flag for `check`/`clippy`/`fix`, so that certain build
// scripts can do less work (i.e. not building/requiring LLVM).
if matches!(cmd_kind, Kind::Check | Kind::Clippy | Kind::Fix) {
// Set a flag for `check`/`clippy`/`fix`, so that te rustc_llvm build

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"te" => "the"

Comment thread src/bootstrap/src/core/builder/cargo.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 27, 2026
@rust-bors

This comment has been minimized.

@rustbot

rustbot commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Kobzol

Kobzol commented Aug 29, 2026

Copy link
Copy Markdown
Member Author

Rebased.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 29, 2026

@jieyouxu jieyouxu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question re. external LLVM vs CI LLVM on host != target scenario

View changes since this review

Comment on lines +1748 to +1749
assert!(self.is_running_on_ci());
panic!("ERROR: LLVM submodule has changes, `download-rustc` can't be used.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are local, won't the assertion swallow the actual useful panic message here?

Comment on lines +1767 to +1768
// CI-rustc can't be used without CI-LLVM. If LLVM Ci is requested, but the
// LLVM submodule has changes, it is an error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

"setting dictionary value"
);
assert!(!config.llvm_ci_mode.download_from_ci());
assert!(matches!(config.llvm_ci_mode, LlvmCiMode::BuildLocally));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

Comment on lines +259 to +272
if builder.config.llvm_ci_mode.requests_download_from_ci()
&& let Some(config) = builder.config.target_config.get(&target)
{
if config.llvm_config.is_some() {
panic!(
"Cannot configure `llvm-config` for {target} when using `llvm.download-ci-llvm`",
);
}
if config.llvm_filecheck.is_some() {
panic!(
"Cannot configure `llvm-filecheck` for {target} when using `llvm.download-ci-llvm`"
);
}
}

@jieyouxu jieyouxu Aug 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without per-target download-ci-llvm, with this logic here, we can't mix:

  • I want to download CI LLVM for host, where it is available
  • I want to provide an external LLVM for the target, where CI LLVM is unavailable

Previously, did we just use external LLVM for the target when host != target, when CI LLVM was available for host and requested? Or did this just never work?

This logic seems a bit fishy, won't in-tree default profiles (compiler/tools/libs) also hit this with if-changed if they try to cross-compile?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants