Skip to content

feat: add Windows cross-compilation support via MinGW and LLVM#313

Merged
LunaStev merged 1 commit into
wavefnd:masterfrom
LunaStev:feat/add-official-Windows-cross-compilation-support-via-MinGW-and-LLVM
May 8, 2026
Merged

feat: add Windows cross-compilation support via MinGW and LLVM#313
LunaStev merged 1 commit into
wavefnd:masterfrom
LunaStev:feat/add-official-Windows-cross-compilation-support-via-MinGW-and-LLVM

Conversation

@LunaStev
Copy link
Copy Markdown
Member

@LunaStev LunaStev commented May 8, 2026

This PR introduces robust cross-compilation support for Windows (x86_64-pc-windows-gnu) from Linux hosts. By integrating the MinGW toolchain, Wine (for build-time introspection), and platform-specific ABI lowering, Wave can now generate standalone Windows executables with correctly bundled runtime dependencies.

Key Changes

1. Build Orchestration (x.py)

  • Environment Configuration: Added support for MinGW compilers (x86_64-w64-mingw32-gcc/g++) and Windows-targeted LLVM tools (llvm-config.exe).
  • Standalone Packaging: The package command now automatically resolves and bundles essential MinGW runtime DLLs—including libgcc_s_seh-1.dll, libstdc++-6.dll, and libwinpthread-1.dll—ensuring that the generated .exe runs on Windows systems without requiring a pre-installed MinGW environment.
  • Target Selection: Enabled the ability to pass explicit triples to the build script (e.g., python3 x.py build x86_64-pc-windows-gnu).

2. LLVM Optimization & Feature Flags

  • Modular Target Initialization: Abstracted LLVM target initialization behind Cargo features (llvm-target-all, llvm-target-x86).
  • Reduced Build Times: When cross-compiling for Windows, x.py now explicitly enables only llvm-target-x86. This significantly reduces compilation time and avoids linking conflicts with irrelevant LLVM targets.

3. Backend & ABI Adjustments

  • Windows x64 Calling Convention: Implemented specific ABI lowering rules for Windows x64 (classify_param_x86_64_windows, classify_ret_x86_64_windows). This ensures that integer extensions, SRet (Structured Return), and ByVal structs strictly follow the Windows ABI, which differs from the System V ABI used on Linux/macOS.
  • Conditional Compilation: Added windows to the supported OS list for the #[target(os="...")] attribute.
  • Linker Refinement: Updated the LLVM backend to prevent the automatic injection of Linux-specific libraries (-lc, -lm) when targeting Windows, allowing the MinGW linker to manage its own standard libraries.

4. Platform Policy

  • Tier Promotion: Updated README.md to promote Windows (MinGW/GNU) from Tier 4 (Unofficial) to Tier 3 (Experimental), reflecting the increased stability and official support in the build pipeline.

Rationale

Enabling Windows support from a Linux host allows for a more streamlined CI/CD process and empowers developers to target the most popular desktop OS without leaving their primary development environment. The implementation of the Windows-specific ABI is critical for reliable FFI with native Windows DLLs and the Win32 API.

This commit introduces robust cross-compilation support for Windows (`x86_64-pc-windows-gnu`) from a Linux host. It resolves build and runtime dependencies for the Wave compiler on Windows by integrating MinGW, Wine, and native Windows LLVM binaries into the build and packaging pipeline.

[Details]
1. Build System (`x.py`) Updates:
  - Added full environment configuration for MinGW (`x86_64-w64-mingw32-gcc`/`g++`) and Windows LLVM (`llvm-config.exe`).
  - Added automatic resolution and bundling of required MinGW runtime DLLs (`libgcc_s_seh-1.dll`, `libstdc++-6.dll`, `libwinpthread-1.dll`) during the `package` step to ensure the generated `.exe` is standalone.
  - Allowed passing specific target triples to `x.py` (e.g., `x.py build x86_64-pc-windows-gnu`).

2. LLVM and Feature Flags (`Cargo.toml` & `llvm/Cargo.toml`):
  - Abstracted target initialization via Cargo features (`llvm-target-all`, `llvm-target-x86`).
  - When building for Windows via MinGW, `x.py` now disables default features and explicitly enables only `llvm-target-x86` to significantly reduce compilation time and avoid linking issues with irrelevant LLVM targets.

3. Import & Backend Adjustments:
  - Added Windows to the supported targets in the `TargetAttr` parser (`#[target(os="windows")]`).
  - Adjusted the LLVM backend (`backend.rs`) to prevent injecting default Linux libc/libm (`-lc`, `-lm`) when the target is `x86_64-*-windows-gnu`.
  - Added custom ABI lowering classification (`classify_param_x86_64_windows`, `classify_ret_x86_64_windows`) to correctly handle C-ABI integer extensions and SRet/ByVal structs for the Windows x64 calling convention.

4. Documentation:
  - Promoted Windows (MinGW/GNU) from Tier 4 (Unofficial) to Tier 3 (Experimental) in `README.md`.

Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev merged commit f76d139 into wavefnd:master May 8, 2026
2 checks passed
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