Skip to content

[Proof of concept] Build shared LLVM lib for gnullvm#151795

Closed
mati865 wants to merge 2 commits intorust-lang:mainfrom
mati865:push-okvosrxznyrr
Closed

[Proof of concept] Build shared LLVM lib for gnullvm#151795
mati865 wants to merge 2 commits intorust-lang:mainfrom
mati865:push-okvosrxznyrr

Conversation

@mati865
Copy link
Member

@mati865 mati865 commented Jan 28, 2026

No description provided.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Jan 28, 2026
@mati865

This comment was marked as outdated.

@rust-bors

This comment was marked as resolved.

@mati865

This comment was marked as outdated.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Jan 28, 2026
Build shared LLVM lib for gnullvm


try-job: dist-x86_64-llvm-mingw
try-job: dist-aarch64-llvm-mingw
@rust-log-analyzer

This comment was marked as outdated.

@rust-bors

This comment was marked as outdated.

@mati865

This comment was marked as outdated.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Jan 28, 2026
Build shared LLVM lib for gnullvm


try-job: dist-x86_64-llvm-mingw
@rust-bors

This comment was marked as outdated.

@rust-log-analyzer

This comment was marked as outdated.

@mati865

This comment was marked as outdated.

@mati865
Copy link
Member Author

mati865 commented Jan 29, 2026

So much fun. This is not related to llvm.static-libstdcpp = true, bootstrap logic is really convoluted here.

When doing ./x dist and build/host/llvm/.llvm-stamp doesn't exist the build fails because LLVM DLL is missing from bin:

$ fd 'libLLVM-22-rust-dev.dll$' build/host/
build/host/stage1/lib/libLLVM-22-rust-dev.dll
build/host/llvm/bin/libLLVM-22-rust-dev.dll
build/host/llvm/build/bin/libLLVM-22-rust-dev.dll
build/host/stage1/lib/rustlib/x86_64-pc-windows-gnullvm/lib/libLLVM-22-rust-dev.dll

Running ./x dist again without changing anything (LLVM stamp is present):

$ fd 'libLLVM-22-rust-dev.dll$' build/host/
build/host/stage1/bin/libLLVM-22-rust-dev.dll
build/host/stage1/lib/libLLVM-22-rust-dev.dll
build/host/llvm/bin/libLLVM-22-rust-dev.dll
build/host/stage0-sysroot/lib/rustlib/x86_64-pc-windows-gnullvm/lib/libLLVM-22-rust-dev.dll
build/host/stage1/lib/rustlib/x86_64-pc-windows-gnullvm/lib/libLLVM-22-rust-dev.dll
build/host/llvm/build/bin/libLLVM-22-rust-dev.dll

./x build doesn't exhibit the same issue because it always copies that DLL everywhere, regardless of build/host/llvm/.llvm-stamp presence.

With my libdir change, first ./x dist (missing LLVM stamp) succeeds and results in:

$ fd 'libLLVM-22-rust-dev.dll$' build/host/
build/host/llvm/bin/libLLVM-22-rust-dev.dll
build/host/llvm/build/bin/libLLVM-22-rust-dev.dll
build/host/stage1/bin/libLLVM-22-rust-dev.dll
build/host/stage1/lib/rustlib/x86_64-pc-windows-gnullvm/bin/libLLVM-22-rust-dev.dll

Second ./x dist (LLVM stamp present) run:

$ fd 'libLLVM-22-rust-dev.dll$' build/host/
build/host/stage0-sysroot/lib/rustlib/x86_64-pc-windows-gnullvm/bin/libLLVM-22-rust-dev.dll
build/host/stage1/bin/libLLVM-22-rust-dev.dll
build/host/llvm/bin/libLLVM-22-rust-dev.dll
build/host/llvm/build/bin/libLLVM-22-rust-dev.dll
build/host/stage1/lib/rustlib/x86_64-pc-windows-gnullvm/bin/libLLVM-22-rust-dev.dll

./x build (regardless of stamp):

