Skip to content

fix(build): use correct linker stack-size flag for GNU target - #3547

Closed
andreguzik wants to merge 1 commit into
rtk-ai:developfrom
andreguzik:fix/build-gnu-windows-stack-flag
Closed

andreguzik wants to merge 1 commit into
rtk-ai:developfrom
andreguzik:fix/build-gnu-windows-stack-flag

Conversation

@andreguzik

Copy link
Copy Markdown

Problem

build.rs unconditionally emits /STACK:8388608 on any Windows build:

#[cfg(windows)]
{
    println!("cargo:rustc-link-arg=/STACK:8388608");
}

/STACK: is MSVC linker syntax. On x86_64-pc-windows-gnu (MinGW), the GNU
linker doesn't understand it and the build fails:

x86_64-w64-mingw32-gcc ... -o rtk.exe ...
ld.exe: cannot find /STACK:8388608: No such file or directory
collect2.exe: error: ld returned 1 exit status

This breaks cargo build/cargo test/cargo install --path . for anyone
whose default Rust toolchain is stable-x86_64-pc-windows-gnu instead of
stable-x86_64-pc-windows-msvc (a common setup for contributors who don't
have Visual Studio Build Tools installed).

Fix

Select the flag syntax based on CARGO_CFG_TARGET_ENV (set by Cargo for
build scripts): keep /STACK:8388608 for msvc, use the GNU-ld equivalent
-Wl,--stack,8388608 otherwise. Also switched the outer guard from
#[cfg(windows)] (host-compile-time) to checking CARGO_CFG_TARGET_OS
(the actual build target), which is the more correct signal for a build
script and matches how CARGO_CFG_TARGET_ENV is already being read.

Testing

  • cargo fmt --all --check
  • cargo clippy --all-targets (no new warnings)
  • cargo test — 2575 passed, 8 ignored, 0 failed (previously: build didn't
    complete at all on this target)
  • cargo install --path . succeeds and produces a working rtk.exe on
    stable-x86_64-pc-windows-gnu

No behavior change on x86_64-pc-windows-msvc (still emits /STACK:) or
non-Windows targets (flag is skipped entirely, same as before).

Build-script-only change; not user-facing, so no docs update needed per
CONTRIBUTING.md.

build.rs unconditionally emitted /STACK:8388608, which is MSVC linker
syntax. On x86_64-pc-windows-gnu (MinGW), this breaks the build:

  ld.exe: cannot find /STACK:8388608: No such file or directory

Select the flag based on CARGO_CFG_TARGET_ENV: keep /STACK: for msvc,
use -Wl,--stack,8388608 for gnu.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@KuSh

KuSh commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

Closing in favour of #3613, which makes the same windows-gnu stack flag change in build.rs, keys it off the build target rather than the host, and has a signed CLA. Review and comments are welcome on #3613, or reply here if your version covers a case it does not.

@KuSh KuSh closed this Sep 26, 2026
@KuSh KuSh added the duplicate This issue or pull request already exists label Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants