windows: Use a default stack size of 8MB (#8711)

This matches Linux and avoids annoying stack overflows, especially when running our own demos (see printerdemo).

This is now also documented for our users.

Fixes #4586
This commit is contained in:
Simon Hausmann 2025-06-16 15:27:34 +02:00 committed by GitHub
parent 52c978238e
commit 2ea583d9d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 0 deletions

View file

@ -19,3 +19,12 @@ rustflags = [
"-C",
"target-feature=+s32c1i",
]
[target.x86_64-pc-windows-msvc]
# Increase default stack size to avoid running out of stack
# space in debug builds. The size matches Linux's default.
rustflags = ["-C", "link-arg=/STACK:8000000"]
[target.aarch64-pc-windows-msvc]
# Increase default stack size to avoid running out of stack
# space in debug builds. The size matches Linux's default.
rustflags = ["-C", "link-arg=/STACK:8000000"]

View file

@ -63,6 +63,27 @@ your Python script.
</TabItem>
</Tabs>
### Rust: Stack Overflows
When developing Rust applications on Windows, you might sooner or later observe the program aborting with `STATUS_STACK_OVERFLOW`,
especially in debug builds. This is a known issue that's a combination of a high demand for stack space and MSVC defaulting to
a stack size for the main thread that's significantly smaller compared to other operating systems.
This is fixed by configuring the linker. Create a [`.cargo\config.toml`](https://doc.rust-lang.org/cargo/reference/config.html#configuration)
file in your project (note the `.cargo` sub-directory) with the following contents:
```toml
[target.x86_64-pc-windows-msvc]
# Increase default stack size to avoid running out of stack
# space in debug builds. The size matches Linux's default.
rustflags = ["-C", "link-arg=/STACK:8000000"]
[target.aarch64-pc-windows-msvc]
# Increase default stack size to avoid running out of stack
# space in debug builds. The size matches Linux's default.
rustflags = ["-C", "link-arg=/STACK:8000000"]
```
</TabItem>
<TabItem label="macOS" icon="apple">