$ fd 'libLLVM-22-rust-dev.dll$' build/host/
build/host/stage1/bin/libLLVM-22-rust-dev.dll
build/host/stage1/lib/rustlib/x86_64-pc-windows-gnullvm/bin/libLLVM-22-rust-dev.dll
build/host/stage0-sysroot/lib/rustlib/x86_64-pc-windows-gnullvm/bin/libLLVM-22-rust-dev.dll
build/host/llvm/build/bin/libLLVM-22-rust-dev.dll
build/host/llvm/bin/libLLVM-22-rust-dev.dll

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Jan 29, 2026
@mati865
Copy link
Member Author

mati865 commented Jan 29, 2026

@bors try jobs=dist-x86_64-llvm-mingw,dist-aarch64-llvm-mingw

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Jan 29, 2026
Build shared LLVM lib for gnullvm


try-job: dist-x86_64-llvm-mingw
try-job: dist-aarch64-llvm-mingw
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 29, 2026

☀️ Try build successful (CI)
Build commit: f27b4c2 (f27b4c2d245b933b6015413152ab92379d3c4bc4, parent: ba284f468cd2cda48420251efc991758ec13d450)

@mati865
Copy link
Member Author

mati865 commented Jan 29, 2026

cc @ZuseZ4, this draft is a proof of concept shared LLVM library regarding #151774

$ cargo +f27b4c2d245b933b6015413152ab92379d3c4bc4 r
   Compiling hello v0.1.0 (C:\Users\Mateusz\AppData\Local\Temp\hello)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.57s
     Running `target\debug\hello.exe`
Hello, world!

$ ntldd ~/.rustup/toolchains/f27b4c2d245b933b6015413152ab92379d3c4bc4/bin/rustc_driver-16129f0090ce922d.dll
C:/Users/Mateusz/.rustup/toolchains/f27b4c2d245b933b6015413152ab92379d3c4bc4/bin/rustc_driver-16129f0090ce922d.dll:
        kernel32.dll => C:\WINDOWS\SYSTEM32\kernel32.dll (0x0000011cb9980000)
        libunwind.dll => C:\Users\Mateusz\.rustup\toolchains\f27b4c2d245b933b6015413152ab92379d3c4bc4\bin\libunwind.dll (0x0000011cafed0000)
        libLLVM-22-rust-1.95.0-nightly.dll => C:\Users\Mateusz\.rustup\toolchains\f27b4c2d245b933b6015413152ab92379d3c4bc4\bin\libLLVM-22-rust-1.95.0-nightly.dll (0x0000011cbc920000)
        bcryptprimitives.dll => C:\WINDOWS\SYSTEM32\bcryptPrimitives.dll (0x0000011cba000000)
        bcrypt.dll => C:\WINDOWS\SYSTEM32\bcrypt.dll (0x0000011cba3e0000)
        ADVAPI32.dll => C:\WINDOWS\SYSTEM32\ADVAPI32.dll (0x0000011cbc060000)
        oleaut32.dll => C:\WINDOWS\SYSTEM32\OLEAUT32.dll (0x0000011cba580000)
        ole32.dll => C:\WINDOWS\SYSTEM32\ole32.dll (0x0000011cbbec0000)
        ntdll.dll => C:\WINDOWS\SYSTEM32\ntdll.dll (0x0000011cb9a50000)
        WS2_32.dll => C:\WINDOWS\SYSTEM32\WS2_32.dll (0x0000011cafed0000)
        USERENV.dll => C:\WINDOWS\SYSTEM32\USERENV.dll (0x0000011caff10000)

pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
// FIXME: add helper?
let dst_libdir = sysroot.join(builder.sysroot_libdir_relative(Compiler::new(1, target)));
let dst_runtime_libdir = dst_libdir.parent().unwrap().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.

Isn't this wrong when the libdir has been configured to be say lib64 on a linux system? The libdir helper doesn't take that into account, while sysroot_libdir_relative does. Maybe use builder.libdir_relative() instead? sysroot_libdir_relative is meant for where the standard library is stored while libdir_relative is for where the dylibs rustc itself links against are stored.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not a final solution, just a proof of concept that this can work on Windows.

