Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cross-Compilation

Cross-compilation builds the transpiled Rust project for a target platform different from the host. Batuta supports cross-compilation through Cargo’s target triple system and the cross tool.

Target Triples

A target triple specifies the architecture, vendor, OS, and ABI:

<arch>-<vendor>-<os>-<abi>

Common Targets

Target TriplePlatformUse Case
x86_64-unknown-linux-gnuLinux x86-64 (glibc)Standard Linux servers
x86_64-unknown-linux-muslLinux x86-64 (musl)Static binaries, Alpine
aarch64-unknown-linux-gnuLinux ARM64AWS Graviton, Raspberry Pi 4
x86_64-apple-darwinmacOS IntelMac development
aarch64-apple-darwinmacOS Apple SiliconM1/M2/M3 Macs
x86_64-pc-windows-msvcWindows x86-64Windows deployment
wasm32-unknown-unknownWebAssemblyBrowser deployment

Using Cargo Directly

# Install target toolchain
rustup target add aarch64-unknown-linux-gnu

# Cross-compile
batuta build --release --target aarch64-unknown-linux-gnu

Using the cross Tool

The cross tool uses Docker containers with pre-configured cross-compilation toolchains:

# Install cross
cargo install cross

# Cross-compile without manual toolchain setup
cross build --release --target aarch64-unknown-linux-gnu

This is the recommended approach because it handles linker configuration, system libraries, and C dependencies automatically.

musl Static Linking

The musl target produces fully static binaries with no dynamic library dependencies, ideal for Docker scratch containers, Lambda functions, and air-gapped environments:

rustup target add x86_64-unknown-linux-musl
batuta build --release --target x86_64-unknown-linux-musl

WebAssembly Target

WASM builds require special handling. See the Batuta wasm feature flag:

# WASM debug build
batuta build --wasm

# WASM release build
batuta build --wasm --release

The WASM build disables filesystem access and uses in-memory analysis, controlled by the wasm feature flag in Cargo.toml.

Configuration

Cross-compilation settings in batuta.toml:

[build]
target = "x86_64-unknown-linux-musl"
cargo_flags = ["--locked"]

Navigate: Table of Contents