Skip to content

Cross-compilation: Windows x86_64 target (COFF link, :cross-rt-windows) - #708

Merged
ropoctl merged 2 commits into
withlang-dev:mainfrom
ropoctl:cross-windows-x86_64
Jul 24, 2026
Merged

ropoctl merged 2 commits into
withlang-dev:mainfrom
ropoctl:cross-windows-x86_64

Conversation

@ropoctl

@ropoctl ropoctl commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Windows x86_64 cross-compilation (Linux → Windows, verified under wine)

Adds an x86_64-pc-windows-msvc cross target (kind 5) so with can cross-compile Windows PE executables from a Linux host. Builds on the linux_x86_64 cross pipeline.

Verified working

A hello-world and a non-trivial program using std.process.args() cross-compile on Linux and run correctly under wine (exit 0; argv, stdlib, print all fine):

with build --target x86_64-pc-windows-msvc hello.w -o hello.exe   # PE32+ console exe
wine hello.exe                                                     # -> prints correctly

Linking is native on Linux (the LLVM SDK's lld-link in COFF mode) against an xwin-splatted MSVC CRT + Windows SDK import libs; wine is only used to run the produced exe.

Changes (Windows cross enablement)

  • TargetSpec — target_spec_cross_supported accepts kind 5.
  • Link.w — route kind 5 to the Windows link recipe via the COFF lld-link driver (link_stage_coff_lld_for); kind 5 → rt_windows_x86_64.o; link_stage_make_archive returns raw objects for a Windows target (lld-link won't pull members from GNU .a archives on a cross link); MSVC/UCRT/UM libpaths overridable via WITH_WINDOWS_{MSVC,UCRT,UM}_LIBDIR (C:/… fallbacks kept for on-Windows).
  • BuildGraphOps — embed generator emits COFF .section .rdata for a windows entry.
  • build.w — :cross-rt-windows builds the full Windows runtime + LLVM/clang bridges + a COFF-form llvm_ld.rsp, mirroring :cross-rt. Also fixes the platform runtime object name (rt_<platform>.o) in both cross-rt sets.

Incidental fix (separate commit)

  • The default build stamp action never created its declared out/command/build marker, so the action verifier failed every default with build and no state was blessed.

Known follow-up

The compiler itself cross-links to a with-windows-x86_64.exe that loads under wine but exits immediately (~0.5s) without doing work — a full stage1–3 self-bootstrap under wine is not yet green. Ordinary With programs run fine under wine; the only difference for the compiler is the statically-linked LLVM/libclang, so this points at LLVM/clang static-init under wine, not the cross plumbing. Under investigation.

ropoctl added 2 commits July 24, 2026 08:19
The post-link version-stamp action (run_patch_version_action) produced the
release binary but never created its declared out/command/build extra-output
marker, so the action verifier failed every default `with build` and no
build state was blessed (forcing full rebuilds). Create the capture dir the
same way the sibling run_with_compiler_build_action does.
…t-windows)

Extend the Linux-only cross pipeline to Windows x86_64 (kind 5):

- TargetSpec: target_spec_cross_supported accepts kind 5.
- Link.w: route kind 5 to the existing Windows link recipe using the SDK's
  lld-link COFF driver (link_stage_coff_lld_for) — links natively on any host,
  no wine needed for the link; kind 5 -> rt_windows_x86_64.o platform object;
  make link_stage_make_archive return raw objects for a Windows target (lld-link
  does not pull members from GNU .a archives on a cross link); make the recipe's
  MSVC/UCRT/UM libpaths overridable via WITH_WINDOWS_*_LIBDIR so a cross host can
  point at an xwin-splatted lib tree (C:/... fallbacks kept for on-Windows).
- BuildGraphOps: embed generator emits COFF .section .rdata for a windows entry.
- build.w: :cross-rt-windows builds the full windows_x86_64 runtime + bridges +
  COFF-form llvm_ld.rsp into out/lib/cross/windows_x86_64/, mirroring :cross-rt.
  The llvm_ld.rsp excludes LLVM-C.lib (the import stub for the dynamic LLVM-C.dll)
  so the statically-linked compiler does not acquire a runtime dependency on a
  DLL that does not exist — matching the native metadata action. Also fix the
  platform runtime object name (rt_<platform>.o) for both cross-rt sets.

Verified under wine (Linux host): hello-world and args/stdlib programs run; and
the cross-compiled compiler itself runs (version) and compiles (emit-obj -> COFF)
under wine.
@ropoctl
ropoctl force-pushed the cross-windows-x86_64 branch from 38be8f7 to feb6ca2 Compare July 24, 2026 06:24
@ropoctl

ropoctl commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto current main (conflicts with the kind-2 linux-aarch64 refactor resolved; now MERGEABLE).

Update — the compiler now runs AND compiles under wine. Root cause of the earlier bootstrap failure was a bug in this PR's own cross-rt-windows link metadata: it included LLVM-C.lib (the import stub for the dynamic LLVM-C.dll), so the statically-linked compiler acquired a runtime dependency on a DLL that doesn't exist → the loader failed with STATUS_DLL_NOT_FOUND (0xC0000135, which wine's wrapper surfaces as exit 53) before main. The fix excludes LLVM-C.lib, matching the native metadata action. Verified on a Linux host under wine 11.0:

  • wine with-windows-x86_64.exe version → prints, exit 0
  • wine with-windows-x86_64.exe build --emit-obj hw.w -o hw.o → produces a valid COFF object, exit 0

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.

1 participant