mohitmishra786/low-level-dev-skills

rust-cross

Rust cross-compilation skill.

소스 보기

사용 방법

  1. 설치 명령을 복사하고 자신의 에이전트 환경에 설치하기 전에 소스 패키지를 확인하세요.
  2. 필요한 도구, 인증 정보, 지원 환경은 원본 문서에서 확인하세요.
  3. 입력과 원하는 산출물을 설명하고 출처와 결과를 대조하세요.
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill rust-cross

시작 전 확인

  • 설치에는 모델 구독, API 한도, 파일 접근 권한이 포함되지 않습니다.
  • 별점 수와 설치 수는 활동 지표이며 독립적인 품질·보안 검증이 아닙니다.
원본 Skill 문서

원본 저장소의 제목, 예시, 코드, 표, 링크, 이미지를 유지해 표시합니다.

Rust Cross-Compilation

Purpose

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.

Triggers

  • "How do I cross-compile Rust for ARM/aarch64?"
  • "How do I build a Rust binary for a different OS?"
  • "How do I use the cross tool for Rust cross-compilation?"
  • "How do I build Rust for embedded (no_std) targets?"
  • "How do I use cargo-zigbuild?"
  • "My cross-compiled Rust binary won't run on the target"

Workflow

1. Add a rustup target

bash
# 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

2. Common target triples

TargetUse case
x86_64-unknown-linux-gnuLinux x86-64 (glibc)
x86_64-unknown-linux-muslLinux x86-64 (musl, static)
aarch64-unknown-linux-gnuARM64 Linux (Raspberry Pi 4, AWS Graviton)
aarch64-unknown-linux-muslARM64 Linux static
x86_64-pc-windows-gnuWindows x86-64 (MinGW)
x86_64-pc-windows-msvcWindows x86-64 (MSVC)
x86_64-apple-darwinmacOS x86-64
aarch64-apple-darwinmacOS Apple Silicon
wasm32-unknown-unknownWASM (browser)
wasm32-wasiWASM with WASI
thumbv7m-none-eabiCortex-M3 bare metal
thumbv7em-none-eabihfCortex-M4/M7 with FPU
riscv32imac-unknown-none-elfRISC-V 32-bit bare metal

3. cross tool (Docker-based, easiest)

cross uses pre-built Docker images with the correct cross-toolchain:

bash
# 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
toml
# 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"]

4. cargo-zigbuild (zero-setup, uses zig cc)

zig cc ships a complete C cross-toolchain — no system cross-compiler needed:

bash
# 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:

  • No Docker required
  • Faster (no container startup)
  • Works for most targets out of the box
  • Supports precise glibc version targeting

5. .cargo/config.toml for cross targets

toml
# .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"

6. Static binaries with musl

bash
# 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

7. Embedded bare-metal (#[no_std])

toml
# .cargo/config.toml
[build]
target = "thumbv7em-none-eabihf"   # Set default target

[target.'cfg(target_arch = "arm")']
runner = "probe-run --chip STM32F411CE"
rust
// 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 {}
}
toml
# Cargo.toml
[dependencies]
cortex-m = "0.7"
cortex-m-rt = "0.7"

[profile.release]
opt-level = "z"
lto = true
codegen-units = 1
panic = "abort"
bash
cargo build --release  # Uses default target from .cargo/config.toml

For target triple reference and embedded setup details, see references/.

Related skills

  • Use skills/rust/rustc-basics for compiler and profile configuration
  • Use skills/compilers/cross-gcc for the underlying cross-compiler setup
  • Use skills/zig/zig-cross for Zig's native cross-compilation approach
  • Use skills/build-systems/cmake when Rust is part of a CMake cross-build

관련 작업

같은 저장소의 Skills

더 많은 Skills

모든 Skills
mohitmishra786
커뮤니티

core-dumps

Core dump analysis skill for production crash triage. Use when loading core files in GDB or LLDB, enabling core dump generation on Linux/macOS, mapping symbols with debuginfo or debuginfod, or extracting backtraces from crashes without re-running the program. Activates on queries about core files, ulimit, coredumpctl, debuginfod, crash triage, or analyzing segfaults from production binaries.

설치 수
2
GitHub Stars
267
업데이트
6월 27일
mohitmishra786
커뮤니티

custom-allocators

Custom allocator skill for memory allocation strategies. Use when implementing pool/slab/arena allocators, tuning jemalloc/mimalloc, writing Rust GlobalAlloc, or benchmarking allocator performance. Activates on queries about jemalloc, mimalloc, tcmalloc, arena allocator, GlobalAlloc, or fragmentation.

설치 수
2
GitHub Stars
267
업데이트
6월 27일
mohitmishra786
커뮤니티

ebpf

eBPF skill for Linux observability and networking. Use when writing eBPF programs with libbpf or bpftrace, attaching kprobes/tracepoints/XDP hooks, debugging verifier errors, working with eBPF maps, or achieving CO-RE portability across kernel versions. Activates on queries about eBPF, bpftool, bpftrace, XDP programs, libbpf, verifier errors, eBPF maps, or kernel tracing with BPF.

설치 수
2
GitHub Stars
267
업데이트
6월 27일
mohitmishra786
커뮤니티

flamegraphs

Flamegraph generation and interpretation skill. Use when converting perf, Valgrind Callgrind, or other profiler output into SVG flamegraphs using Brendan Gregg's FlameGraph tools, or when reading flamegraphs to identify performance bottlenecks. Activates on queries about flamegraphs, stackcollapse, flamegraph.svg, identifying hot frames, wide vs tall frames, or performance visualisation.

설치 수
2
GitHub Stars
267
업데이트
6월 27일