mohitmishra786/low-level-dev-skills / skills/rust/rust-cross
rust-cross
VerifiedRust 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 5.8 KB |
| references/cross-targets.md | markdown | 4.2 KB |
references/cross-targets.md
View on GitHub# Rust Cross-Compilation Target Reference
## Full Target Triple Format
```text
<cpu_arch>-<vendor>-<os>-<abi>
```
- `cpu_arch`: x86_64, aarch64, armv7, thumbv7m, riscv32imac, wasm32, ...
- `vendor`: unknown, pc, apple, (omitted for bare metal)
- `os`: linux, windows, macos, none (bare metal), wasi
- `abi`: gnu, musl, msvc, eabi, eabihf, (omitted for some)
## Tier 1 Targets (guaranteed to work)
| Target | Platform |
|--------|----------|
| `x86_64-unknown-linux-gnu` | Linux 64-bit (glibc) |
| `x86_64-pc-windows-gnu` | Windows 64-bit (MinGW) |
| `x86_64-pc-windows-msvc` | Windows 64-bit (MSVC) |
| `x86_64-apple-darwin` | macOS 64-bit |
| `aarch64-unknown-linux-gnu` | ARM64 Linux |
| `aarch64-apple-darwin` | macOS Apple Silicon |
| `i686-unknown-linux-gnu` | Linux 32-bit |
## Popular Tier 2 Targets
| Target | Platform | Notes |
|--------|----------|-------|
| `x86_64-unknown-linux-musl` | Linux static | No glibc dep |
| `aarch64-unknown-linux-musl` | ARM64 Linux static | |
| `armv7-unknown-linux-gnueabihf` | ARM 32-bit Linux | Raspberry Pi 2/3 (32-bit) |
| `wasm32-unknown-unknown` | WASM browser | No std |
| `wasm32-wasip1` | WASM WASI preview 1 (formerly `wasm32-wasi`) | Some std |
| `wasm32-wasip2` | WASM component, WASI 0.2 | Some std |
| `x86_64-unknown-freebsd` | FreeBSD | |
| `aarch64-linux-android` | Android ARM64 | |
| `x86_64-linux-android` | Android x86-64 | |
## Bare Metal (Embedded) Targets
| Target | Architecture | Use case |
|--------|-------------|----------|
| `thumbv6m-none-eabi` | Cortex-M0/M0+ | RP2040, lowest-end MCUs |
| `thumbv7m-none-eabi` | Cortex-M3 | STM32F1, LPC1768 |
| `thumbv7em-none-eabi` | Cortex-M4/M7 (no FPU) | STM32F4 without FPU |
| `thumbv7em-none-eabihf` | Cortex-M4/M7 (FPU) | STM32F4/F7 with FPU |
| `thumbv8m.main-none-eabi` | Cortex-M33 | STM32U5, nRF9160 |
| `riscv32imac-unknown-none-elf` | RISC-V 32-bit | ESP32-C3, GD32VF |
| `riscv64imac-unknown-none-elf` | RISC-V 64-bit | SiFive boards |
| `avr-unknown-gnu-atmega328` | AVR | Arduino Uno (nightly only) |
## Glibc Version Targeting (cargo-zigbuild)
```bash
# Format: <target>.<glibc_major>.<glibc_minor>
cargo zigbuild --target aarch64-unknown-linux-gnu.2.17 # Very compatible
cargo zigbuild --target x86_64-unknown-linux-gnu.2.28 # Modern systems
cargo zigbuild --target aarch64-unknown-linux-gnu.2.35 # Ubuntu 22.04+
# Check required glibc version of a binary
objdump -T ./myapp | grep GLIBC
readelf -V ./myapp
```
## cross Docker Images
```bash
# List available images
docker pull ghcr.io/cross-rs/aarch64-unknown-linux-gnu:main
# Available at ghcr.io/cross-rs/<target>:main
# aarch64-unknown-linux-gnu
# x86_64-unknown-linux-musl
# armv7-unknown-linux-gnueabihf
# aarch64-unknown-linux-musl
# x86_64-pc-windows-gnu
# ... (see https://github.com/cross-rs/cross)
```
## OpenSSL Cross-Compilation
OpenSSL is the most common pain point in cross-compilation:
```bash
# Option 1: use rustls instead (no C dependency)
# In Cargo.toml:
# reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"] }
# Option 2: cross with pre-built OpenSSL
# Cross.toml:
# [target.aarch64-unknown-linux-gnu]
# pre-build = ["apt-get install -y libssl-dev:arm64"]
# Option 3: cargo-zigbuild with vendored OpenSSL
OPENSSL_STATIC=1 cargo zigbuild --target aarch64-unknown-linux-gnu
# Option 4: openssl-src crate (builds from source)
# [dependencies]
# openssl = { version = "0.10", features = ["vendored"] }
```
## Embedded Project Structure
```text
my-embedded/
├── .cargo/
│ └── config.toml # default target, runner, linker
├── Cargo.toml
├── memory.x # Linker script (memory map)
├── build.rs # Copy memory.x to OUT_DIR
└── src/
└── main.rs # #![no_std] #![no_main]
```
```text
# .cargo/config.toml for STM32F4
[build]
target = "thumbv7em-none-eabihf"
[target.thumbv7em-none-eabihf]
runner = "probe-run --chip STM32F411CEUx"
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=--nmagic",
]
```
```toml
# Cargo.toml for embedded
[dependencies]
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7"
stm32f4xx-hal = { version = "0.20", features = ["stm32f411"] }
panic-probe = { version = "0.3", features = ["print-defmt"] }
defmt = "0.3"
defmt-rtt = "0.4"
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |