Skip to content

Install LLVM DLL in the right place on Windows#152609

Open
mati865 wants to merge 2 commits intorust-lang:mainfrom
mati865:gnullvm-llvm-dll
Open

Install LLVM DLL in the right place on Windows#152609
mati865 wants to merge 2 commits intorust-lang:mainfrom
mati865:gnullvm-llvm-dll

Conversation

@mati865
Copy link
Member

@mati865 mati865 commented Feb 14, 2026

Continuation of #151795 towards #151774.

Unlike other systems, Windows requires runtime libraries to be present in PATH or right next to the binary.
So, we copy the library next to the binary as the easier solution.

Tested building rust-openssl in debug and release modes, but the difference is within noise margin.

@rustbot rustbot added A-CI Area: Our Github Actions CI 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) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Feb 14, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 14, 2026

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

/// compiler's sysroot.
///
/// For example this returns `lib` on Unix and `bin` on Windows.
pub fn sysroot_runtime_libdir_relative(&self, compiler: Compiler) -> PathBuf {
Copy link
Member

Choose a reason for hiding this comment

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

What is the difference with relative_libdir? And if there is difference when should you choose this one over relative_libdir and vice versa?

Copy link
Member Author

@mati865 mati865 Feb 14, 2026

Choose a reason for hiding this comment

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

To be honest, I have no idea what is the deal with stage == 0, but I thought leaving it there would be safer.

Also, libdir_relative doesn't "Windowsize" the path, so uncommenting install.libdir in bootstrap.toml will result in a broken Windows build because the DLLs would go to build/host/stage1/lib.
Although I don't know how much we should care about it since it doesn't work anyway. With this PR, libLLVM will correctly go to stage1/bin, but rustc_driver and std still go to stage1/lib.

Technically, all shared objects should be handled by sysroot_runtime_libdir_relative or similar function.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can change this PR to use relative_libdir for installing LLVM, if we don't care about install.libdir case and stage0 is not a problem.

Copy link
Member

Choose a reason for hiding this comment

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

install.libdir is meant for the Unix world, not for Windows. Setting install.libdir on Windows probably already results in a broken build before this PR as rustc_driver.dll ends up in the wrong dir.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair enough, removed the new helper.

Unlike other systems, Windows requires runtime libraries to be present
in `PATH` or right next to the binary.

So, we copy the library next to the binary as the easier solution.
@@ -2533,7 +2533,7 @@ fn maybe_install_llvm(
),
)]
pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
let dst_libdir = sysroot.join("lib/rustlib").join(target).join("lib");
let dst_libdir = sysroot.join("lib/rustlib").join(target).join(libdir(target));
Copy link
Member

Choose a reason for hiding this comment

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

Rustc probably expects it in lib when linking. I don't think this copy of the LLVM dylib is every used at runtime.

Copy link
Member Author

Choose a reason for hiding this comment

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

That wouldn't work well on Windows. With both GNU toolchains you can link to DLL directly, but it's a hit-or-miss situation. Linking via import library is the right way to do it.
With MSVC's link.exe and lld-link the situation is clearer - you cannot link DLL directly at all, the import library is the only way.

Maybe we don't need it at all and should bundle the import library instead on Windows?

Copy link
Member

Choose a reason for hiding this comment

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

This function should be installing both the DLL and the import library into the rustc linker path. Putting just the import library in rustlib and having a single copy of LLVM.dll in $(rustc --print sysroot)/bin would make sense to me. Doesn't have to be in the same PR IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently it only installs the DLL. I'll revert this change when I'm back home.

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

Labels

A-CI Area: Our Github Actions CI 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) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants