Skip to content

Better qis runtime handling #320

Better qis runtime handling

Better qis runtime handling #320

Workflow file for this run

name: Rust test / linting
env:
TRIGGER_ON_PR_PUSH: true # Set to true to enable triggers on PR pushes
RUSTFLAGS: -C debuginfo=0
RUST_BACKTRACE: 1
on:
push:
branches: [ "master", "development", "dev" ]
paths:
- 'crates/**'
- 'examples/**'
- 'julia/pecos-julia-ffi/**'
- 'Cargo.toml'
- '.github/workflows/rust-test.yml'
- '.pre-commit-config.yaml'
pull_request:
branches: [ "master", "development", "dev" ]
paths:
- 'crates/**'
- 'examples/**'
- 'julia/pecos-julia-ffi/**'
- 'Cargo.toml'
- '.github/workflows/rust-test.yml'
- '.pre-commit-config.yaml'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
rust-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust (for local testing)
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
export PATH="$HOME/.cargo/bin:$PATH"
- name: Set up Rust
run: rustup override set stable && rustup update
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref_name == 'master' || github.ref_name == 'development' || github.ref_name == 'dev' }}
- name: Setup LLVM 14.0.6
uses: ./.github/actions/setup-llvm
- name: Install rustfmt
run: rustup component add rustfmt
- name: Check formatting
run: cargo fmt --all -- --check
- name: Install clippy
run: rustup component add clippy
- name: Run clippy
run: cargo clippy --workspace --all-targets -- -D warnings
rust-lint-no-llvm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust (for local testing)
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
export PATH="$HOME/.cargo/bin:$PATH"
- name: Set up Rust
run: rustup override set stable && rustup update
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref_name == 'master' || github.ref_name == 'development' || github.ref_name == 'dev' }}
- name: Install rustfmt
run: rustup component add rustfmt
- name: Check formatting
run: cargo fmt --all -- --check
- name: Install clippy
run: rustup component add clippy
- name: Run clippy without LLVM features
run: |
echo "Running clippy without LLVM features..."
# Use --manifest-path to avoid workspace resolution pulling in LLVM dependencies
echo "Testing pecos-core..."
cd crates/pecos-core && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-engines..."
cd crates/pecos-engines && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-qsim..."
cd crates/pecos-qsim && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-programs..."
cd crates/pecos-programs && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-rng..."
cd crates/pecos-rng && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-qasm..."
cd crates/pecos-qasm && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-phir-json..."
cd crates/pecos-phir-json && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-qis-ffi-types..."
cd crates/pecos-qis-ffi-types && cargo clippy --all-targets -- -D warnings && cd ../..
# Test the main pecos crate without default features
echo "Testing pecos without default features..."
cd crates/pecos && cargo clippy --all-targets --no-default-features -- -D warnings && cd ../..
# Note: Skipping crates that require LLVM:
# - pecos-hugr-qis (HUGR to LLVM compiler)
# - pecos-qis-core (has inkwell dependency)
# - pecos-qis-selene (depends on pecos-qis-core with llvm feature)
# - pecos-phir (when hugr feature is enabled, depends on tket-qsystem which pulls in LLVM)
echo "Successfully tested core crates without LLVM!"
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure
rust-test:
needs: [pre-commit, rust-lint]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Install Rust (for local testing)
if: matrix.os == 'windows-latest'
run: |
curl -sSf -o rustup-init.exe https://win.rustup.rs
./rustup-init.exe -y --default-toolchain stable --profile minimal
echo "$HOME\.cargo\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
$env:Path += ";$HOME\.cargo\bin"
- name: Install Rust (for local testing)
if: matrix.os != 'windows-latest'
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
export PATH="$HOME/.cargo/bin:$PATH"
- name: Set up Rust
run: rustup show
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref_name == 'master' || github.ref_name == 'development' || github.ref_name == 'dev' }}
- name: Setup LLVM 14.0.6
uses: ./.github/actions/setup-llvm
- name: Set up Visual Studio environment on Windows
if: matrix.os == 'windows-latest'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
- name: Compile tests (macOS)
if: matrix.os == 'macos-latest'
run: |
# CRITICAL: Prevent Homebrew library paths from being used during linking
# This fixes the "@rpath/libunwind.1.dylib" runtime error on macOS
# Reference: https://github.com/rust-lang/rust/issues/135372
unset LIBRARY_PATH
unset LD_LIBRARY_PATH
unset DYLD_LIBRARY_PATH
unset DYLD_FALLBACK_LIBRARY_PATH
unset PKG_CONFIG_PATH
export LIBRARY_PATH=/usr/lib
echo "RUSTFLAGS: $RUSTFLAGS"
cargo test --no-run
- name: Compile tests (Linux/Windows)
if: matrix.os != 'macos-latest'
run: cargo test --no-run
- name: Run tests (macOS)
if: matrix.os == 'macos-latest'
run: |
# CRITICAL: Prevent Homebrew library paths from being used during linking
# This fixes the "@rpath/libunwind.1.dylib" runtime error on macOS
# Reference: https://github.com/rust-lang/rust/issues/135372
unset LIBRARY_PATH
unset LD_LIBRARY_PATH
unset DYLD_LIBRARY_PATH
unset DYLD_FALLBACK_LIBRARY_PATH
unset PKG_CONFIG_PATH
export LIBRARY_PATH=/usr/lib
cargo test --workspace
- name: Run tests (Linux)
if: matrix.os == 'ubuntu-latest'
run: cargo test --workspace
- name: Run tests (Windows)
if: matrix.os == 'windows-latest'
run: |
# Run all non-doctest tests
cargo test --workspace --exclude pecos-rslib --lib --bins --tests --examples
# For Windows, we need to run doctests for the pecos crate specially
# to ensure they run from the crate directory
cd crates/pecos
cargo test --doc
cd ../..
# Run doctests for other crates normally
cargo test --workspace --exclude pecos-rslib --exclude pecos --doc