Skip to content

ci: improve cross-compilation and package building #16

ci: improve cross-compilation and package building

ci: improve cross-compilation and package building #16

Workflow file for this run

name: CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_call:
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
RUST_BACKTRACE: short
PKG_CONFIG_ALLOW_CROSS: 1
jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libudev-dev pkg-config
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Check formatting
run: cargo fmt --all -- --check
- name: Check clippy
run: cargo clippy -- -D warnings
- name: Run tests
run: cargo test --all-features
build-linux:
name: Build Linux
needs: check
runs-on: ubuntu-latest
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- armv7-unknown-linux-gnueabihf
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
uses: taiki-e/install-action@cross
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ matrix.target }}-
- name: Cache cross
uses: actions/cache@v3
if: matrix.target != 'x86_64-unknown-linux-gnu'
with:
path: ~/.cargo/.cross
key: ${{ runner.os }}-cross-${{ matrix.target }}-${{ hashFiles('Cross.toml') }}
restore-keys: |
${{ runner.os }}-cross-${{ matrix.target }}-
- name: Install system dependencies
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
sudo apt-get update && \
sudo apt-get install -y libudev-dev
- name: Build
run: |
if [ "${{ matrix.target }}" = "x86_64-unknown-linux-gnu" ]; then
cargo build --release --target ${{ matrix.target }}
else
cross build --release --target ${{ matrix.target }}
fi