fix(build): emit GNU-compatible stack linker arg on windows-gnu#2895
Open
silvaduartesuop wants to merge 1 commit into
Open
fix(build): emit GNU-compatible stack linker arg on windows-gnu#2895silvaduartesuop wants to merge 1 commit into
silvaduartesuop wants to merge 1 commit into
Conversation
build.rs emitted the MSVC-only `/STACK:8388608` linker argument on every
Windows target. On the x86_64-pc-windows-gnu toolchain the linker is GNU
ld (via MinGW), which does not understand `/STACK:` and fails at link
time ("cannot find /STACK:8388608"), breaking `cargo install` for MinGW
users without the MSVC linker.
Select the argument by target env: keep `/STACK:` for MSVC and emit the
equivalent `-Wl,--stack,8388608` for GNU. The 8 MiB stack reservation is
preserved on both toolchains.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
build.rsunconditionally emitted the MSVC-only/STACK:8388608linkerargument on every Windows target.
x86_64-pc-windows-gnutoolchain the linker is GNUld(viaMinGW), which does not understand
/STACK:and fails at the final linkstep — so
cargo installis broken for MinGW users who don't have theMSVC linker installed.
/STACK:8388608for MSVCand emit the equivalent
-Wl,--stack,8388608for GNU. The 8 MiB stackreservation (needed so the clap command graph doesn't overflow the
default 1 MiB stack at startup) is preserved on both toolchains.
Error before this change
Test plan
cargo install/cargo build --releaseonx86_64-pc-windows-gnunow links cleanly (previously failed as above). Built the full crate
with this exact change.
rtk.exestarts correctly —rtk --versionandrtk --helprun without the stack overflow the reservation guardsagainst, confirming the 8 MiB stack is still applied on GNU.
cargo fmt -- --check build.rsis clean./STACK:8388608) unchanged — verified by inspection; Idon't have an MSVC toolchain on hand to build that path.
Note: this is a one-line build-script fix; there's no meaningful unit test
for target-env-conditional linker-arg emission, so no test file is added.
Happy to adjust the approach if you'd prefer a different mechanism (e.g. a
.cargo/config.tomlper-targetrustflags).