MSVC toolchain flags override windows_subsystem = "windows"

Open
#4,296 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
build-system

Research direction

Start with rust/private/rustc.bzl at the subsystem flag forwarding point cited in the report, then compare it with rules_cc's windows_cc_toolchain_config.bzl linker_subsystem_flag. Run repro.ps1 on Windows x64 with MSVC to reproduce the direct rustc and Bazel outputs. Done means the Rust windows_subsystem attribute determines the Bazel-built executable's PE subsystem rather than the forwarded console flag.

Written by the indexing model from the issue text.

Description

help wanted needs-triage platform: windows windows

Codex report: rust_binary builds a console executable from #![windows_subsystem = "windows"] on MSVC. Direct rustc produces a GUI executable from the same two-line source. The C++ toolchain supplies /SUBSYSTEM:CONSOLE, and rules_rust forwards it after rustc's subsystem selection.

On Windows x64 with MSVC, install Rust 1.98.0 and Bazelisk, then run:

git clone https://github.com/ashi009/rules-rust-windows-subsystem-repro
cd rules-rust-windows-subsystem-repro
./repro.ps1

Output excerpt from rules_rust 0.70.0:

$ rustc +1.98.0 -Vv
rustc 1.98.0 (88d9e12ae 2026-08-18)
...
$ bazel version
Build label: 8.7.0
...
out/direct.exe : PE subsystem 2 (2 = Windows GUI, 3 = Windows console)
...
bazel-bin/gui.exe : PE subsystem 3 (2 = Windows GUI, 3 = Windows console)

The Windows CI run reproduces this on both 0.70.0 and upstream main at 83d85cce0ab56b42a7466d8b34f4e52949d2d064.

The flag comes from rules_cc's linker_subsystem_flag and is forwarded by rules_rust. The Rust attribute should determine the resulting subsystem.

Dominant language
Starlark
Stars
857
Forks
701
Avg merge
4d 7h
Merged PRs (30d)
46

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bazelbuild/rules_rust

All issues in bazelbuild/rules_rust

Similar issues

More Build System issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.