@mati865 mati865 changed the title Build shared LLVM lib for gnullvm [Proof of concept] Build shared LLVM lib for gnullvm Feb 4, 2026
@ZuseZ4
Copy link
Member

ZuseZ4 commented Feb 4, 2026

@mati865 I'd prefer to land this first without the Enzyme changes, so I can later have one or in which I enable it for all 3 OS, and potentially just have to revert that one if it ends up breaking something. I would give the Zulip discussion a day or two, but I don't think people will have strong opinions on this choice.

@ZuseZ4 ZuseZ4 self-assigned this Feb 5, 2026
@mati865
Copy link
Member Author

mati865 commented Feb 6, 2026

@ZuseZ4 sure, I'll look soon. Once my flu is gone and my brain can comprehend more than just a single expression at a time.

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.
@mati865
Copy link
Member Author

mati865 commented Feb 13, 2026

@bors try jobs=dist-x86_64-llvm-mingw,dist-aarch64-llvm-mingw

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Feb 13, 2026
[Proof of concept] Build shared LLVM lib for gnullvm


try-job: dist-x86_64-llvm-mingw
try-job: dist-aarch64-llvm-mingw
@mati865
Copy link
Member Author

mati865 commented Feb 13, 2026

@bors cancel

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 13, 2026

❗ There is currently no auto build in progress on this PR.

Hint: There is a pending try build on this PR. Maybe you meant to cancel it? You can do that using @bors try cancel.

@mati865
Copy link
Member Author

mati865 commented Feb 13, 2026

@bors try cancel

@bors try jobs=dist-x86_64-llvm-mingw,dist-aarch64-llvm-mingw

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 13, 2026

Try build cancelled. Cancelled workflows:

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Feb 13, 2026
[Proof of concept] Build shared LLVM lib for gnullvm


try-job: dist-x86_64-llvm-mingw
try-job: dist-aarch64-llvm-mingw
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 13, 2026

💔 Test for 2c8caf7 failed: CI. Failed job:

@mati865
Copy link
Member Author

mati865 commented Feb 13, 2026

@bors try jobs=dist-x86_64-llvm-mingw

AArch64 runner is flaky, but we don't need it either way.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Feb 13, 2026
[Proof of concept] Build shared LLVM lib for gnullvm


try-job: dist-x86_64-llvm-mingw
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 13, 2026

☀️ Try build successful (CI)
Build commit: e3e67f6 (e3e67f6a9969c8b96992df779eb1f0a5e4a9cfd9, parent: d7daac06d87e1252d10eaa44960164faac46beff)

@mati865
Copy link
Member Author

mati865 commented Feb 14, 2026

On disk sizes of the installed toolchains:

$ rustup-toolchain-install-master e3e67f6a9969c8b96992df779eb1f0a5e4a9cfd9 -c cargo
509M

$ rustup-toolchain-install-master d7daac06d87e1252d10eaa44960164faac46beff -c cargo
627M

$ rustup-toolchain-install-master e3e67f6a9969c8b96992df779eb1f0a5e4a9cfd9 -c cargo -c llvm-tools -f
671M

$ rustup-toolchain-install-master d7daac06d87e1252d10eaa44960164faac46beff -c cargo -c llvm-tools -f
1.1G

This is despite shipping two identical LLVM DLLs, so quite impressive.

Given the lack of replies in #t-compiler > Changing static linking of rustc to LLVM to dynamic
#t-compiler > Changing static linking of rustc to LLVM to dynamic, I have created a new PR: #152609

@mati865 mati865 closed this Feb 14, 2026
@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 Feb 14, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 15, 2026
Install LLVM DLL in the right place on Windows

Continuation of rust-lang#151795 towards rust-lang#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.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 16, 2026
Install LLVM DLL in the right place on Windows

Continuation of rust-lang#151795 towards rust-lang#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.
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 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.

5 participants