Skip to content

Conversation

@mati865
Copy link
Member

@mati865 mati865 commented Oct 9, 2025

No description provided.

@rustbot rustbot added 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) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 9, 2025
@mati865
Copy link
Member Author

mati865 commented Oct 9, 2025

Tested locally on Windows but a shareable build would be useful.
@bors try jobs=dist-x86_64-linux,dist-x86_64-windows-gnullvm

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 9, 2025
Windows-gnullvm self-contained

try-job: dist-x86_64-linux
try-job: dist-x86_64-windows-gnullvm
@rust-log-analyzer

This comment was marked as resolved.

@rust-log-analyzer

This comment was marked as resolved.

@rust-bors

This comment was marked as resolved.

@mati865
Copy link
Member Author

mati865 commented Oct 9, 2025

@bors try jobs=dist-x86_64-linux,dist-x86_64-windows-gnullvm

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 9, 2025
Windows-gnullvm self-contained

try-job: dist-x86_64-linux
try-job: dist-x86_64-windows-gnullvm
@rust-bors
Copy link

rust-bors bot commented Oct 9, 2025

☀️ Try build successful (CI)
Build commit: 87a3415 (87a3415f29207b7d5add0b9bd83328ee459e7843, parent: 0b278a539440be291466ea463a9b6310eaf4d7bb)

@petrochenkov petrochenkov self-assigned this Oct 10, 2025
@mati865
Copy link
Member Author

mati865 commented Oct 28, 2025

Seems to work nicely, even with -Zbuild-std without having Clang in PATH.
What's left here is a cleanup and reconsideration of what would be the best way to move this forward.

@estebank
Copy link
Contributor

estebank commented Nov 4, 2025

@mati865 are there any blockers we could help you with?

@mati865
Copy link
Member Author

mati865 commented Nov 5, 2025

@estebank I had a few ideas how to refactor it, but none of them turned out satisfying. I'm going to take another stab at it this week.

@mati865 mati865 force-pushed the gnullvm-self-contained branch from f3f33b7 to 9d27d77 Compare November 10, 2025 20:02
@rust-log-analyzer

This comment has been minimized.

@mati865 mati865 force-pushed the gnullvm-self-contained branch from 9d27d77 to 9f92112 Compare November 11, 2025 12:45
@bors

This comment was marked as resolved.

@mati865 mati865 force-pushed the gnullvm-self-contained branch from 9f92112 to 48d04c8 Compare November 12, 2025 14:19
@mati865 mati865 force-pushed the gnullvm-self-contained branch from 48d04c8 to 2b5ac0b Compare November 12, 2025 14:54
@mati865
Copy link
Member Author

mati865 commented Nov 12, 2025

@bors try jobs=dist-x86_64-linux,dist-x86_64-windows-gnullvm

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Nov 12, 2025
Windows-gnullvm self-contained

try-job: dist-x86_64-linux
try-job: dist-x86_64-windows-gnullvm
@rust-bors
Copy link

rust-bors bot commented Nov 12, 2025

☀️ Try build successful (CI)
Build commit: da8dd69 (da8dd699e467041c9cfdc421e44ac8758d9288e2, parent: 2fcbda6c1a70606bdb09857e01d01fc6229da712)

Comment on lines +1422 to +1431
let self_contained_target = sess.target.os == Os::Windows
&& sess.target.env == Env::Gnu
&& sess.target.abi == Abi::Llvm
&& self_contained_components.is_linker_enabled();
if self_contained_target
&& let Some(ret) =
infer_from(sess, None, Some(LinkerFlavor::Gnu(Cc::No, Lld::Yes)), features)
{
return ret;
}
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 doesn't feel nice, but alternatives would involve modifying the target spec to somehow allow configuring two different linkers.

@mati865 mati865 marked this pull request as ready for review November 17, 2025 18:09
@rustbot
Copy link
Collaborator

rustbot commented Nov 17, 2025

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

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

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

These commits modify compiler targets.
(See the Target Tier Policy.)

