Skip to content

ci: add Miri (unsafe paths) and AddressSanitizer (vcamera) lanes #12

ci: add Miri (unsafe paths) and AddressSanitizer (vcamera) lanes

ci: add Miri (unsafe paths) and AddressSanitizer (vcamera) lanes #12

Workflow file for this run

name: CI
on:
push:
branches: [main]
pull_request:
# Cancel superseded runs on the same ref.
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
lint:
name: fmt + clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install libgphoto2 + libclang
run: |
sudo apt-get update
sudo apt-get install -y libgphoto2-dev pkg-config clang libclang-dev
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --all --check
- run: cargo clippy --workspace --all-targets -- -D warnings
# Full suite (incl. the Directory-Browse virtual-camera integration tests,
# which need the `directory` camlib + `disk` iolib shipped on these platforms).
test:
name: test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Install libgphoto2 (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libgphoto2-dev pkg-config clang libclang-dev
- name: Install libgphoto2 (macOS)
if: runner.os == 'macOS'
run: brew install libgphoto2 pkgconf
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build (default features = build-time bindgen)
run: cargo build --workspace --all-targets
- name: Test
run: cargo test --workspace --all-targets
- name: Test (log feature)
run: cargo test -p gphoto2 --features log
- name: Doc tests
run: cargo test --workspace --doc
- name: Verify committed-bindings path also builds
run: cargo build --workspace --no-default-features
# libgphoto2 has no MSVC port, so Windows support is via the GNU toolchain in
# MSYS2/MinGW. We build everything and run the unit tests (which exercise the
# core FFI: errors, strings, version, widget tree). The virtual-camera
# integration tests need camlibs/iolibs that aren't reliably packaged for
# Windows, so they run on Linux/macOS above.
windows:
name: test (windows / mingw64)
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v4
- uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: >-
mingw-w64-x86_64-libgphoto2
mingw-w64-x86_64-pkgconf
mingw-w64-x86_64-rust
- name: Versions
run: |
cargo --version
pkg-config --modversion libgphoto2
- name: Build (committed bindings; no libclang needed)
run: cargo build --workspace --all-targets --no-default-features
- name: Unit tests
run: cargo test --workspace --lib --no-default-features
# Build libgphoto2 from the vendored source with its virtual PTP camera
# (--enable-vusb + ptp2) and run the vcamera tests against it. This is the only
# way to cover capture / config tree / events without real hardware.
vcamera:
name: vcamera (virtual PTP)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install build deps
run: |
sudo apt-get update
sudo apt-get install -y ninja-build libltdl-dev pkg-config gettext clang libclang-dev
# apt's meson is too old for libgphoto2 (needs >= 1.4.0); use pipx.
pipx install meson
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build vusb libgphoto2 + run vcamera tests
run: ./scripts/run-vcamera-tests.sh
# Run Miri (Stacked Borrows) over the pure-unsafe code — callback trampolines,
# event-data malloc/free, string marshalling, ABI guards. Tests that call into
# libgphoto2 are excluded via cfg(miri), since Miri can't execute FFI.
miri:
name: miri (unsafe paths)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install libgphoto2 + libclang
run: |
sudo apt-get update
sudo apt-get install -y libgphoto2-dev pkg-config clang libclang-dev
- uses: dtolnay/rust-toolchain@nightly
with:
components: miri
- uses: Swatinem/rust-cache@v2
- run: cargo miri test --workspace --lib
# AddressSanitizer over the real C boundary: build libgphoto2 (vusb+ptp2) with
# ASan and run the vcamera tests instrumented, catching out-of-bounds / UAF in
# our marshalling or in libgphoto2 itself during real capture/config/events.
asan:
name: asan (vcamera, runtime)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install build deps
run: |
sudo apt-get update
sudo apt-get install -y ninja-build libltdl-dev pkg-config gettext clang libclang-dev llvm
pipx install meson
- uses: dtolnay/rust-toolchain@nightly
with:
components: rust-src
- uses: Swatinem/rust-cache@v2
- name: Build ASan libgphoto2 + run vcamera tests under ASan
run: ./scripts/run-vcamera-asan.sh