name: Rust
on:
push:
branches:
- "main"
pull_request:
branches:
- "main"
- "dev"
- "hotfix/**"
env:
CARGO_TERM_COLOR: always
jobs:
building:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Build
run: cargo build --verbose --all-features
- name: Cache dependencies
uses: actions/cache@v5
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-deps-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-deps-
linting:
runs-on: ubuntu-latest
needs: [building]
steps:
- uses: actions/checkout@v6
- name: Cache dependencies
uses: actions/cache@v5
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-deps-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-deps-
- name: Cache nightly toolchain
id: cache-nightly-toolchain
uses: actions/cache@v5
with:
path: ~/.rustup/toolchains/nightly-*
key: ${{ runner.os }}-rustup-nightly-toolchain-${{ hashFiles('~/.rustup/toolchains/nightly-*') }}
restore-keys: ${{ runner.os }}-rustup-nightly-toolchain-
- if: ${{ steps.cache-nightly-toolchain.outputs.cache-hit != 'true' }}
name: Install nightly toolchain
run: rustup toolchain install --no-self-update -c rustfmt nightly
- name: Format check
run: cargo xtask fmt-check
docs:
runs-on: ubuntu-latest
needs: [building]
steps:
- uses: actions/checkout@v6
- name: Cache dependencies
uses: actions/cache@v5
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-deps-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-deps-
- name: Check docs
run: |
cargo doc --message-format json-diagnostic-short \
| jq -se 'any(.[]; .reason == "compiler-message" and (.message.level == "warning" or .message.level == "error")) | not'
testing:
runs-on: ubuntu-latest
needs: [building]
steps:
- uses: actions/checkout@v6
- name: Cache dependencies
uses: actions/cache@v5
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-deps-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-deps-
- name: Run tests
run: cargo test -q --all-features --jobs 6
code_coverage:
runs-on: ubuntu-latest
needs: [building]
steps:
- uses: actions/checkout@v6
- name: Store active toolchain
run: echo "ACTIVE_RUST_TOOLCHAIN=$(rustup show active-toolchain | sed 's/ .*$//')" >> $GITHUB_ENV
- name: Store active target
run: echo "ACTIVE_RUST_TARGET=$(echo "${{ env.ACTIVE_RUST_TOOLCHAIN }}" | sed 's/^[^-]\+-//')" >> $GITHUB_ENV
- name: Create .local/bin
run: mkdir -p "$HOME/.local/bin"
- name: Cache dependencies
uses: actions/cache@v5
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-deps-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-deps-
- name: Cache llvm-tools component
uses: actions/cache@v5
id: cache-llvm-tools
env:
RUSTUP_LLC_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/llc
RUSTUP_LLVM_AR_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/llvm-ar
RUSTUP_LLVM_AS_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/llvm-as
RUSTUP_LLVM_COV_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/llvm-cov
RUSTUP_LLVM_DIS_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/llvm-dis
RUSTUP_LLVM_LINK_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/llvm-link
RUSTUP_LLVM_NM_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/llvm-nm
RUSTUP_LLVM_OBJCOPY_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/llvm-objcopy
RUSTUP_LLVM_OBJDUMP_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/llvm-objdump
RUSTUP_LLVM_PROFDATA_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/llvm-profdata
RUSTUP_LLVM_READOBJ_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/llvm-readobj
RUSTUP_LLVM_SIZE_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/llvm-size
RUSTUP_LLVM_STRIP_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/llvm-strip
RUSTUP_OPT_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/bin/opt
RUSTUP_LIBLLVM_LOCATION: ~/.rustup/${{ env.ACTIVE_RUST_TOOLCHAIN }}/lib/rustlib/${{ env.ACTIVE_RUST_TARGET }}/lib/libLLVM-*
with:
path: |
${{ env.RUSTUP_LLC_LOCATION }}
${{ env.RUSTUP_LLVM_AR_LOCATION }}
${{ env.RUSTUP_LLVM_AS_LOCATION }}
${{ env.RUSTUP_LLVM_COV_LOCATION }}
${{ env.RUSTUP_LLVM_DIS_LOCATION }}
${{ env.RUSTUP_LLVM_LINK_LOCATION }}
${{ env.RUSTUP_LLVM_NM_LOCATION }}
${{ env.RUSTUP_LLVM_OBJCOPY_LOCATION }}
${{ env.RUSTUP_LLVM_OBJDUMP_LOCATION }}
${{ env.RUSTUP_LLVM_PROFDATA_LOCATION }}
${{ env.RUSTUP_LLVM_READOBJ_LOCATION }}
${{ env.RUSTUP_LLVM_SIZE_LOCATION }}
${{ env.RUSTUP_LLVM_STRIP_LOCATION }}
${{ env.RUSTUP_OPT_LOCATION }}
${{ env.RUSTUP_LIBLLVM_LOCATION }}
key: >-
${{ runner.os }}-cache-llvm-tools-${{ hashFiles(
env.RUSTUP_LLC_LOCATION,
env.RUSTUP_LLVM_AR_LOCATION,
env.RUSTUP_LLVM_AS_LOCATION,
env.RUSTUP_LLVM_COV_LOCATION,
env.RUSTUP_LLVM_DIS_LOCATION,
env.RUSTUP_LLVM_LINK_LOCATION,
env.RUSTUP_LLVM_NM_LOCATION,
env.RUSTUP_LLVM_OBJCOPY_LOCATION,
env.RUSTUP_LLVM_OBJDUMP_LOCATION,
env.RUSTUP_LLVM_PROFDATA_LOCATION,
env.RUSTUP_LLVM_READOBJ_LOCATION,
env.RUSTUP_LLVM_SIZE_LOCATION,
env.RUSTUP_LLVM_STRIP_LOCATION,
env.RUSTUP_OPT_LOCATION,
env.RUSTUP_LIBLLVM_LOCATION
) }}
restore-keys: ${{ runner.os }}-cache-llvm-tools-
- if: ${{ steps.cache-llvm-tools.outputs.cache-hit != 'true' }}
name: Install llvm-tools component
run: rustup component add llvm-tools
- name: Cache grcov
uses: actions/cache@v5
id: cache-grcov
with:
path: $HOME/.local/bin/grcov-*
key: ${{ runner.os }}-cache-grcov-${{ hashFiles('${{ env.HOME }}/.local/bin/grcov-*') }}
restore-keys: ${{ runner.os }}-cache-grcov-
- if: ${{ steps.cache-grcov.outputs.cache-hit != 'true' }}
name: Install grcov
run: |
curl -sL https://github.com/mozilla/grcov/releases/latest/download/grcov-x86_64-unknown-linux-gnu.tar.bz2 \
| tar jxf - -C "$HOME/.local/bin"
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Coverage
run: cargo xtask coverage
- name: Upload code coverage report artifact
uses: actions/upload-artifact@v6
with:
name: code coverage report
path: target/coverage/html/
retention-days: 7