Skip to content

fix(build): target-aware stack flag so windows-gnu toolchain links - #2539

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

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

Conversation

@galaxy-luke

Copy link
Copy Markdown

Problem

Building rtk from source (or cargo install --git) on the x86_64-pc-windows-gnu toolchain fails during the final link:

error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
  = note: ld.exe: cannot find /STACK:8388608: No such file or directory
          collect2.exe: error: ld returned 1 exit status

This makes rtk impossible to install for anyone on the GNU toolchain (e.g. users with only MSYS2/MinGW and no MSVC Build Tools). See #1814.

Root cause

build.rs reserves a larger main-thread stack (correct — Clap + the command graph can exceed the default 1 MiB), but the flag is injected under #[cfg(windows)] only:

println!("cargo:rustc-link-arg=/STACK:8388608");

/STACK:N is MSVC linker syntax. On windows-gnu, the GNU linker (ld, driven by gcc) doesn't recognize it and treats it as a file path → link failure.

Fix

Branch on the target being built. Subtlety: #[cfg(target_env = ...)] inside build.rs reflects the host, not the target being compiled, so we read Cargo's TARGET env var instead:

  • *-pc-windows-msvc → /STACK:8388608 (unchanged)
  • *-pc-windows-gnu → -Wl,--stack,8388608 (GNU equivalent)

Verification

Built and installed on Windows 11 with stable-x86_64-pc-windows-gnu + MinGW-w64 (UCRT), where it previously failed with the exact error above. After the fix, cargo +stable-x86_64-pc-windows-gnu install --path . --locked succeeds; rtk --version / rtk gain work.

Fixes #1814

build.rs injected /STACK:8388608 guarded only by #[cfg(windows)]. This is
MSVC linker syntax; on x86_64-pc-windows-gnu the GNU linker (ld) doesn't
recognize it and fails with:
  ld.exe: cannot find /STACK:8388608: No such file or directory

Branch on CARGO's TARGET env var (build.rs cfg(target_env) reflects the
host, not the target). MSVC keeps /STACK:N; GNU uses -Wl,--stack,N.

Fixes rtk-ai#1814

Co-Authored-By: Claude <noreply@anthropic.com>
@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.


luke seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@galaxy-luke

Copy link
Copy Markdown
Author

您好!我已經完成 CLA 的簽署。再麻煩抽空協助 Review 以及核准 Workflow 執行,謝謝!

@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@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 stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error: linking with x86_64-w64-mingw32-gcc failed: exit code: 1

3 participants