Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixed

- Windows builds reserve an 8 MiB main-thread stack, matching Linux and macOS. Windows gives the main thread 1 MiB by default, and building clap's command tree for this many subcommands needs almost all of it in an unoptimized build, so any addition to the `message` command made every debug and test invocation of `teams` on Windows — `--help` included — fail with `thread 'main' has overflowed its stack`, and `cargo test` failed on `windows-latest` while passing on Linux and macOS. A build script now passes `/STACK:8388608` to the MSVC linker (`--stack` on the GNU toolchain). The reservation is address space rather than committed memory, so an idle process costs nothing extra.

## v0.6.0 - 2026-08-30

### Added
Expand Down
29 changes: 29 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Windows reserves 1 MiB of stack for the main thread; Linux and macOS give
//! it 8 MiB. Building clap's command tree for this many subcommands uses
//! almost all of that 1 MiB in an unoptimized build (measured at just under
//! it on 2026-09-06), so on Windows every debug or test invocation of `teams`
//! — `--help` included — overflowed the stack as soon as one more flag was
//! added to `message`, and `cargo test` failed there while passing elsewhere.
//!
//! Reserving the same 8 MiB the Unix targets get removes the cliff. It is
//! address space, not committed memory, so an idle process costs nothing
//! extra. rustup does the same for the same reason (clap's debug-mode stack
//! use, clap-rs/clap#5134). A build script survives CI overriding `RUSTFLAGS`, which a
//! `.cargo/config.toml` `rustflags` entry would not.

use std::env;

const MAIN_THREAD_STACK_BYTES: u32 = 8 * 1024 * 1024;

fn main() {
println!("cargo:rerun-if-changed=build.rs");

if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
return;
}
match env::var("CARGO_CFG_TARGET_ENV").as_deref() {
Ok("msvc") => println!("cargo:rustc-link-arg=/STACK:{MAIN_THREAD_STACK_BYTES}"),
Ok("gnu") => println!("cargo:rustc-link-arg=-Wl,--stack,{MAIN_THREAD_STACK_BYTES}"),
_ => {}
}
}