2.8 KiB
Bux Cross-Compilation Support — Design Document
Date: 2026-06-10 Status: Approved Scope: MVP cross-compilation via
--targetCLI flag
1. Overview
Bux compiles to C, which means cross-compilation is nearly free — we only need to pass the correct target triple to the C compiler (cc). This feature adds --target <triple> support to the Bux CLI.
Goals
bux build --target aarch64-linux-gnuproduces an ARM64 binarybux build --target x86_64-windows-gnuproduces a Windows binary- No changes to the compiler pipeline — only the final
ccinvocation changes
Non-Goals
- Automatic cross-compiler toolchain detection
- Custom linker scripts or startup code
- Multiple target builds in one invocation
2. How Cross-Compilation Works
Bux compilation pipeline:
.bux source → lexer → parser → sema → HIR → C code → cc → binary
The entire pipeline is target-independent until the final cc step. For cross-compilation:
- Bux generates the same C code
- Instead of
cc -O2 -pthread -o output ... - We run
cc -O2 -pthread -target aarch64-linux-gnu -o output ...
Or, if a cross-compiler prefix is needed:
aarch64-linux-gnu-gcc -O2 -pthread -o output ...
3. CLI Interface
# Native build (default)
bux build
# Cross-compile to ARM64 Linux
bux build --target aarch64-linux-gnu
# Cross-compile to Windows
bux build --target x86_64-pc-windows-gnu
# Also works with buxc project
buxc project . --target aarch64-linux-gnu
4. Implementation
Changes to src/cli.bux
-
Parse
--targetflag: InCli_Run, scanargsfor--targetbefore processing the command. Extract the target triple. -
Store target: Add a global variable
g_targetTriple: String(default""). -
Pass to
cc: In bothCli_Compile(line ~251) andCli_BuildProject(line ~1143), append-target <triple>to thecccommand ifg_targetTripleis set.
Target Triple Format
We pass the triple directly to cc without validation. Examples:
aarch64-linux-gnu→cc -target aarch64-linux-gnu ...x86_64-pc-windows-gnu→cc -target x86_64-pc-windows-gnu ...wasm32-wasi→cc -target wasm32-wasi ...
Error Handling
If cc fails with an invalid target, the user sees the standard cc error message. Bux does not need custom error handling for this.
5. Files to Modify
| File | Change |
|---|---|
src/cli.bux |
Parse --target flag, store in global, append to cc command |
6. Testing
- Native build:
bux build— should work as before (no-targetflag) - Invalid target:
bux build --target invalid-target—ccshould fail with appropriate error - Valid target (if cross-compiler available):
bux build --target aarch64-linux-gnu— should produce ARM64 binary