Reserve an 8 MiB main-thread stack on Windows - #94
Merged
Conversation
Windows gives the main thread 1 MiB; Linux and macOS give it 8 MiB. Building clap's command tree for this many subcommands needs just under 1 MiB in an unoptimized build (measured with `ulimit -s` on 2026-09-06: main fails below 1024 KiB on macOS too), so adding a single flag to `message` (#90, #91) made every debug and test invocation on Windows, `--help` included, die with `thread 'main' has overflowed its stack`, and `cargo test --all-targets` failed on windows-latest only. A build script now passes `/STACK:8388608` to the MSVC linker (and `--stack` to the GNU one). This is the approach rustup takes for the same clap behaviour (clap-rs/clap#5134), and unlike a `.cargo/config` rustflags entry it survives CI setting `RUSTFLAGS`. The reservation is address space, not committed memory. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WG7vFLjFZHqAUMRS1zkWRE
Contributor
Author
|
Proof: #90 was rebased onto this branch and its |
This was referenced Sep 6, 2026
Merged
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.
Problem
Windows gives the main thread 1 MiB of stack; Linux and macOS give it 8 MiB. Building clap's derived command tree for this many subcommands needs just under 1 MiB in an unoptimized build, so
mainis already at the edge: adding one flag tomessage(#90, #91) made every debug and test invocation ofteamson Windows,--helpincluded, fail withand
cargo test --all-targetsfailed onwindows-latestonly (both PRs' CI runs), while #92 and #93, which do not touchmessage, passed.Measured locally with
ulimit -s:main, #90 and #91 all fail below 1024 KiB on macOS as well, in every startup phase including--help-json, which only builds the command tree.Fix
A
build.rspasses/STACK:8388608to the MSVC linker (--stackon the GNU toolchain) for Windows targets, which matches the Unix defaults. This is what rustup does for the same clap behaviour (clap-rs/clap#5134). A build script survives CI overridingRUSTFLAGS, which a.cargo/config.tomlrustflagsentry would not. The reservation is address space, not committed memory.Verification
mainpasses on Windows with or without this change, so the proof is #90: it is rebased onto this branch and itswindows-latestjob goes green with the same code that failed before.🤖 Generated with Claude Code
https://claude.ai/code/session_01WG7vFLjFZHqAUMRS1zkWRE