Skip to content

bootstrap: always build llvm's dylib when linking to it - #160597

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
xSetech:bootstrap/build_llvm_shared
Oct 12, 2026
Merged

rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
xSetech:bootstrap/build_llvm_shared

Conversation

@xSetech

@xSetech xSetech commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

The bootstrap example says that LLVM's dynamic library will be built when llvm.link-shared is true. It actually only set the flag that enables linking against the library (LLVM_LINK_LLVM_DYLIB). It should also set LLVM_BUILD_LLVM_DYLIB.

On clean builds, LLVM's configuration helpfully sets the BUILD flag to true if the LINK flag is true. If a dev toggles link-shared from false to true after an initial build, LINK will be "ON" (given by bootstrap) and BUILD will be "OFF" (from the cmake cache). The library to link will not be built, causing the build to fail at link time.

With this change, the library is always built when it's to be linked. Conversely, it is not built if it is not to be linked.

  • I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

@rustbot

rustbot commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

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

@rustbot rustbot added 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) labels Aug 6, 2026
@rustbot

rustbot commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

r? @clubby789

rustbot has assigned @clubby789.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: bootstrap
  • bootstrap expanded to 6 candidates
  • Random selection from Mark-Simulacrum, clubby789, jieyouxu

@xSetech

xSetech commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@nikic I moved LLVM_VERSIONED_DYLIB_NAME_ON_DARWIN=OFF out of the block so it's always off. Seems like that was your intent from #158734, but let me know if it actually depends on llvm_link_shared()

@Kobzol

Kobzol commented Aug 6, 2026

Copy link
Copy Markdown
Member

On clean builds, LLVM's configuration helpfully sets the BUILD flag to true if the LINK flag is true. If a dev toggles link-shared from false to true after an initial build, LINK will be "ON" (given by bootstrap) and BUILD will be "OFF" (from the cmake cache). The library to link will not be built, causing the build to fail at link time.

I wonder how does that show up? Because if LLVM was already built locally, and you modify the LLVM bootstrap settings, CMake won't be involved at all, because bootstrap currently caches the whole build and doesn't examine whether the settings changed or not.

@xSetech

xSetech commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

On clean builds, LLVM's configuration helpfully sets the BUILD flag to true if the LINK flag is true. If a dev toggles link-shared from false to true after an initial build, LINK will be "ON" (given by bootstrap) and BUILD will be "OFF" (from the cmake cache). The library to link will not be built, causing the build to fail at link time.

I wonder how does that show up? Because if LLVM was already built locally, and you modify the LLVM bootstrap settings, CMake won't be involved at all, because bootstrap currently caches the whole build and doesn't examine whether the settings changed or not.

That's right. LLVM configuration can be rerun by removing .llvm-stamp. See the following quote.

By default, the Rust build system does not check for changes to the LLVM source code or its build configuration settings. So, if you need to rebuild the LLVM that is linked into rustc, first delete the file .llvm-stamp, which should be located in build/host/llvm/.

@Kobzol

Kobzol commented Aug 6, 2026

Copy link
Copy Markdown
Member

Yeah, that's what I was wondering about, if you trigger this by manually removing the stamp. This seems reasonable, and could help making LLVM rebuilds more robust (which is important especially if we manage to re-land #158380).

@rust-bors

This comment has been minimized.

@clubby789

clubby789 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Sorry for missing this; if you want to rebase, I think this looks reasonable.

@rustbot author

@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 Oct 10, 2026
@rustbot

rustbot commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

The bootstrap example says that LLVM's dynamic library will be built
when llvm.link-shared is true. It actually only set the flag that enables
linking against the library (LLVM_LINK_LLVM_DYLIB). It should also set
LLVM_BUILD_LLVM_DYLIB.

On clean builds, LLVM's configuration helpfully sets the BUILD flag to
true if the LINK flag is true. If a dev toggles link-shared from false
to true after an initial build, LINK will be "ON" (given by bootstrap)
and BUILD will be "OFF" (from the cmake cache). The library to link will
not be built, causing the build to fail at link time.