@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 Nov 17, 2025
}
}

fn make_win_llvm_dist(plat_root: &Path, target: TargetSelection, builder: &Builder<'_>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: maybe put it next to fn make_win_dist? I tried to look above and below to check the difference between the two functions, but didn't find what I searched for.

"libmingw32.a",
"libmingwex.a",
"libmsvcrt.a",
// Windows import libs, remove them once std transitions to raw-dylib
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, it didn't transition yet? I clearly remember some PR doing that. Maybe not for this target specifically?

Copy link
Member Author

Choose a reason for hiding this comment

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

Std is still built without raw-dylib:

if let Mode::Rustc | Mode::ToolRustcPrivate | Mode::ToolBootstrap | Mode::ToolTarget = mode
{
rustflags.arg("--cfg=windows_raw_dylib");
}

return ret;
}

// When using a supported target in self-contained linker mode, we want to use rust-lld directly.
Copy link
Contributor

Choose a reason for hiding this comment

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

I dislike this at pretty fundamental level.

-Clink-self-contained isn't supposed to change the linker flavor, only to change where the linker (and other things) are looked up.

If windows-gnullvm targets can be built with naked linker, without clang, then perhaps they should change the default linker and linker flavor to ld.lld?
Are windows-gnullvm targets stable enough for it to be considered a breaking change?

Also, in self-contained mode we are supposed to use ld.lld from the self-contained directory, not rust-lld.
It seems like the logic below results in that, but then the comment above is misleading.

Copy link
Member Author

Choose a reason for hiding this comment

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

If windows-gnullvm targets can be built with naked linker, without clang

Basically all the targets can be linked with just a linker without CC driver given you provide required objects and libraries.
Currently, Rust ships those libraries and objects for *-pc-windows-gnu (in rust-mingw component) and some musl targets (I don't know which ones exactly; definitely x86_64 and aarch64). Which means they could just pass those shipped libs to the linker directly if they are using them anyway (so we are using -Clink-self-contained).

For example, take x86_64-pc-windows-gnu. It ships x86_64-w64-mingw32-gcc.exe and ld.exe, but it doesn't really matter whether we call x86_64-w64-mingw32-gcc -l[rust objects] -l[mingw-w64 objects and libs] -o result.exe or ld -l[rust objects] -l[mingw-w64 objects and libs] -o result.exe as long as you add the flags in the correct form, i.e. prepend them with -Wl, when using GCC as the proxy. It was just easier to ship GCC binary and reuse the code.

What I'm trying to achieve here is to pass the libraries directly to LLD in self-contained-mode for windows-gnullvm hosts, so it can run similarly to windows-gnu hosts even when there is no mingw-w64 toolchain installed. But also keep the previous behaviour, which will call x86_64-w64-mingw32-clang from PATH if it finds one.
Shipping clang is difficult because of its sheer size, so writing a wrapper that just calls LLD would be more feasible.

then perhaps they should change the default linker and linker flavor to ld.lld?

This would be a groundbreaking change. That would mean it no longer uses user's toolchain and libraries. I think this would be pretty bad.

Also, in self-contained mode we are supposed to use ld.lld from the self-contained directory, not rust-lld.

There are no self-contained binaries, only lib/rustlib/x86_64-pc-windows-gnullvm/bin/gcc-ld/ which contains various wrappers over rust-lld.


// Returns true if linker is located within sysroot
fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
// Assume `-C linker=rust-lld` as self-contained mode
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic here pre-dates windows-gnullvm targets, so apparently someone used windows-gnu targets with the naked rust-lld linker, and I see some supports for that in the target specs.
But this PR removes the self-contained mode from windows-gnu + rust-lld mode, what is the reason for that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I lost that in one of the refactors of this code.

I happen to know the person who did it: https://github.com/rust-lang/rust/pull/76167/files#diff-862130c0af71054886913befc8084094485fa7d764d95f55644e033e34acd126R1214

@petrochenkov petrochenkov 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 Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants