Allow cross with Zig #20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build, test and release | |
on: push | |
jobs: | |
build: | |
name: Build and test | |
strategy: | |
fail-fast: false | |
matrix: | |
job: | |
- { target: x86_64-unknown-linux-musl, binary_name: linux-amd64, os: ubuntu-latest } | |
- { target: x86_64-apple-darwin, binary_name: darwin-amd64, os: macos-latest } | |
- { target: x86_64-pc-windows-msvc, binary_name: windows-amd64.exe, os: windows-latest } | |
runs-on: ${{ matrix.job.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install libudev-dev | |
run: sudo apt-get update && sudo apt-get install libudev-dev musl-tools linux-libc-dev | |
if: matrix.job.os == 'ubuntu-latest' | |
- name: Setup Zig | |
uses: goto-bus-stop/setup-zig@v2 | |
with: | |
version: '0.11.0' | |
- name: Cache Rust dependencies | |
uses: actions/[email protected] | |
with: | |
path: target | |
key: ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
${{ runner.OS }}-build- | |
- name: Install latest Rust nightly | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
components: rustc, cargo | |
toolchain: 1.71.0 | |
override: true | |
target: ${{ matrix.job.target }} | |
- name: Install cargo-zigbuild | |
run: cargo install cargo-zigbuild | |
- name: Build with Zigbuild | |
run: cargo zigbuild --release --target=${{ matrix.job.target }} | |
if: matrix.job.os == 'ubuntu-latest' | |
env: | |
PKG_CONFIG_ALLOW_CROSS: 1 | |
- name: Run cargo build --release | |
uses: actions-rs/cargo@v1 | |
if: matrix.job.os != 'ubuntu-latest' | |
with: | |
args: --release --target=${{ matrix.job.target }} | |
command: build | |
- name: Rename binary to use structured filename | |
run: | | |
rm target/${{ matrix.job.target }}/release/litra.d | |
cp target/${{ matrix.job.target }}/release/litra* litra_${{ github.ref_name }}_${{ matrix.job.binary_name }} | |
- name: Upload binary as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
path: litra_${{ github.ref_name }}_${{ matrix.job.binary_name }} | |
name: litra_${{ github.ref_name }}_${{ matrix.job.binary_name }} | |
release: | |
name: Create release with binary assets | |
runs-on: ubuntu-latest | |
needs: build | |
if: startsWith(github.event.ref, 'refs/tags/v') | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
name: litra_${{ github.ref_name }}_linux-amd64 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: litra_${{ github.ref_name }}_darwin-amd64 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: litra_${{ github.ref_name }}_windows-amd64.exe | |
- name: Create release | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: | | |
litra_${{ github.ref_name }}_windows-amd64.exe | |
litra_${{ github.ref_name }}_darwin-amd64 | |
litra_${{ github.ref_name }}_linux-amd64 |