skills/rust/rust-cross/SKILL.md
Rust cross-compilation skill. Use when building Rust binaries for a different target architecture or OS, using cross or cargo-zigbuild for hermetic cross-compilation, configuring .cargo/config.toml for cross targets, or targeting embedded and bare-metal systems. Activates on queries about Rust cross-compilation, rustup targets, cross tool, cargo-zigbuild, aarch64-unknown-linux-gnu, thumbv7m-none-eabi, or building for embedded.
npx skillsauth add mohitmishra786/low-level-dev-skills rust-crossInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guide agents through Rust cross-compilation: adding rustup targets, using cross for hermetic Docker-based cross-builds, cargo-zigbuild for zero-setup cross-compilation, .cargo/config.toml configuration, and embedded bare-metal targets.
# List installed targets
rustup target list --installed
# List all available targets
rustup target list
# Add a target
rustup target add aarch64-unknown-linux-gnu
rustup target add x86_64-unknown-linux-musl # static Linux
rustup target add wasm32-unknown-unknown # WASM
rustup target add thumbv7m-none-eabi # Cortex-M
# Build for target
cargo build --target aarch64-unknown-linux-gnu --release
| Target | Use case |
|--------|----------|
| x86_64-unknown-linux-gnu | Linux x86-64 (glibc) |
| x86_64-unknown-linux-musl | Linux x86-64 (musl, static) |
| aarch64-unknown-linux-gnu | ARM64 Linux (Raspberry Pi 4, AWS Graviton) |
| aarch64-unknown-linux-musl | ARM64 Linux static |
| x86_64-pc-windows-gnu | Windows x86-64 (MinGW) |
| x86_64-pc-windows-msvc | Windows x86-64 (MSVC) |
| x86_64-apple-darwin | macOS x86-64 |
| aarch64-apple-darwin | macOS Apple Silicon |
| wasm32-unknown-unknown | WASM (browser) |
| wasm32-wasi | WASM with WASI |
| thumbv7m-none-eabi | Cortex-M3 bare metal |
| thumbv7em-none-eabihf | Cortex-M4/M7 with FPU |
| riscv32imac-unknown-none-elf | RISC-V 32-bit bare metal |
cross uses pre-built Docker images with the correct cross-toolchain:
# Install
cargo install cross
# Build (drop-in replacement for cargo)
cross build --target aarch64-unknown-linux-gnu --release
cross test --target aarch64-unknown-linux-gnu
# Cross.toml — project configuration
# Cross.toml
[target.aarch64-unknown-linux-gnu]
image = "ghcr.io/cross-rs/aarch64-unknown-linux-gnu:main"
pre-build = [
"apt-get update && apt-get install -y libssl-dev:arm64"
]
[build.env]
passthrough = ["PKG_CONFIG_PATH", "OPENSSL_DIR"]
zig cc ships a complete C cross-toolchain — no system cross-compiler needed:
# Install
cargo install cargo-zigbuild
# Also needs zig installed: https://ziglang.org/download/
# Build (no Docker, no system cross-compiler)
cargo zigbuild --target aarch64-unknown-linux-gnu --release
cargo zigbuild --target x86_64-unknown-linux-musl --release
# Target with glibc version (important for compatibility)
cargo zigbuild --target aarch64-unknown-linux-gnu.2.17 --release
# This builds against glibc 2.17 (very compatible)
# Windows from Linux/macOS
cargo zigbuild --target x86_64-pc-windows-gnu --release
cargo-zigbuild advantages over cross:
# .cargo/config.toml
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc" # System cross-linker
# or with zig:
# linker = "zig"
# rustflags = ["-C", "link-arg=cc", "-C", "link-arg=-target", "-C", "link-arg=aarch64-linux-gnu"]
[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"
rustflags = ["-C", "target-feature=+crt-static"]
[target.wasm32-unknown-unknown]
runner = "wasmtime" # Run WASM tests with wasmtime
[target.thumbv7m-none-eabi]
runner = "qemu-arm -cpu cortex-m3"
# Add musl target
rustup target add x86_64-unknown-linux-musl
# Build statically linked binary
cargo build --target x86_64-unknown-linux-musl --release
# Verify it's static
file target/x86_64-unknown-linux-musl/release/myapp
# → ELF 64-bit, statically linked, not stripped
# Or with cargo-zigbuild (easier musl)
cargo zigbuild --target x86_64-unknown-linux-musl --release
# .cargo/config.toml
[build]
target = "thumbv7em-none-eabihf" # Set default target
[target.'cfg(target_arch = "arm")']
runner = "probe-run --chip STM32F411CE"
// src/main.rs
#![no_std]
#![no_main]
use core::panic::PanicInfo;
#[cortex_m_rt::entry]
fn main() -> ! {
loop {}
}
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
# Cargo.toml
[dependencies]
cortex-m = "0.7"
cortex-m-rt = "0.7"
[profile.release]
opt-level = "z"
lto = true
codegen-units = 1
panic = "abort"
cargo build --release # Uses default target from .cargo/config.toml
For target triple reference and embedded setup details, see references/.
skills/rust/rustc-basics for compiler and profile configurationskills/compilers/cross-gcc for the underlying cross-compiler setupskills/zig/zig-cross for Zig's native cross-compilation approachskills/build-systems/cmake when Rust is part of a CMake cross-builddevelopment
QEMU/KVM skill for virtualization and kernel development. Use when running qemu-system-x86_64 with KVM, configuring virtio devices, VFIO passthrough, QMP monitor, libvirt, or booting custom kernels. Activates on queries about QEMU, KVM, virtio, VFIO, virsh, virt-install, or -kernel -append.
development
Hardware virtualization internals skill for Intel VT-x and AMD-V. Use when studying VMCS/VMCB, EPT/NPT page tables, VMEXIT handling, APIC virtualization, or building minimal hypervisors. Activates on queries about VMX, SVM, VMCS, EPT, NPT, VMEXIT, or type-1 hypervisor.
testing
Linux containers internals skill for namespaces, cgroups, and OCI. Use when understanding clone/unshare namespaces, cgroups v2 limits, overlayfs, runc, seccomp profiles, capabilities, or escape mitigations. Activates on queries about namespaces, cgroups, overlayfs, runc, seccomp-bpf, OCI spec, or container escape.
tools
Reverse engineering skill for binary analysis. Use when decompiling with Ghidra, analyzing with radare2, scripting RE tools, triaging with strings/file/xxd, or diffing binaries. Activates on queries about Ghidra, radare2, r2, decompiler, Binary Ninja, Diaphora, or stripped binary analysis.