name: build-rust-binaries
on:
push:
branches: ["main", "master"]
tags: ["v*"]
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- name: linux-x86_64
runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
bin: todo
archive: todo-linux-x86_64.tar.gz
- name: linux-arm64
runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
bin: todo
archive: todo-linux-arm64.tar.gz
- name: windows-x86_64
runner: windows-latest
target: x86_64-pc-windows-msvc
bin: todo.exe
archive: todo-windows-x86_64.zip
- name: macos-x86_64
runner: macos-15-intel
target: x86_64-apple-darwin
bin: todo
archive: todo-macos-x86_64.tar.gz
- name: macos-arm64
runner: macos-latest
target: aarch64-apple-darwin
bin: todo
archive: todo-macos-arm64.tar.gz
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo registry + target
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.target }}-cargo-
- name: Install Linux deps
if: startsWith(matrix.runner, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libssl-dev
- name: Build
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Package (Linux/macOS)
if: runner.os != 'Windows'
run: |
mkdir -p package
cp target/${{ matrix.target }}/release/${{ matrix.bin }} package/${{ matrix.bin }}
tar -C package -czf ${{ matrix.archive }} ${{ matrix.bin }}
- name: Package (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path package | Out-Null
Copy-Item "target/${{ matrix.target }}/release/${{ matrix.bin }}" "package/${{ matrix.bin }}"
Compress-Archive -Path "package/${{ matrix.bin }}" -DestinationPath "${{ matrix.archive }}" -Force
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.archive }}
path: ${{ matrix.archive }}
if-no-files-found: error