Skip to content

bootstrap: use target's LLVM libdir when cross-compiling - #162170

Open
heiher wants to merge 1 commit into
rust-lang:mainfrom
heiher:fix-llvm-libdir
Open

bootstrap: use target's LLVM libdir when cross-compiling#162170
heiher wants to merge 1 commit into
rust-lang:mainfrom
heiher:fix-llvm-libdir

Conversation

@heiher

@heiher heiher commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Cargo::cargo adds LLVM's library search path to rustflags for ToolRustcPrivate/Codegen so that tools linking against compiler libraries can find libLLVM. However, it always queried host_llvm_config(), which resolves to the host's llvm-config regardless of the requested target. When cross-compiling, this appends the host's LLVM libdir to the target's link flags, which can cause linking to fail.

Only use llvm-config --libdir when target is the host. Otherwise, ensure the Llvm step for target and derive the libdir from its root_dir() instead of invoking llvm-config, since the resulting binary may not be executable on the host if it was built for a different target.

@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 Sep 2, 2026
@rustbot

rustbot commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

`Cargo::cargo` adds LLVM's library search path to `rustflags` for
`ToolRustcPrivate`/`Codegen` so that tools linking against compiler
libraries can find `libLLVM`. However, it always queried
`host_llvm_config()`, which resolves to the *host*'s `llvm-config`
regardless of the requested `target`. When cross-compiling, this
appends the host's LLVM libdir to the target's link flags, which can
cause linking to fail.

Only use `llvm-config --libdir` when `target` is the host. Otherwise,
ensure the `Llvm` step for `target` and derive the libdir from its
`root_dir()` instead of invoking `llvm-config`, since the resulting
binary may not be executable on the host if it was built for a
different target.
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-llvm-21 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] rustc_lint test:false 135.877
   Compiling rustc_passes v0.0.0 (/checkout/compiler/rustc_passes)
##[error]The runner has received a shutdown signal. This can happen when the runner service is stopped, or a manually started runner is canceled.

Session terminated, killing shell...::group::Clock drift check
  local time: Wed Sep  2 06:43:22 UTC 2026
  network time: Wed, 02 Sep 2026 06:43:22 GMT
##[endgroup]
 ...killed.
##[error]The operation was canceled.

@Kobzol Kobzol 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.

.to_owned()
} else {
let llvm_output = self.ensure(Llvm { target });
llvm_output.root_dir().join("lib").to_string_lossy().into_owned()

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.

Does this work also on macOS/Windows? That being said, it is surely better than passing the host LLVM libdir :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It seems to work on macOS/Windows, but I don't have an environment to verify it. Could we test it on CI?

@rustbot rustbot assigned Kobzol and unassigned Mark-Simulacrum Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

5 participants