https://github.com/ibrahimcesar/xcargo
π― Cross-compilation, zero friction - Build Rust for any target with automatic toolchain management, Zig integration, and containers
https://github.com/ibrahimcesar/xcargo
build-tool cargo cli cross-compilation cross-platform developer-tools docker linux macos multiplatform rust toolchain windows zig
Last synced: 3 months ago
JSON representation
π― Cross-compilation, zero friction - Build Rust for any target with automatic toolchain management, Zig integration, and containers
- Host: GitHub
- URL: https://github.com/ibrahimcesar/xcargo
- Owner: ibrahimcesar
- License: mit
- Created: 2025-11-18T12:06:44.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2026-02-22T17:31:27.000Z (4 months ago)
- Last Synced: 2026-03-10T00:41:28.541Z (3 months ago)
- Topics: build-tool, cargo, cli, cross-compilation, cross-platform, developer-tools, docker, linux, macos, multiplatform, rust, toolchain, windows, zig
- Language: Rust
- Homepage: https://ibrahimcesar.github.io/xcargo/
- Size: 1.69 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: .github/SECURITY_EVALUATION.md
- Roadmap: ROADMAP.md
Awesome Lists containing this project
README
# xcargo π―
_Cross-compilation, zero friction_
**xcargo** is a Rust cross-compilation tool that just works. Automatic toolchain management, beautiful output, and zero-configuration cross-compilation.
[](https://crates.io/crates/xcargo)
[](https://docs.rs/xcargo)
[](https://opensource.org/licenses/MIT)
[Installation](#-installation) | [Quick Start](#-quick-start) | [Documentation](https://ibrahimcesar.github.io/xcargo) | [Examples](#-usage-examples)
## β¨ Features
- π― **Zero Configuration** - Works out of the box for most targets
- π§ **Auto-Installation** - Automatically installs missing toolchains and targets
- π¨ **Beautiful Output** - Colored messages with helpful tips and hints
- β‘ **Smart Detection** - Figures out what you need automatically
- π¦ **Interactive Setup** - TUI wizard for easy project configuration
- π **Parallel Builds** - Build multiple targets concurrently for 2-3x speedup
- π¦ **Zig Integration** - Auto-detect Zig for zero-config cross-compilation (macOS/Windows β Linux)
- π³ **Container Support** - Docker/Podman integration for complex cross-compilation
- π **Many Targets** - Linux, Windows, macOS, WebAssembly, and more
- π€ **CI/CD Ready** - Perfect for GitHub Actions, GitLab CI
## π¦ Installation
### Quick Install (Recommended)
#### macOS / Linux
```bash
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/ibrahimcesar/xcargo/releases/latest/download/xcargo-installer.sh | sh
```
#### Windows (PowerShell)
```powershell
irm https://github.com/ibrahimcesar/xcargo/releases/latest/download/xcargo-installer.ps1 | iex
```
### Package Managers
#### Homebrew (macOS / Linux)
```bash
brew install ibrahimcesar/tap/xcargo
```
#### Cargo (from source)
```bash
# Coming soon: cargo install xcargo
# Install from GitHub
cargo install --git https://github.com/ibrahimcesar/xcargo
```
### Prebuilt Binaries
Download prebuilt binaries from the [latest release](https://github.com/ibrahimcesar/xcargo/releases/latest):
- **macOS (Apple Silicon)**: [xcargo-aarch64-apple-darwin.tar.xz](https://github.com/ibrahimcesar/xcargo/releases/latest/download/xcargo-aarch64-apple-darwin.tar.xz)
- **macOS (Intel)**: [xcargo-x86_64-apple-darwin.tar.xz](https://github.com/ibrahimcesar/xcargo/releases/latest/download/xcargo-x86_64-apple-darwin.tar.xz)
- **Linux (glibc)**: [xcargo-x86_64-unknown-linux-gnu.tar.xz](https://github.com/ibrahimcesar/xcargo/releases/latest/download/xcargo-x86_64-unknown-linux-gnu.tar.xz)
- **Linux (musl)**: [xcargo-x86_64-unknown-linux-musl.tar.xz](https://github.com/ibrahimcesar/xcargo/releases/latest/download/xcargo-x86_64-unknown-linux-musl.tar.xz)
- **Windows (MSVC)**: [xcargo-x86_64-pc-windows-msvc.zip](https://github.com/ibrahimcesar/xcargo/releases/latest/download/xcargo-x86_64-pc-windows-msvc.zip)
All downloads include SHA256 checksums for verification.
See the full [Installation Guide](https://ibrahimcesar.github.io/xcargo/installation) for more options.
### Interactive Setup
The easiest way to get started is with the interactive setup wizard:
```bash
xcargo init --interactive
```
This will guide you through:
- β¨ Selecting target platforms
- βοΈ Configuring parallel builds
- π§ Setting up caching
- π³ Choosing container strategy
- π¦ Installing targets automatically
### First Build
```bash
# Build for your current platform
xcargo build
# Build for a specific target
xcargo build --target x86_64-pc-windows-gnu
# Build for all configured targets
xcargo build --all
# Release build
xcargo build --target x86_64-unknown-linux-gnu --release
```
## π‘ Usage Examples
### Basic Cross-Compilation
```bash
# Build for Windows from any platform
xcargo build --target x86_64-pc-windows-gnu
# Build for Linux ARM
xcargo build --target aarch64-unknown-linux-gnu
# Build for macOS (M1/M2)
xcargo build --target aarch64-apple-darwin
# Build for WebAssembly
xcargo build --target wasm32-unknown-unknown
# Use container for build (requires --features container)
xcargo build --target x86_64-unknown-linux-gnu --container
```
### Zero-Config Cross-Compilation with Zig
xcargo automatically detects [Zig](https://ziglang.org/) and uses it for cross-compilation when building for a different OS. No configuration needed!
```bash
# Install Zig (optional - enables native cross-compilation)
# macOS
brew install zig
# Windows
scoop install zig
# or: choco install zig
# Linux
# Download from https://ziglang.org/download/
```
**With Zig installed, cross-compilation just works:**
```bash
# On macOS or Windows, build for Linux - no Docker needed!
xcargo build --target x86_64-unknown-linux-gnu
# Output:
# βΉ Zig 0.15.2 detected, using for cross-compilation
# π‘ Cross-compiling using Zig toolchain
# β Build completed for x86_64-unknown-linux-gnu
```
**Supported targets with Zig:**
- β
`x86_64-unknown-linux-gnu`
- β
`aarch64-unknown-linux-gnu`
- β
`armv7-unknown-linux-gnueabihf`
- β οΈ `x86_64-unknown-linux-musl` (may have issues)
### Target Management
```bash
# List common cross-compilation targets
xcargo target list
# Show installed targets
xcargo target list --installed
# Get detailed info about a target
xcargo target info x86_64-pc-windows-gnu
# Add a new target
xcargo target add x86_64-unknown-linux-musl
```
### Configuration
```bash
# Show current configuration
xcargo config
# Show default configuration template
xcargo config --default
# Initialize with defaults
xcargo init
# Interactive setup wizard
xcargo init --interactive
```
## βοΈ Configuration File
Create an `xcargo.toml` in your project root:
```toml
[targets]
# Default targets to build when no target is specified
default = [
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-gnu",
]
# Per-target custom configuration
[targets."x86_64-pc-windows-gnu"]
linker = "x86_64-w64-mingw32-gcc"
[targets."x86_64-pc-windows-gnu".env]
CC = "x86_64-w64-mingw32-gcc"
[build]
# Enable parallel builds for multiple targets (2-3x faster!)
parallel = true
# Enable build caching
cache = true
# Force container usage (not yet implemented)
force_container = false
# Additional cargo flags to pass to all builds
cargo_flags = []
[container]
# Container runtime: auto, docker, podman
# Note: youki (pure Rust OCI runtime) will be supported in a future release
runtime = "auto"
# When to use containers
use_when = "target.os != host.os"
# Image pull policy
pull_policy = "if-not-present"
# Build profiles for different scenarios
[profiles.release-all]
targets = [
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-gnu",
"x86_64-apple-darwin",
"aarch64-unknown-linux-gnu",
"aarch64-apple-darwin",
]
```
## π― Supported Targets
xcargo supports all Rust targets. Common ones include:
**Linux**
- `x86_64-unknown-linux-gnu` - Linux x86_64
- `x86_64-unknown-linux-musl` - Linux x86_64 (static)
- `aarch64-unknown-linux-gnu` - Linux ARM64
**Windows**
- `x86_64-pc-windows-gnu` - Windows x86_64 (MinGW)
- `x86_64-pc-windows-msvc` - Windows x86_64 (MSVC)
**macOS**
- `x86_64-apple-darwin` - macOS x86_64
- `aarch64-apple-darwin` - macOS ARM64 (M1/M2)
**WebAssembly**
- `wasm32-unknown-unknown` - WebAssembly
Run `xcargo target list` to see all common targets with descriptions.
## π§ Linker Configuration
For successful cross-compilation, you often need to configure linkers. xcargo makes this easy:
### Windows Cross-Compilation (from macOS/Linux)
```toml
[targets."x86_64-pc-windows-gnu"]
linker = "x86_64-w64-mingw32-gcc"
[targets."x86_64-pc-windows-gnu".env]
CC = "x86_64-w64-mingw32-gcc"
AR = "x86_64-w64-mingw32-ar"
```
**Install on macOS:** `brew install mingw-w64`
**Install on Linux:** `sudo apt install mingw-w64`
### Linux Cross-Compilation (from macOS)
```toml
[targets."x86_64-unknown-linux-gnu"]
linker = "x86_64-linux-gnu-gcc"
[targets."x86_64-unknown-linux-gnu".env]
CC = "x86_64-linux-gnu-gcc"
```
**Note:** Linux cross-compilation from macOS often requires containers
### What xcargo does automatically:
- β
Verifies linker exists in PATH before building
- β
Sets `CARGO_TARGET_*_LINKER` environment variable
- β
Applies custom environment variables (`CC`, `AR`, etc.)
- β
Shows helpful errors with installation instructions if linker is missing
## π³ Container Builds
For complex cross-compilation scenarios where native toolchains are difficult to set up, xcargo supports container-based builds using Docker or Podman.
### Installation with Container Support
```bash
# Install xcargo with container feature
cargo install xcargo --features container
# Ensure you have Docker or Podman installed
docker --version # or: podman --version
```
### When to Use Containers
Container builds are ideal when:
- π Cross-compiling between different operating systems (e.g., macOS β Linux)
- π§ Native toolchains are difficult to install or configure
- π― You need reproducible builds across different development machines
- π¦ Your project has complex system dependencies
### Basic Usage
```bash
# Build using a container
xcargo build --target x86_64-unknown-linux-gnu --container
# Container builds work with all flags
xcargo build --target aarch64-unknown-linux-gnu --container --release
```
### Automatic Container Detection
Configure xcargo to automatically use containers when needed:
```toml
# xcargo.toml
[container]
# Container runtime: auto, docker, podman
runtime = "auto"
# Automatically use containers when cross-compiling to different OS
use_when = "target.os != host.os"
# Or always use containers
# use_when = "always"
# Or never use containers
# use_when = "never"
# Image pull policy: always, if-not-present, never
pull_policy = "if-not-present"
```
With this configuration, xcargo will automatically use containers when building for a different OS:
```bash
# On macOS, this will automatically use a container
xcargo build --target x86_64-unknown-linux-gnu
# On Linux, this will use native toolchain
xcargo build --target x86_64-unknown-linux-gnu
```
### Supported Container Targets
xcargo uses pre-built images from [cross-rs](https://github.com/cross-rs/cross) for these targets:
**Linux:**
- `x86_64-unknown-linux-gnu`
- `x86_64-unknown-linux-musl`
- `aarch64-unknown-linux-gnu`
- `aarch64-unknown-linux-musl`
- `armv7-unknown-linux-gnueabihf`
- `arm-unknown-linux-gnueabihf`
**Windows:**
- `x86_64-pc-windows-gnu`
**Android:**
- `aarch64-linux-android`
- `armv7-linux-androideabi`
- `x86_64-linux-android`
- `i686-linux-android`
**Note:** macOS and WebAssembly targets don't use containers:
- macOS cross-compilation requires osxcross or building on macOS
- WebAssembly builds work natively without containers
### Container Requirements
**Docker:**
```bash
# macOS
brew install --cask docker
# Or download from https://www.docker.com/products/docker-desktop
# Linux
sudo apt install docker.io # Ubuntu/Debian
sudo dnf install docker # Fedora
sudo systemctl start docker
sudo usermod -aG docker $USER # Add yourself to docker group
```
**Podman (Docker-compatible alternative):**
```bash
# macOS
brew install podman
podman machine init
podman machine start
# Linux
sudo apt install podman # Ubuntu/Debian
sudo dnf install podman # Fedora
```
### Advanced Configuration
```toml
[container]
# Prefer specific runtime
runtime = "podman"
# Custom registry for images
registry = "my-registry.com/cross-images"
# Always use containers for reproducible builds
use_when = "always"
# Per-target container configuration
[targets."x86_64-unknown-linux-gnu"]
linker = "x86_64-linux-gnu-gcc"
[targets."x86_64-unknown-linux-gnu".env]
CC = "x86_64-linux-gnu-gcc"
CUSTOM_VAR = "value"
```
### How Container Builds Work
1. **Runtime Detection** - Finds Docker or Podman on your system
2. **Image Selection** - Chooses the appropriate cross-rs image for your target
3. **Volume Mounting** - Mounts your project and cargo cache into the container
4. **Build Execution** - Runs `cargo build` inside the container
5. **Artifact Extraction** - Build artifacts appear in your local `target/` directory
```
βββββββββββββββββββββββββββββββββββ
β xcargo build --container β
ββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββ
β Detect container β
β runtime (Docker/ β
β Podman) β
βββββββββ¬ββββββββββββ
β
βΌ
βββββββββββββββββββββ
β Pull cross-rs β
β image for target β
βββββββββ¬ββββββββββββ
β
βΌ
βββββββββββββββββββββ
β Mount project & β
β cargo cache β
βββββββββ¬ββββββββββββ
β
βΌ
βββββββββββββββββββββ
β Run cargo build β
β in container β
βββββββββ¬ββββββββββββ
β
βΌ
βββββββββββββββββββββ
β Extract artifacts β
β to local target/ β
βββββββββββββββββββββ
```
### Troubleshooting
**Container runtime not found:**
```bash
# Check if Docker/Podman is installed and running
docker info
# or
podman info
```
**Permission denied errors (Linux):**
```bash
# Add your user to the docker group
sudo usermod -aG docker $USER
# Then log out and back in
```
**Image pull failures:**
```bash
# Manually pull the image
docker pull ghcr.io/cross-rs/x86_64-unknown-linux-gnu:latest
# Check your network/proxy settings
docker info | grep -i proxy
```
## π§ How It Works
1. **Target Detection** - Analyzes the target triple and determines requirements
2. **Toolchain Check** - Verifies the Rust toolchain and target are installed
3. **Auto-Installation** - Installs missing components via rustup
4. **Smart Building** - Uses native builds when possible, suggests containers when needed
5. **Helpful Output** - Shows tips, hints, and next steps
```
ββββββββββββββββββββββββββββββββ
β xcargo build --target linux β
ββββββββββββ¬ββββββββββββββββββββ
β
βΌ
βββββββββββββββββ
β Detect target β
β requirements β
βββββββββ¬ββββββββ
β
βΌ
ββββββββββββββββββ
β Check toolchainβ
β & install if β
β missing β
βββββββββ¬βββββββββ
β
βΌ
ββββββββββββββββββ
β Execute cargo β
β build with β
β proper flags β
ββββββββββββββββββ
```
## π€ CI/CD Integration
### GitHub Actions
```yaml
name: Cross-Platform Build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install xcargo
run: cargo install xcargo
- name: Build for all targets
run: xcargo build --all
```
### GitLab CI
```yaml
build:
image: rust:latest
script:
- cargo install xcargo
- xcargo build --all
artifacts:
paths:
- target/*/release/*
```
## π¨ Beautiful Output
xcargo provides helpful, colored output with tips and hints:
```
β¨ xcargo Interactive Setup
Let's configure cross-compilation for your project!
β Detected host platform: aarch64-apple-darwin
? Which targets do you want to build for?
ββ to navigate, Space to select, Enter to confirm
[ ] Linux x86_64
[β] Windows x86_64 (GNU)
[β] macOS ARM64 (M1/M2)
β Configuration created successfully!
π Configuration Summary
ββββββββββββββββββββββββ
Targets: x86_64-pc-windows-gnu, aarch64-apple-darwin
Parallel builds: enabled
Build cache: enabled
Container strategy: target.os != host.os
π‘ Tip: Run 'xcargo build' to build for your host platform
π‘ Tip: Run 'xcargo build --all' to build for all configured targets
```
## π Status
**Current Version:** 0.2.0
β
**Working Features:**
- Target detection and validation
- Toolchain management via rustup
- Basic cross-compilation
- Configuration system (xcargo.toml)
- Interactive TUI setup wizard
- Beautiful colored output with tips
- Self-building capability (xcargo builds itself!)
- **Parallel target compilation** (2-3x speedup with `parallel = true`)
- **Linker configuration** (automatic CARGO_TARGET_*_LINKER setup)
- **Container builds** (Docker/Podman integration with `--features container`)
- Smart error messages with platform-specific help
- GitHub Actions CI/CD integration
π§ **Planned Features:**
- **Bundled cross-compilation toolchains** - Zero-dependency builds without Docker (download minimal toolchains on-demand)
- Pure Rust OCI runtime (youki integration) as optional feature
- Native dependency management
- Build caching improvements
- Custom container image support
## πΊοΈ Roadmap
### Phase 1: Core Cross-Compilation (v0.1-0.2) β
- β
Target detection and validation
- β
Toolchain management via rustup
- β
Configuration system (xcargo.toml)
- β
Interactive TUI setup wizard
- β
Parallel builds for 2-3x speedup
- β
Linker configuration
- β
Container builds (Docker/Podman)
- β
Binary signing (minisign)
### Phase 2: Zero-Dependency Builds (v0.3) π§
**Goal:** Make cross-compilation work out of the box with zero external dependencies.
- [ ] **Bundled toolchain system**
- Download minimal cross-compilation toolchains on-demand (~20-50MB per target)
- Cache in `~/.xcargo/toolchains/`
- No Docker, no manual toolchain installation required
- Fallback to containers for complex targets
- [ ] Build and host pre-compiled toolchains for tier 1 targets
- [ ] Automatic toolchain updates
**Trade-offs:**
- β
Better UX: Just works, no setup needed
- β
Smaller downloads: 20-50MB vs 500MB+ containers
- β
Offline-friendly: Works after first download
- β οΈ More complexity: Need to build/maintain toolchains
- β οΈ Hosting costs: Bandwidth for toolchain downloads
### Phase 3: Enhanced Security & Distribution (v0.4)
**Platform-Specific Code Signing** π―
Currently, xcargo binaries are signed with **minisign** (free, cross-platform). For enhanced platform integration, we're considering:
**macOS Code Signing:**
- **What:** Sign with Apple Developer certificate, enable Gatekeeper
- **Benefit:** Better macOS user experience, no "unidentified developer" warnings
- **Cost:** $99/year Apple Developer Program
- **Status:** Planned, pending community interest
**Windows Authenticode:**
- **What:** Sign with code signing certificate, satisfy SmartScreen
- **Benefit:** Better Windows user experience, no security warnings
- **Cost:** $100-500/year for certificate
- **Status:** Planned, pending community interest
**Want platform-specific signing?**
- π React to [#123](https://github.com/ibrahimcesar/xcargo/issues/123) if you want macOS signing
- π React to [#124](https://github.com/ibrahimcesar/xcargo/issues/124) if you want Windows signing
- π¬ Share your use case in the issues
> **Note:** Platform signing requires paid certificates. We'll implement these features when there's sufficient community interest to justify the ongoing costs. Minisign signatures will always be provided as a free, cross-platform verification method.
**Other v0.4 features:**
- [ ] `xcargo sign` - Help users sign their own binaries
- [ ] Native dependency detection and management
- [ ] Advanced build caching
- [ ] Build profiles and presets
### Phase 4: Advanced Features (v0.5+)
- [ ] youki integration (pure Rust OCI runtime)
- [ ] Custom toolchain registry
- [ ] Build reproducibility guarantees
- [ ] SBOM (Software Bill of Materials) generation
- [ ] Integration with cargo-dist
- [ ] Plugin system for custom targets
### Community-Driven Priorities
We prioritize features based on community feedback. Share your needs:
- π [Report bugs](https://github.com/ibrahimcesar/xcargo/issues/new?template=bug_report.md)
- π‘ [Request features](https://github.com/ibrahimcesar/xcargo/issues/new?template=feature_request.md)
- π¬ [Join discussions](https://github.com/ibrahimcesar/xcargo/discussions)
## π Comparison
| Feature | xcargo | cross | cargo-zigbuild |
|---------|--------|-------|----------------|
| **Native-first** | β
| β | β οΈ Via Zig |
| **Auto-install targets** | β
| β | β |
| **Interactive setup** | β
| β | β |
| **Parallel builds** | β
| β | β |
| **Beautiful output** | β
| β οΈ | β οΈ |
| **Configuration file** | β
| β
| β |
| **Container support** | β
| β
| β |
| **Zero config** | β
| β | β οΈ |
## π€ Contributing
Contributions are welcome! This is an early-stage project with lots of opportunity to help.
**Ways to contribute:**
- π Report bugs and suggest features via [GitHub Issues](https://github.com/ibrahimcesar/xcargo/issues)
- π» Submit pull requests for fixes or new features
- π Improve documentation
- π― Test on different platforms and targets
- β Star the repo to show support!
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
## π Documentation
- [Full Documentation](https://ibrahimcesar.github.io/xcargo)
- [API Documentation](https://docs.rs/xcargo)
- [Configuration Reference](https://ibrahimcesar.github.io/xcargo/docs/reference/configuration)
- [Target Guide](https://ibrahimcesar.github.io/xcargo/docs/guides/target-management)
- [Container Security Guide](docs/guides/container-security.md) - π Best practices for secure builds
## π Security
xcargo is built with security in mind:
- β
**Memory safe** - Written in Rust with zero unsafe code
- β
**Input validation** - All inputs are validated and sanitized
- β
**No shell execution** - Direct process execution prevents injection attacks
- β
**Audited dependencies** - All dependencies are regularly scanned
- β
**Security evaluation** - Comprehensive security review completed for v1.0.0
**Security resources:**
- [Security Policy](SECURITY.md) - Vulnerability reporting process
- [Security Evaluation](.github/SECURITY_EVALUATION.md) - Detailed security analysis
- [Container Security Guide](docs/guides/container-security.md) - Secure container builds
**Report security issues:** security@xcargo.dev or via [GitHub Security Advisories](https://github.com/ibrahimcesar/xcargo/security/advisories)
## π License
[MIT](./LICENSE) Β© Ibrahim Cesar
## π Acknowledgments
Inspired by excellent tools in the Rust ecosystem:
- [cross](https://github.com/cross-rs/cross) - Container-based cross-compilation
- [cargo-zigbuild](https://github.com/rust-cross/cargo-zigbuild) - Zig linker approach
- [rustup](https://rustup.rs/) - Rust toolchain management
---
**xcargo** - *Cross-compilation, zero friction* π―
Made with β€οΈ by [Ibrahim Cesar](https://github.com/ibrahimcesar)
[β Star on GitHub](https://github.com/ibrahimcesar/xcargo) | [π¦ View on crates.io](https://crates.io/crates/xcargo) | [π Read the Docs](https://ibrahimcesar.github.io/xcargo)