Skip to content

Instantly share code, notes, and snippets.

@reticivis-net
Created August 6, 2024 02:09
Show Gist options
  • Save reticivis-net/bfbd3e398e96e2327a891faa6ebf6eb0 to your computer and use it in GitHub Desktop.
Save reticivis-net/bfbd3e398e96e2327a891faa6ebf6eb0 to your computer and use it in GitHub Desktop.
easy Rust cross-platform compiling for github actions
name: Build
on:
workflow_dispatch:
jobs:
release:
name: Release - ${{ matrix.platform.release_for }}
strategy:
matrix:
platform:
- release_for: Linux-x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
bin: ${{ github.event.repository.name }}
name: ${{ github.event.repository.name }}-x86_64-unknown-linux-gnu
command: build
- release_for: Linux-ARM
os: ubuntu-latest
target: aarch64-unknown-linux-gnu
bin: ${{ github.event.repository.name }}
name: ${{ github.event.repository.name }}-aarch64-unknown-linux-gnu
command: build
- release_for: Windows-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
bin: ${{ github.event.repository.name }}.exe
name: ${{ github.event.repository.name }}-x86_64-pc-windows-msvc.exe
command: build
# uncomment for windows for ARM, not all crates support this
# - release_for: Windows-ARM
# os: windows-latest
# target: aarch64-pc-windows-msvc
# bin: ${{ github.event.repository.name }}.exe
# name: ${{ github.event.repository.name }}-aarch64-pc-windows-msvc.exe
# command: build
- release_for: macOS-x86_64
os: macOS-latest
target: x86_64-apple-darwin
bin: ${{ github.event.repository.name }}
name: ${{ github.event.repository.name }}-x86_64-apple-darwin
command: build
- release_for: macOS-ARM
os: macOS-latest
target: aarch64-apple-darwin
bin: ${{ github.event.repository.name }}
name: ${{ github.event.repository.name }}-aarch64-apple-darwin
command: build
# more release targets here ...
runs-on: ${{ matrix.platform.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.platform.target }} # not sure if this is necessary but it makes me sleep at night
- name: Build binary
uses: houseabsolute/actions-rust-cross@v0
with:
command: ${{ matrix.platform.command }}
target: ${{ matrix.platform.target }}
args: "--locked --release"
strip: true
toolchain: nightly
- name: Publish release artifacts
uses: actions/upload-artifact@v4
with:
# github forces these to be a zip which is dumb but whatever might as well embrace it,,,
name: ${{ matrix.platform.name }}
path: "./target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}"
# compression-level: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment