Skip to content

crossCompile()

Cross-compile a project for multiple targets.

Signature

zig
pub fn crossCompile(b: *std.Build, compile: *Step.Compile, cfg: CrossConfig) void

CrossConfig

zig
pub const CrossConfig = struct {
    targets: []const std.Target.Query = &.{},
    step_name: []const u8 = "cross",
    step_desc: []const u8 = "Cross compile for all targets",
};

Usage

zig
_ = buildx.project(b, .{
    .name = "myapp",
    .root = "src/main.zig",
    .cross = .{
        .targets = buildx.targets.desktop(),
    },
});

Standalone

zig
const exe = buildx.project(b, .{
    .name = "myapp",
    .root = "src/main.zig",
});

buildx.crossCompile(b, exe, .{
    .targets = &.{
        .{ .cpu_arch = .x86_64, .os_tag = .linux },
        .{ .cpu_arch = .aarch64, .os_tag = .linux },
    },
});

Target Presets

PresetTargetsDescription
targets.all()216All OS + all architectures
targets.desktop()6Windows/Linux/macOS, x86_64 + aarch64
targets.linux()16Linux, all architectures
targets.windows()4Windows, x86/x64/ARM/AArch64
targets.macos()2macOS, x86_64 + aarch64
targets.arm()24ARM/AArch64 across all OS
targets.riscv()2RISC-V 32/64 on Linux
targets.freestanding()8No OS, all architectures
targets.wasm()2WebAssembly 32/64 on WASI

Output

Artifacts are placed in zig-out/bin/ with triple suffixes:

zig-out/bin/myapp-x86_64-linux
zig-out/bin/myapp-aarch64-linux
zig-out/bin/myapp-x86_64-windows.exe

Released under the MIT License.