Skip to content

Reserve an 8 MiB main-thread stack on Windows - #94

Merged
sionsmith merged 1 commit into
mainfrom
fix/windows-main-thread-stack
Sep 6, 2026
Merged

Reserve an 8 MiB main-thread stack on Windows#94
sionsmith merged 1 commit into
mainfrom
fix/windows-main-thread-stack

Conversation

@sionsmith

Copy link
Copy Markdown
Contributor

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 main is already at the edge: adding one flag to message (#90, #91) made every debug and test invocation of teams on Windows, --help included, fail with

thread 'main' has overflowed its stack

and cargo test --all-targets failed on windows-latest only (both PRs' CI runs), while #92 and #93, which do not touch message, 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.rs passes /STACK:8388608 to the MSVC linker (--stack on 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 overriding RUSTFLAGS, which a .cargo/config.toml rustflags entry would not. The reservation is address space, not committed memory.

Verification

main passes on Windows with or without this change, so the proof is #90: it is rebased onto this branch and its windows-latest job goes green with the same code that failed before.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WG7vFLjFZHqAUMRS1zkWRE

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
@sionsmith
sionsmith merged commit 11208a2 into main Sep 6, 2026
6 checks passed
@sionsmith
sionsmith deleted the fix/windows-main-thread-stack branch September 6, 2026 05:59
@sionsmith

Copy link
Copy Markdown
Contributor Author

Proof: #90 was rebased onto this branch and its windows-latest job went green (run 34015265296) with the same message changes that overflowed the stack in run 34014865730.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant