Skip to content

fix(build): use the GNU linker's stack flag on *-pc-windows-gnu - #3239

Open
kamusmg wants to merge 1 commit into
rtk-ai:developfrom
kamusmg:fix/windows-gnu-stack-link-arg
Open

fix(build): use the GNU linker's stack flag on *-pc-windows-gnu#3239
kamusmg wants to merge 1 commit into
rtk-ai:developfrom
kamusmg:fix/windows-gnu-stack-link-arg

Conversation

@kamusmg

@kamusmg kamusmg commented Jul 27, 2026

Copy link
Copy Markdown

Summary

  • rtk does not build at all on x86_64-pc-windows-gnu:

    error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
      = note: ld.exe: cannot find /STACK:8388608: No such file or directory
    
  • build.rs emits cargo:rustc-link-arg=/STACK:8388608, which is MSVC link.exe syntax. GNU ld reads /STACK:8388608 as a file path and aborts. CI only covers windows-latest (msvc), so the gnu target has been silently unbuildable.

  • Emit -Wl,--stack,8388608 there instead, keeping /STACK: for msvc so the original intent (a larger main-thread stack for clap's command graph) is preserved on both.

  • Also switches the gate from #[cfg(windows)] to CARGO_CFG_TARGET_OS/CARGO_CFG_TARGET_ENV. Inside a build script #[cfg(windows)] describes the host compiling build.rs, not the target, so today it fires when cross-compiling away from Windows and misses cross-compiling toward it.

Test plan

  • cargo fmt --all -- --check — clean
  • cargo clippy --all-targets — clean
  • cargo test --all on x86_64-pc-windows-gnu2511 passed, 0 failed (this target could not produce a binary before this change)
  • Manual: rtk --version, rtk grep, rtk find, rtk git status all start and run — the larger stack is still applied, just spelled for the right linker

`/STACK:8388608` is MSVC link.exe syntax. GNU ld reads it as a file path and
aborts with `cannot find /STACK:8388608`, so the crate does not link at all on
x86_64-pc-windows-gnu. CI only covers windows-latest (msvc), so the target has
been silently unbuildable.

Emit `-Wl,--stack,8388608` there instead, and gate on the target rather than the
host: inside a build script `#[cfg(windows)]` describes the machine compiling
build.rs, so it also fires when cross-compiling away from Windows and misses
cross-compiling toward it. CARGO_CFG_TARGET_OS/ENV is the target-accurate source.
@CLAassistant

CLAassistant commented Jul 27, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@bharvey42

Copy link
Copy Markdown

Confirming this from the user side, and it's worse than a nicety: current develop (aa40853) does not link at all on x86_64-pc-windows-gnu. build.rs emits the MSVC-only /STACK:8388608 under #[cfg(windows)]; GNU ld reads it as a file path and aborts. CI only covers windows-latest (msvc), so the target has been silently unbuildable on mainline.

This patch fixes it. I've been carrying it in a local fork build since 2026-08-08 and building rtk on that target daily since, with no issues. It still merges cleanly with develop as of today.

Worth noting for triage priority: this also blocks validating any other Windows PR from a gnu toolchain, since you can't build the baseline to compare against. I hit exactly that today and had to apply this patch locally just to run cargo test on develop.

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.

3 participants