feat: implement standalone toolchain packaging for Windows and Linux#315
Merged
LunaStev merged 1 commit intoMay 18, 2026
Conversation
This commit massively improves the cross-platform capabilities of the `wavec` compiler release process. It enhances the packaging script (`x.py package`) and LLVM backend integration to fully bundle the MinGW Windows runtime and Linux C runtime objects into standalone distributions, eliminating the need for a host compiler or sysroot during user development. [Details] 1. Windows GNU Cross-Compilation & Packaging (`x.py` & `cli.rs`): - Instead of passing linking off to `gcc`, `wavec` now bundles and invokes `ld.lld` directly for Windows GNU targets. - Automatically discovers and bundles MinGW's self-contained C runtime and import libraries (`crt2.o`, `libmingw32.a`, `libkernel32.a`, `libmsvcrt.a`, etc.) via Rust's toolchain (`WAVE_WINDOWS_RUST_TOOLCHAIN`) or user-provided `WAVE_WINDOWS_MINGW_LIB`. - Added PE/DLL dependency resolution in `x.py` (`pe_imported_dlls`) using `objdump` to recursively find and bundle all necessary Windows runtime DLLs (excluding system DLLs) alongside the `wavec.exe` and LLVM binaries. 2. Linux CRT & Sysroot Bundling: - The `x.py` script now compiles `crt1.s` using the bundled `llvm-mc` to produce and package architecture-specific `crt1.o` for Linux targets. - The LLVM backend automatically locates these bundled start/end/libc runtime files alongside the compiler executable if standard system paths fail, allowing `wavec` to produce Linux binaries completely standalone. 3. LLVM Backend & Command Argument Polish: - Fixed issues where global compiler arguments (`opt_flag`, `code_model`, `relocation_model`, etc.) were not consistently passed to `llc` or `ld.lld`. - Corrected `-rpath` patching for Linux binaries. Transferred from `DT_RUNPATH` to legacy `DT_RPATH` (`--disable-new-dtags`) or enforced with `patchelf --force-rpath` to ensure transitive dependencies like `libffi` are correctly resolved via the bundled `libLLVM.so` in clean container environments. 4. Robust Toolchain Validation: - `x.py package` now uses `file` output (`is_binary_for_target`) to verify every copied binary, shared object, or DLL exactly matches the intended architecture (`PE32+ x86-64`, `ELF aarch64`, etc.). The build strictly aborts if an architecture mismatch is detected in the bundled toolchain. 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 significantly enhances the Wave compiler's distribution model by enabling the creation of fully standalone toolchains for Windows and Linux. The goal is to eliminate the requirement for a host-side C compiler (like
gccormsvc) or a pre-configured sysroot. With these changes,wavecnow bundles all necessary runtime objects, libraries, and linkers to produce native binaries out of the box.Key Changes
1. Standalone Windows GNU Support
ld.llddirectly for Windows targets, removing the legacy dependency on an externalgccfor the linking stage.crt2.o,libmingw32.a,libkernel32.a,libmsvcrt.a). These are sourced via the Rust toolchain or custom environment paths.x.pyscript now usesobjdumpto recursively identify all non-system PE/DLL dependencies forwavec.exeand its LLVM sub-tools, ensuring all required shared libraries are included in the package.2. Linux Standalone & CRT Management
crt1.susing the bundledllvm-mcto produce architecture-specificcrt1.oobjects for Linux.wavecexecutable. This allows Wave to produce functional Linux binaries in "clean" environments (like minimal Docker containers) without a system-widelibc-devinstallation.3. Backend & Linking Refinement
llcandld.lldprocesses.DT_RPATHor enforcingpatchelf --force-rpath.libffirequired bylibLLVM.so) are correctly resolved from the bundledlib/directory, even when the system loader ignores the newerDT_RUNPATHtag.4. Toolchain Quality Assurance (QA)
x.py packagecommand now utilizes thefileutility to verify that every single bundled binary (executables, shared objects, and DLLs) exactly matches the intended target architecture. The build process will strictly abort if a "poisoned" binary (e.g., an x86_64 library in an aarch64 package) is detected.Rationale
Previously,
wavecrelied on the user having a compatible toolchain installed on their system to perform the final linking. By transitioning to a "Battery-Included" model wherewaveccarries its own linker and C runtime objects, we provide a consistent, predictable experience for developers across all supported platforms.