With this change, the library is always built when it's to be linked.
Conversely, it is not built if it is not to be linked.
@xSetech
xSetech force-pushed the bootstrap/build_llvm_shared branch from 228d0d8 to a6bcbeb Compare October 11, 2026 01:53
@rustbot

rustbot commented Oct 11, 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.

@xSetech

xSetech commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

@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 Oct 11, 2026
@Kobzol

Kobzol commented Oct 11, 2026

Copy link
Copy Markdown
Member

Could you please also add a comment on top of the env. var. setting, which explains that we should ideally always set these variables? To avoid someone moving it back inside an if condition in the future.

@clubby789

Copy link
Copy Markdown
Contributor

Agree with adding a comment; r=me after that

@xSetech

xSetech commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

@clubby789 Comment added. BTW I'm not sure what r= means, it doesn't look like a rustbot command?

@Kobzol

Kobzol commented Oct 11, 2026

Copy link
Copy Markdown
Member

@bors r=clubby789

It's a command for another bot, bors, but you couldn't actually use it 😅

@rust-bors

rust-bors Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a8d5c6c has been approved by clubby789

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 11, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Oct 11, 2026
…d, r=clubby789

bootstrap: always build llvm's dylib when linking to it

The bootstrap example says that LLVM's dynamic library will be built when llvm.link-shared is true. It actually only set the flag that enables linking against the library (LLVM_LINK_LLVM_DYLIB). It should also set LLVM_BUILD_LLVM_DYLIB.

On clean builds, LLVM's configuration helpfully sets the BUILD flag to true if the LINK flag is true. If a dev toggles link-shared from false to true after an initial build, LINK will be "ON" (given by bootstrap) and BUILD will be "OFF" (from the cmake cache). The library to link will not be built, causing the build to fail at link time.

With this change, the library is always built when it's to be linked. Conversely, it is not built if it is not to be linked.
rust-bors Bot pushed a commit that referenced this pull request Oct 11, 2026
Rollup of 6 pull requests

Successful merges:

 - #160597 (bootstrap: always build llvm's dylib when linking to it)
 - #162810 (vectorized vec::dedup  pre-scan)
 - #162931 (directly deallocates the nodes instead of traversing every element when BTreemap dropping)
 - #162027 (std: add `fs::rename_noreplace`)
 - #164146 (Nuke `Unique` (and `ptr_internals`))
 - #164151 (std: add doctest to parent_id)
rust-bors Bot pushed a commit that referenced this pull request Oct 12, 2026
Rollup of 7 pull requests

Successful merges:

 - #159744 (Allow unary operand types to be inferred later)
 - #160597 (bootstrap: always build llvm's dylib when linking to it)
 - #162810 (vectorized vec::dedup  pre-scan)
 - #162931 (directly deallocates the nodes instead of traversing every element when BTreemap dropping)
 - #162027 (std: add `fs::rename_noreplace`)
 - #163883 (Add `oneshot` `Sender::is_closed`)
 - #164146 (Nuke `Unique` (and `ptr_internals`))
@rust-bors
rust-bors Bot merged commit 0679ba4 into rust-lang:main Oct 12, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 12, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 12, 2026
Rollup merge of #160597 - xSetech:bootstrap/build_llvm_shared, r=clubby789

bootstrap: always build llvm's dylib when linking to it

The bootstrap example says that LLVM's dynamic library will be built when llvm.link-shared is true. It actually only set the flag that enables linking against the library (LLVM_LINK_LLVM_DYLIB). It should also set LLVM_BUILD_LLVM_DYLIB.

On clean builds, LLVM's configuration helpfully sets the BUILD flag to true if the LINK flag is true. If a dev toggles link-shared from false to true after an initial build, LINK will be "ON" (given by bootstrap) and BUILD will be "OFF" (from the cmake cache). The library to link will not be built, causing the build to fail at link time.

With this change, the library is always built when it's to be linked. Conversely, it is not built if it is not to be linked.
@xSetech
xSetech deleted the bootstrap/build_llvm_shared branch October 15, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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