feat: implement advanced cross-compilation support and backend customization#303
Merged
LunaStev merged 1 commit intowavefnd:masterfrom Mar 7, 2026
Conversation
…ization
This commit introduces a robust framework for cross-compilation and
fine-grained backend control. It expands architecture support for ARM64
and x86_64 across Linux and Darwin, while providing a comprehensive CLI
interface for LLVM backend options.
Changes:
- **LLVM Backend & Cross-Compilation**:
- Introduced `BackendOptions` to parameterize target triple, CPU,
features, ABI, sysroot, and linker settings.
- Updated `generate_ir` to initialize all LLVM targets and use
provided backend options during target machine creation.
- Refactored `abi_c.rs` to support System V ABI for both x86_64 and
Arm64 on Linux and macOS.
- **Enhanced Inline Assembly**:
- Implemented Arm64 register group mapping (`x0`-`x30`, `sp`, etc.)
in `plan.rs`.
- Added support for target-specific inline assembly dialects
(Intel for x86, AT&T for ARM).
- Refined automatic clobber logic to avoid trashing GPRs in empty
barrier-like assembly blocks.
- **Advanced CLI Interface**:
- Added `--llvm` subcommand flags to control the backend: `--target`,
`--cpu`, `--features`, `--abi`, and `--sysroot`.
- Added `-C` flags for linker customization: `linker=<path>`,
`link-arg=<arg>`, and `no-default-libs`.
- Reserved the `--whale` flag for future alternative backend support.
- **Parser & Preprocessor**:
- Significantly improved `#[target(os="...")]` preprocessing logic.
The new scanner is aware of block comments, strings, char literals,
and nested braces, preventing premature truncation of target blocks.
- **Infrastructure & Documentation**:
- Formalized a **Tiered Platform Policy** (Tier 1-4) in `README.md`
to set support expectations.
- Updated `x.py` build script to include `aarch64-unknown-linux-gnu`.
- Cleaned up build artifacts by moving object files to the root
temporary directory before linking.
These updates transform Wave into a portable toolchain capable of
targeting multiple architectures and operating systems from a single host.
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 transforms the Wave compiler into a truly portable toolchain by introducing a robust cross-compilation framework and fine-grained backend control. Key features include expanded architecture support for ARM64 and x86_64, a comprehensive CLI for LLVM and linker customization, and a modernized preprocessor for platform-specific code.
Key Changes
1. Advanced Cross-Compilation Framework
BackendOptionsto manage the target triple, CPU, features, ABI, sysroot, and linker settings.abi_c.rsto support the standard System V ABI for both x86_64 and ARM64 across Linux and macOS.2. Architecture-Specific Inline Assembly
x0throughx30,sp) in the assembly planner.3. Granular CLI Interface
--llvmsubcommand to expose low-level backend options:--target,--cpu,--features,--abi, and--sysroot.-Cflags for advanced linking:linker=<path>,link-arg=<arg>, andno-default-libs.--whaleflag for future alternative backend integrations.4. Robust
#[target]Preprocessing#[target]preprocessor. It is now fully aware of block comments, string/char literals, and nested braces, ensuring that platform-specific code blocks are parsed accurately without premature truncation.5. Infrastructure & Policy
README.mdto set clear expectations for target stability.x.pyto includeaarch64-unknown-linux-gnuand improved build artifact hygiene by streamlining the object file placement during the linking phase.Example Usage
Cross-compiling for ARM64 Linux from an x86 host:
wavec build main.wave \ --llvm-target aarch64-unknown-linux-gnu \ -C linker=aarch64-linux-gnu-gccUsing the improved preprocessor:
Benefits