Integrate RustlerPrecompiled for Precompiled NIFs & CI/CD Enhancements #3
Workflow file for this run
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 Precompiled NIFs | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "native/**" | |
- ".github/workflows/release.yml" | |
tags: | |
- "*" | |
pull_request: | |
paths: | |
- ".github/workflows/release.yml" | |
workflow_dispatch: | |
jobs: | |
build_release: | |
name: NIF ${{ matrix.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }}) | |
runs-on: ${{ matrix.job.os }} | |
permissions: | |
contents: write | |
id-token: write | |
attestations: write | |
strategy: | |
fail-fast: false | |
matrix: | |
nif: ["2.16"] # Only build for OTP 26 and 27 | |
job: | |
- { target: aarch64-apple-darwin, os: macos-13 } | |
- { target: aarch64-unknown-linux-gnu, os: ubuntu-22.04, use-cross: true } | |
- { target: x86_64-apple-darwin, os: macos-13 } | |
- { target: x86_64-unknown-linux-gnu, os: ubuntu-22.04 } | |
env: | |
EXSTATIC_BUILD: true # Ensure RustlerPrecompiled forces a build | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
toolchain: stable | |
targets: ${{ matrix.job.target }} | |
- name: Install Cross for cross-compilation (if needed) | |
if: ${{ matrix.job.use-cross }} | |
run: cargo install cross --git https://github.com/cross-rs/cross | |
- name: Extract project version | |
shell: bash | |
run: | | |
echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' mix.exs | head -n1)" >> $GITHUB_ENV | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
prefix-key: v0-precomp | |
shared-key: ${{ matrix.job.target }}-${{ matrix.nif }} | |
workspaces: | | |
native/exstatic | |
- name: Build the project | |
id: build-crate | |
uses: philss/rustler-precompiled-action@v1.1.4 | |
with: | |
project-name: exstatic | |
project-version: ${{ env.PROJECT_VERSION }} | |
target: ${{ matrix.job.target }} | |
nif-version: ${{ matrix.nif }} | |
use-cross: ${{ matrix.job.use-cross }} | |
project-dir: "native/exstatic" | |
- name: Artifact attestation (security verification) | |
uses: actions/attest-build-provenance@v1 | |
with: | |
subject-path: ${{ steps.build-crate.outputs.file-path }} | |
- name: Upload NIF artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ steps.build-crate.outputs.file-name }} | |
path: ${{ steps.build-crate.outputs.file-path }} | |
- name: Publish to GitHub Releases | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: | | |
${{ steps.build-crate.outputs.file-path }} | |
if: startsWith(github.ref, 'refs/tags/') |