| name | boxlang-runtime-compiled-native-binaries |
| description | Use this skill when compiling BoxLang scripts to standalone native executables using MatchBox's --target native flag, cross-compiling for multiple platforms, optimizing binary size, and using Native Fusion to expose Rust functions as BoxLang built-in functions. |
BoxLang Compiled Native Binaries
Overview
MatchBox can compile BoxLang source code to standalone native executables using --target native. The resulting binary embeds a small Rust runner stub (~500 KB) with the compiled BoxLang bytecode appended, requiring no JVM or MatchBox installation on the target machine.
Building a Native Binary
matchbox --target native app.bxs
./app --config=prod.json --debug
The binary accepts the same CLI argument format as the matchbox runner.
Cross-Compilation
Build for multiple platforms using GitHub Actions (recommended) or the cross Rust tool:
GitHub Actions (5 targets in parallel)
name: Build Native Binaries
on:
push:
tags: ["v*"]
jobs:
build:
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact: app-linux-x64
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
artifact: app-linux-arm64
- os: macos-latest
target: x86_64-apple-darwin
artifact: app-macos-x64
- os: macos-latest
target: aarch64-apple-darwin
artifact: app-macos-arm64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact: app-windows-x64.exe
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install MatchBox
run: curl -sSL https://raw.githubusercontent.com/ortus-boxlang/matchbox/master/install/install.sh | bash
- name: Compile
run: matchbox --target native --arch ${{ matrix.target }} app.bxs -o ${{ matrix.artifact }}
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: ${{ matrix.artifact }}
Cross-compilation with cargo cross
cargo install cross
cross build --release --target aarch64-unknown-linux-gnu
Binary Size Optimizations
The default release binary is ~500 KB. You can reduce further with these Rust profile settings in Cargo.toml:
[profile.release]
opt-level = "z"
lto = true
codegen-units = 1
strip = true
Native Fusion — Rust BIFs
Native Fusion lets you write Rust functions and expose them as BoxLang BIFs inside a native binary. This is for performance-critical operations that can't be done efficiently in BoxLang:
use matchbox_sdk::prelude::*;
fn fast_hash(value: &str) -> String {
format!("{:x}", md5::compute(value))
}
fn main() {
let engine = MatchBoxEngine::new()
.register_bifs(vec![
bif!("FastHash", fast_hash)
])
.run_file("app.bxs");
}
var hash = FastHash( "hello world" )
println( hash )
Build as a combined Rust + BoxLang executable:
cargo build --release
Distribution Patterns
Single self-contained binary
matchbox --target native app.bxs -o myapp
Docker with minimal image
FROM scratch
COPY myapp /myapp
ENTRYPOINT ["/myapp"]
Results in an image with only the executable — < 1MB total.
Checklist