feat: add Windows cross-compilation support via MinGW and LLVM#313
Merged
LunaStev merged 1 commit intoMay 8, 2026
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)x86_64-w64-mingw32-gcc/g++) and Windows-targeted LLVM tools (llvm-config.exe).packagecommand now automatically resolves and bundles essential MinGW runtime DLLs—includinglibgcc_s_seh-1.dll,libstdc++-6.dll, andlibwinpthread-1.dll—ensuring that the generated.exeruns on Windows systems without requiring a pre-installed MinGW environment.python3 x.py build x86_64-pc-windows-gnu).2. LLVM Optimization & Feature Flags
llvm-target-all,llvm-target-x86).x.pynow explicitly enables onlyllvm-target-x86. This significantly reduces compilation time and avoids linking conflicts with irrelevant LLVM targets.3. Backend & ABI Adjustments
classify_param_x86_64_windows,classify_ret_x86_64_windows). This ensures that integer extensions,SRet(Structured Return), andByValstructs strictly follow the Windows ABI, which differs from the System V ABI used on Linux/macOS.windowsto the supported OS list for the#[target(os="...")]attribute.-lc,-lm) when targeting Windows, allowing the MinGW linker to manage its own standard libraries.4. Platform Policy
README.mdto 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.