Complete guide for building Windows binaries from Linux.
cargo build --target x86_64-pc-windows-gnu --release✅ Benefits:
- Works out-of-the-box on Linux
- MinGW toolchain (already installed on most systems)
- Fully compatible with all Windows systems
- Simpler setup, no extra tools needed
cargo build --target x86_64-pc-windows-msvc --release✅ Benefits:
- Native Windows compilation
- Slightly smaller binaries
- Maximum Windows compatibility
- Install Rust Windows target:
rustup target add x86_64-pc-windows-gnu- Install MinGW (if not already installed):
Fedora/RHEL:
sudo dnf install mingw64-gcc mingw64-winpthreads-staticUbuntu/Debian:
sudo apt install gcc-mingw-w64-x86-64Arch:
sudo pacman -S mingw-w64-gcccargo build --target x86_64-pc-windows-gnu --releaseOutput: target/x86_64-pc-windows-gnu/release/paddle_decoder.exe
- Install Rust: https://rustup.rs
- Install Visual Studio Build Tools with "Desktop development with C++"
cargo build --target x86_64-pc-windows-msvc --releaseOr simply:
cargo build --releaseOutput: target/release/paddle_decoder.exe
cargo build --releaseRequires osxcross toolchain:
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
# Additional osxcross setup requiredCreate build_all.sh for building all platforms:
#!/bin/bash
echo "🚀 Building for all platforms..."
echo ""
# Linux (native)
echo "🐧 Building Linux binary..."
cargo build --release
echo "✅ Linux: target/release/paddle_decoder"
echo ""
# Windows (cross-compile)
echo "🪟 Building Windows binary..."
cargo build --target x86_64-pc-windows-gnu --release
echo "✅ Windows: target/x86_64-pc-windows-gnu/release/paddle_decoder.exe"
echo ""
# Create distribution folder
mkdir -p dist
cp target/release/paddle_decoder dist/paddle_decoder-linux
cp target/x86_64-pc-windows-gnu/release/paddle_decoder.exe dist/
echo ""
echo "📊 Build Summary:"
ls -lh dist/
echo ""
echo "✨ All builds complete!"Make it executable:
chmod +x build_all.sh
./build_all.shProblem: Trying to use MSVC target on Linux
Solution: Use GNU target instead:
# ❌ This won't work on Linux:
cargo build --target x86_64-pc-windows-msvc --release
# ✅ Use this instead:
cargo build --target x86_64-pc-windows-gnu --releaseProblem: Missing winapi features
Solution: Already fixed in Cargo.toml with:
[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["winuser", "windef", "shellapi", "wincon"] }Check if installed:
which x86_64-w64-mingw32-gccInstall if missing:
# Fedora/RHEL
sudo dnf install mingw64-gcc
# Ubuntu/Debian
sudo apt install gcc-mingw-w64-x86-64| Platform | Command | Output |
|---|---|---|
| Linux → Linux | cargo build --release |
target/release/paddle_decoder |
| Linux → Windows | cargo build --target x86_64-pc-windows-gnu --release |
target/x86_64-pc-windows-gnu/release/paddle_decoder.exe |
| Windows → Windows | cargo build --release |
target/release/paddle_decoder.exe |
| macOS → macOS | cargo build --release |
target/release/paddle_decoder |
Example .github/workflows/build.yml:
name: Build
on: [push, pull_request]
jobs:
build:
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact: paddle_decoder-linux
- os: ubuntu-latest
target: x86_64-pc-windows-gnu
artifact: paddle_decoder.exe
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact: paddle_decoder.exe
- os: macos-latest
target: x86_64-apple-darwin
artifact: paddle_decoder-macos-intel
- os: macos-latest
target: aarch64-apple-darwin
artifact: paddle_decoder-macos-arm64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install MinGW (Linux cross-compile to Windows)
if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64-pc-windows-gnu'
run: sudo apt-get install -y gcc-mingw-w64-x86-64
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: |
target/${{ matrix.target }}/release/paddle_decoder
target/${{ matrix.target }}/release/paddle_decoder.exeFor daily development on Linux:
# Build Windows binary
cargo build --target x86_64-pc-windows-gnu --release
# Build Linux binary
cargo build --releaseThe GNU target works perfectly on Windows and is the standard cross-compilation method from Linux!
BUILD_LINUX.md- Native Linux buildingBUILD_WINDOWS.md- Native Windows buildingBUILD_MACOS.md- Native macOS buildingREADME.md- Project overview
73! 📻