Compiled Native Binaries
Learn to build compiled native binaries with MatchBox
Native Builds
MatchBox can compile your BoxLang application into a single, self-contained native binary for your operating system. The resulting executable requires no JVM, no MatchBox installation, and no runtime dependencies of any kind.
How it Works
MatchBox uses a runner stub architecture to produce lean binaries:
A pre-compiled, stripped, architecture-specific runner stub (~500 KB) contains only the VM core.
The
matchboxcompiler compiles your.bxssource to bytecode.The bytecode is appended to the end of the stub binary.
At startup, the stub reads its own trailing bytes, finds the embedded bytecode, and executes it.
This means no intermediate files, no installers, and no external loaders — just a single file you can chmod +x and ship.
Building a Native Binary
matchbox --target native my_app.bxsThis produces an executable named after your input file (e.g., my_app on macOS/Linux, my_app.exe on Windows).
Full Example
Create cli_tool.bxs:
Compile:
Run:
Cross-Compilation
Native binaries are platform-specific. To produce binaries for other targets you have two options:
Option A: GitHub Actions (recommended)
Use the included GitHub Actions workflow. Every tagged release automatically builds binaries for:
x86_64-unknown-linux-gnuaarch64-unknown-linux-gnux86_64-apple-darwinaarch64-apple-darwinx86_64-pc-windows-msvc
Option B: Manual Cross-Compilation
Add the desired Rust target and build:
Note: cross-compilation may require a cross-linker for the target platform. The cross tool simplifies this via Docker:
Binary Size
MatchBox applies aggressive size optimizations in the release profile:
The resulting binaries are typically ~500 KB — small enough to ship as a GitHub release asset or embed in a container image.
Native Fusion: Rust Interop
Native Fusion lets you write performance-critical functions in Rust and expose them as BoxLang BIFs (Built-In Functions), all statically linked into your final binary.
For the full macro and API reference, see Native Fusion Reference.
When to Use It
You need maximum throughput for a hot path (e.g., data parsing, compression, crypto).
You want to use a Rust crate (e.g.,
serde,reqwest,image) from BoxLang.You need direct access to OS or hardware APIs.
Setting Up a Native Fusion Project
Create your BoxLang entry point, e.g.,
app.bxs.Create a
native/directory alongside it.Write one or more
.rsfiles insidenative/.
When MatchBox detects the native/ directory, it compiles the Rust files together with the VM and links everything into the final binary.
Writing a Native BIF
Each file in native/ must expose a register_bifs function that returns a map of function names to implementations:
Call it from BoxLang like any other BIF:
Build
MatchBox automatically detects native/, compiles the Rust code, merges the BIF registrations, and produces the final binary. No extra tooling needed.
Experimental Java Interop (JNI)
In native builds only, MatchBox includes an experimental JNI bridge that lets you instantiate Java classes and call methods — provided a compatible JVM is installed on the host machine at runtime.
This feature is highly experimental. APIs may change and stability is not guaranteed.
This is not available in WASM builds.
Last updated
Was this helpful?
