Skip to content

Workflow file for this run

permissions:
contents: write
name: Build Rust project on multiple platforms when a new release is created
on:
release:
types: [created]
jobs:
build-windows:
runs-on: windows-latest
env:
FILE_NAME: nethsm-pkcs11-v${{ github.event.release.tag_name }}-x86_64-windows.dll
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable-x86_64-pc-windows-msvc
- uses: Swatinem/rust-cache@v2
- name: Build project
run: cargo build --release
- name: rename file
run: mv target/release/nethsm_pkcs11.dll ${{ env.FILE_NAME }}
- name: Upload to the release
uses: softprops/action-gh-release@v1
with:
files: ${{ env.FILE_NAME }}
build-macos:
runs-on: macos-latest
env:
FILE_NAME: nethsm-pkcs11-v${{ github.event.release.tag_name }}-x86_64-macos.dylib
FILE_NAME_ARM: nethsm-pkcs11-v${{ github.event.release.tag_name }}-aarch64-macos.dylib
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable-x86_64-apple-darwin
target: aarch64-apple-darwin
- uses: Swatinem/rust-cache@v2
- name: Build project for MacOs aaarch64
run: cargo build --release --target aarch64-apple-darwin
- name: Build project
run: cargo build --release
- name: rename file
run: mv target/release/libnethsm_pkcs11.dylib ${{ env.FILE_NAME }}
- name: rename file arm
run: mv target/aarch64-apple-darwin/release/libnethsm_pkcs11.dylib ${{ env.FILE_NAME_ARM }}
- name: Upload to the release
uses: softprops/action-gh-release@v1
with:
files: |
${{ env.FILE_NAME }}
${{ env.FILE_NAME_ARM }}
build-linux:
runs-on: ubuntu-latest
container:
image: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu:22.04", "debian:12", "fedora:38", "alpine:3.18", "fedora:39"]
rust-version: [stable]
env:
FILE_NAME: nethsm-pkcs11-v${{ github.event.release.tag_name }}-x86_64-${{ matrix.os }}.so
HOME: /root
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: install dependencies
run: |
case ${{matrix.os}} in
ubuntu* | debian* )
apt-get update
apt-get install -y curl gcc
;;
alpine*)
apk add curl musl-dev gcc
echo RUSTFLAGS="-C target-feature=-crt-static" >> $GITHUB_ENV
;;
fedora*)
dnf install -y curl gcc
;;
esac
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust-version }}
- uses: Swatinem/rust-cache@v2
- name: Build project
run: cargo build --release
- name: rename file
run: mv target/release/libnethsm_pkcs11.so ${{ env.FILE_NAME }}
- name: Upload to the release
uses: softprops/action-gh-release@v1
with:
files: ${{ env.FILE_NAME }}
cross-build-linux:
runs-on: ubuntu-latest
name: Build on ${{ matrix.distro }} ${{ matrix.arch }}
strategy:
matrix:
include:
- arch: aarch64
distro: bullseye
target: aarch64-unknown-linux-gnu
- arch: aarch64
distro: ubuntu22.04
target: aarch64-unknown-linux-gnu
- arch: aarch64
distro: alpine_latest
target: aarch64-unknown-linux-musl
# Not supported by ring
# - arch: riscv64
# distro: ubuntu22.04
# target: riscv64gc-unknown-linux-gnu
env:
FILE_NAME: nethsm-pkcs11-v${{ github.event.release.tag_name }}-${{ matrix.arch }}-${{ matrix.distro }}.so
steps:
- uses: actions/checkout@v3
- uses: uraimo/run-on-arch-action@v2
name: Build artifact
id: build
with:
githubToken: ${{ github.token }}
arch: ${{ matrix.arch }}
distro: ${{ matrix.distro }}
setup: |
mkdir -p "${PWD}/artifacts"
dockerRunArgs: |
--volume "${PWD}/artifacts:/artifacts"
env: |
FILE_NAME: "${{env.FILE_NAME}}"
TARGET: "${{ matrix.target }}"
RUSTFLAGS: "-C target-feature=-crt-static"
shell: /bin/sh
install: |
case ${{matrix.distro}} in
ubuntu* | bullseye )
apt-get update
apt-get install -y curl gcc
;;
alpine*)
apk add curl musl-dev gcc
;;
esac
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
. $HOME/.cargo/env
rustup target add ${{ matrix.target }}
run: |
. $HOME/.cargo/env
cargo build --release --target ${{ matrix.target }}
mv target/${{ matrix.target }}/release/libnethsm_pkcs11.so /artifacts/${{env.FILE_NAME}}
- uses: softprops/action-gh-release@v1
with:
files: artifacts/${{ env.FILE_NAME }}
upload-licenses:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: install cargo-license
run: cargo install cargo-license
- name: Generate licenses
run: ./tools/collect_licenses.sh
- name: rename file
run: mv _LICENSE LICENSE
- name: Upload to the release
uses: softprops/action-gh-release@v1
with:
files: LICENSE