/dstack-native:zig-crossfrom DStack Native
Guides Zig cross-compilation: target triples, -mcpu features, zig cc for C, multi-target build.zig, bare-metal Cortex-M, and WebAssembly targets.
Ships in DStack Native. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You build a binary for a different OS or CPU than the build host, from Zig or C sources, using Zig as the cross toolchain. You work read-only: you hand the user the triple, the CPU choice, and the exact commands or build.zig loop in chat, and they run them. Scratch cross builds go in a scratch directory, never into the project's outputs. You are done when the triple is confirmed in zig targets on the installed Zig and a scratch build for that triple produces a file whose file line matches the target platform.
Ask for anything missing rather than guessing it:
zig version. The commands below ran on Zig 0.14.1.Compose the triple as <arch>-<os>-<abi> using only names from the lists zig targets prints. That output is a ZON document: .arch, .os, and .abi hold the legal names, and .libc lists the triples with a bundled libc. Common choices:
x86_64-linux-gnu, x86_64-linux-musl (static), aarch64-linux-gnu, aarch64-linux-musl, arm-linux-gnueabihf (32-bit ARM with FPU), x86_64-windows-gnu, aarch64-macos-none, x86_64-macos-none, wasm32-freestanding, wasm32-wasi, thumb-freestanding-eabihf (Cortex-M with FPU; the CPU selects the M variant), riscv32-freestanding-none.
The triple counts only if it appears in zig targets. A fuller list lives in references/zig-target-triples.md.
zig build-exe src/main.zig -target aarch64-linux-gnu -O ReleaseFast, or through the build system with zig build -Dtarget=aarch64-linux-gnu -Doptimize=ReleaseFast.-target x86_64-windows-gnu produces a .exe.-target aarch64-macos-none links a plain executable on its own; code that needs Apple frameworks needs the macOS SDK passed via --sysroot and framework paths.The build counts when file reports the target's executable format.
-mcpu native detects the build host and is wrong for a cross build. -mcpu baseline is the portable floor for the architecture. Add or remove features with + and -:
-mcpu x86_64+avx2+bmi2, -mcpu x86_64_v3-mcpu cortex_a72 (Raspberry Pi 4)-mcpu cortex_m4+vfp4-mcpu neoverse_n1, -mcpu apple_m1CPU and feature names are listed per architecture under .cpus in zig targets; the choice counts only if it appears there. If Zig prints is not a recognized feature, that is distribution noise (Zig built against a different LLVM), not failure: the build still completes, so report it and move on.
zig cczig cc needs no system cross toolchain:
zig cc -target aarch64-linux-gnu -O2 -o myapp-arm64 main.czig cc -target x86_64-windows-gnu main.c -o myapp.exezig cc -target x86_64-linux-musl -static main.c -o myapp-staticIn a Makefile, define one CC per platform, for example CC_LINUX_ARM64 = zig cc -target aarch64-linux-gnu. The artifact counts when it matches the target format.
build.zigLoop over std.Target.Query values, resolve each with b.resolveTargetQuery(t), and give each executable a distinct name:
const targets = [_]std.Target.Query{
.{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu },
.{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu },
.{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .gnu },
.{ .cpu_arch = .aarch64, .os_tag = .macos },
};
for (targets) |t| {
const exe = b.addExecutable(.{
.name = b.fmt("myapp-{s}-{s}", .{ @tagName(t.cpu_arch.?), @tagName(t.os_tag.?) }),
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = b.resolveTargetQuery(t),
.optimize = .ReleaseFast,
}),
});
b.installArtifact(exe);
}
This counts when zig-out/bin holds one artifact per target.
zig build-exe src/main.zig -target thumb-freestanding-eabihf -mcpu cortex_m4+vfp4 -O ReleaseSmall -T linker.ld. The root file supplies pub fn panic(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn and an exported entry point named in the linker script, such as export fn _start() void. Freestanding code cannot use std facilities that need an OS (threads, files, std.debug.print); when the compiler reports Unsupported operating system freestanding, remove the offending std call from the freestanding path. The result counts when the ELF links with the script's entry symbol.
zig build-exe src/main.zig -target wasm32-freestanding -O ReleaseSmall --export=init --export=update -fno-entry, where each exported function is export fn.zig build-exe src/main.zig -target wasm32-wasi -O ReleaseSafe produces main.wasm for a WASI runtime.Either counts when file reports a WebAssembly module.
available architectures: listing after -target means the arch name is not one Zig uses. thumbv7em is not an arch; thumb plus -mcpu cortex_m4 is.Unsupported operating system freestanding means an std call needs an OS. Remove it from the freestanding path.--sysroot and framework paths; a plain executable needs nothing.rust-cross. Naming that skill never runs it.A chat report with the triple and CPU, the build command or build.zig loop, the bare-metal or WebAssembly specifics when they apply, and the file line from the scratch build proving the target format.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
zig, cross-compilation, target-triples, mcpu, bare-metal, wasm
npx claudepluginhub gosuda/dstack-skills --plugin dstack-native18 skills in this plugin
/abi-and-calling-conventionsUse when explaining System V AMD64, ARM AAPCS, RISC-V psABI, stack frames, variadic calls, or FFI register rules. Not for the Rust FFI binding layer: use rust-ffi./assembly-armUse when reading or writing AArch64 or AArch32 Thumb assembly, inline asm in C, AAPCS64 register roles, or NEON and SVE vector code. Not for ABI detail across ISAs: use abi-and-calling-conventions./assembly-x86Use when reading GCC or Clang x86-64 assembly, writing inline asm, decoding AT&T syntax, or applying System V AMD64 register rules. Not for SIMD intrinsic selection./c-hardening-baselineUse when C code is written or audited and needs a pure-C baseline: standard, undefined behavior, integer and buffer safety, sanitizers, fuzzing, build flags. Not for C++./code-generation-and-backendsUse when reading llc output, tracing IR through legalization and instruction selection, or scoping a new LLVM target. Not for IR-level passes./compiler-frontendUse when building a lexer, Pratt or recursive-descent parser, AST, symbol table, type checker, or LLVM IR emitter for a language or DSL. Not for optimizing IR.Other plugins' skills for the same job