Skip to content

fix: preserve Windows target architecture in driver links and resources - #776

Merged
Sunrisepeak merged 4 commits into
mcpp-community:mainfrom
julixian:fix/windows-x86-target-tools
Oct 6, 2026
Merged

Sunrisepeak merged 4 commits into
mcpp-community:mainfrom
julixian:fix/windows-x86-target-tools

Conversation

@julixian

@julixian julixian commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

An x86 Windows build compiled for i686 but dropped the selected target on the clang driver link. The driver consequently selected the host architecture's CRT. Adding a project link flag worked around that failure, but llvm-windres still produced an x64 COFF resource, which could not link into the x86 image.

Preserve crossTargetFlag in both C and C++ PE driver links. Select the COFF resource target explicitly: LLVM windres receives the LLVM triple; GNU windres receives pe-i386 for x86, i386, i486, i586 and i686, or pe-x86-64 for x86_64/amd64. Share this selection between planned resources and build-program UTF-8 manifests. Native rc.exe/llvm-rc continue producing architecture-neutral .res files.

Closes #775.

Criteria

  • NinjaBackend.WindowsDriverLinksRetainTheSelectedTargetForCAndCxx checks both driver link lines for i686, x86_64 and aarch64. BuildResources.CoffTargetFollowsTheTargetInsteadOfTheHost checks LLVM triples, all five 32-bit x86 spellings, GNU BFD names and the unchanged .res path. Both passed locally in the fresh-binary unit suite. The driver-link regression runs on Windows and explicitly skips other hosts, whose links use different branches; the resource-target regression runs in all platform unit-test jobs.
  • E2E 889 builds C EXEs, C++ EXEs and explicit-export DLLs for x86 and x64, checks the PE and resource COFF machine fields, runs the EXEs, and verifies resource data after changing the .rc. It passed locally with the freshly built binary and is selected by the Windows MSVC-capable E2E jobs.
  • The same E2E failed on released 2026.10.5.2 at the first x86 C driver link (_mainCRTStartup unresolved). Re-running with only an explicit project link target reached the independent resource failure (res/app.o: machine type x64 conflicts with x86). These establish both pre-fix failures.
  • Fresh self-host build and full fresh-binary test: 146 passed, 0 failed on Windows x64, LLVM 20.1.7, MSVC 14.51 and Windows SDK 10.0.26100. Existing Windows resources E2E 197 also passed. Cross-host runtime builds and GNU windres execution are left to CI; they are not claimed as local passes.

Intersections

New rule or feature Invariant it crosses Test at the crossing
Keep the target in PE driver links C and C++ drivers must select the same target CRT; shared images must retain their target Driver-link unit test; E2E 889 C/C++ EXE and DLL matrix
Select the windres COFF target The resource object's machine must match the linked image; resource changes remain tracked COFF-target unit test; E2E 889 machine and incremental data checks
Share resource target selection Build-program manifests use the same resource compiler contract; native .res needs no COFF target COFF-target unit test native-tool cases; existing E2E 197

Compatibility

No manifest changes or migration are required. Existing x64 builds keep their output architecture; x86 driver builds and resource objects now follow the selected target. Changed Ninja commands rebuild affected resource objects and relink images. Native MSVC link.exe and .res compilation are unchanged. GNU windres retains its existing behavior outside the two mapped x86 architectures.

Checks before merging

  • bash .github/tools/check_docs_style.sh, check_docs_structure.sh and check_version_pins.sh pass. Windows Python was run with PYTHONUTF8=1 for the structure check.
  • python3 .github/tools/check_workflow_assertions.py passes (22 workflows, 0 problems). Module wiring, prepare file lengths, narrow-conversion guard and git diff --check also pass.
  • No commit on the branch carries an attribution trailer: git log origin/main..HEAD -i --grep='Co-Authored-By' prints nothing.
  • The squash merge is given an explicit subject and body, so GitHub does not compose one from the branch's commits. Suggested subject: fix: preserve Windows target architecture in driver links and resources. Suggested body: Carry the selected target through C/C++ PE driver links and windres COFF compilation. Add unit and real x86/x64 image/resource regression coverage. Closes #775.

@Sunrisepeak
Sunrisepeak merged commit a0c40ec into mcpp-community:main Oct 6, 2026
99 of 102 checks passed
Sunrisepeak added a commit that referenced this pull request Oct 6, 2026
…ing of a target row, windres recognition and the manifest resource's command (#777)

- triple::parse writes MSVC's `x86` as `i686`, as `amd64` and `arm64` are written; `[target.x86-windows-msvc]` and `--target x86-windows-msvc` are the i686 row and reach clang and llvm-windres as `i686-pc-windows-msvc` (SPEC-004 1.13 §4.6).
- Triple::is_x86_32 and Triple::msvc_arch answer the 32-bit x86 question for the NASM format, the windres COFF target, the MSVC toolset and redist directories, the ABI tool environment and PE export discovery; i386-i586 no longer select the x64 MSVC directory. The 32-bit host_arch is spelled `i686`.
- Every reader of a `[target.<triple>]` row finds it by any spelling: find_target_entry moves to mcpp.build.prepare_inputs, and the runner and min_api_level readers use it.
- RcTool::llvm is decided by find_rc_tool (the name, or the file a symlink resolves to), so llvm-mingw's `<triple>-windres` receives a triple.
- The build program's UTF-8 manifest resource keeps its command beside the object and is compiled again when it changes.
- E2E 889 builds the `x86` spelling; unit tests TargetRowSpelling, the triple vocabulary, the MSVC arch mapping, windres recognition and the manifest command.
- Docs 04/21 in both languages, SPEC-004 1.13, CHANGELOG (including #775/#776).

Design: .agents/docs/2026-10-06-windows-x86-arch-vocabulary-and-rc-follow-ups-design.md
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.

fix: preserve Windows target architecture in driver links and COFF resources

2 participants