Skip to content

Separate out maturin build in CI, use DEV_MODE=0 for test #108

Separate out maturin build in CI, use DEV_MODE=0 for test

Separate out maturin build in CI, use DEV_MODE=0 for test #108

Workflow file for this run

name: Python CI
on:
push: # Runs on pushes to all branches
pull_request:
branches:
- main
workflow_dispatch: # Allows manual triggering from GitHub Actions UI
env:
VICEROY_TAG: v0.16.3
jobs:
build:
runs-on: forge-amd64-medium
steps:
- uses: actions/checkout@v4
- name: Get wasiless submodule
# Org-internal submodules are very tricky to check out.
env:
SSHK: ${{ secrets.WASILESS_REPO_READ_KEY }}
run: |
mkdir -p $HOME/.ssh
echo "$SSHK" > $HOME/.ssh/ssh.key
chmod 600 $HOME/.ssh/ssh.key
export GIT_SSH_COMMAND="ssh -i $HOME/.ssh/ssh.key"
git submodule update --init --recursive
- name: Set up Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.92.0
target: wasm32-unknown-unknown
components: rustfmt, clippy
# Disable the built-in cargo cache - we'll use a more sophisticated setup below
cache: false
- name: Set up nightly Rust toolchain with rust-src
run: |
rustup toolchain install nightly --component rust-src
rustup target add wasm32-wasip1 --toolchain nightly
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install uv
run: pip install uv
# Cache cargo binaries (viceroy, wasm-tools, etc.)
- name: Cache cargo binaries
id: cache-cargo-bins
uses: actions/cache@v4
with:
key: cargo-bins-${{ runner.os }}-${{ env.VICEROY_TAG }}
path: |
~/.cargo/bin/viceroy*
~/.cargo/bin/wasm-tools*
~/.cargo/bin/wac*
- name: Install wasm-tools and wac
if: steps.cache-cargo-bins.outputs.cache-hit != 'true'
run: cargo install wasm-tools wac-cli
- name: Install viceroy
if: steps.cache-cargo-bins.outputs.cache-hit != 'true'
run: cargo install --git https://github.com/fastly/Viceroy.git --tag "$VICEROY_TAG" viceroy
# Cache Rust dependencies and build artifacts
- name: Cache Rust dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: cargo-deps-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
cargo-deps-${{ runner.os }}-
# Cache componentize-py CPython build (this is the slow part!)
# The CPython build is deterministic based on the componentize-py version
# componentize-py will download WASI SDK automatically if not found at /opt/wasi-sdk
- name: Cache componentize-py CPython build
uses: actions/cache@v4
with:
path: |
~/.cargo/git/checkouts/componentize-py-*/*/cpython/builddir/
target/*/build/componentize-py-*/out/
key: componentize-py-cpython-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-v2
restore-keys: |
componentize-py-cpython-${{ runner.os }}-
# Setup sccache for C/C++ compilation caching (speeds up CPython build)
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.8
- name: Configure sccache
run: |
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
echo "CC=sccache clang" >> $GITHUB_ENV
echo "CXX=sccache clang++" >> $GITHUB_ENV
# Build the Rust native extension; this would be triggered by `uv sync` but
# separated out here as it can take quite awhile depending on what is
# cached.
- name: Build native extension
run: uv run maturin develop --release
# Install Python dependencies (fast now that native extension is built)
- name: Install Python dependencies
run: uv sync --extra dev --extra test --extra examples
# Finally, do our final checks
- name: Check formatting
run: make format-check
- name: Run linting
run: make lint
- name: Run tests
# Use DEV_MODE=0 to use the installed fastly-compute-py binary instead of rebuilding with cargo
run: DEV_MODE=0 make test