Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 36 additions & 25 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Python CI

on:
push: # Runs on pushes to all branches
pull_request:
push:
branches:
- main
pull_request:
workflow_dispatch: # Allows manual triggering from GitHub Actions UI

env:
Expand All @@ -21,7 +21,7 @@ jobs:
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
# Disable the built-in cargo cache - we use our own below
cache: false
- name: Set up nightly Rust toolchain with rust-src
run: |
Expand All @@ -33,57 +33,68 @@ jobs:
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*
~/.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
# CRITICAL: ~/.cargo/git/checkouts/ contains componentize-py source + built CPython (5+ min build)
- name: Cache Rust dependencies

# Cache Rust registry and git sources separately from build artifacts.
#
# Sources are keyed only on Cargo.lock so they survive a clean target/
# and are shared across build profiles (release, clippy, etc.).
#
# Build artifacts (target/) are cached separately per Cargo.lock AND
# Rust toolchain version, because different toolchain versions produce
# incompatible artifacts.
- name: Cache Rust sources
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.cargo/git/checkouts/
target/
key: cargo-deps-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-v3
key: cargo-sources-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-v1
restore-keys: |
cargo-deps-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-
cargo-deps-${{ runner.os }}-

# Setup sccache for Rust compilation caching
- 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
cargo-sources-${{ runner.os }}-

# Build artifacts are cached per Cargo.lock + toolchain. We cache both
# release and debug/clippy profiles together since they share most deps.
- name: Cache Rust build artifacts
uses: actions/cache@v4
with:
path: target/
key: cargo-target-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-${{ env.RUSTUP_TOOLCHAIN }}-v1
restore-keys: |
cargo-target-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-
cargo-target-${{ runner.os }}-

# Build the Rust native extension (this is the slow part - builds componentize-py + CPython)
# Build the native extension in release mode first so the release
# artifacts are in target/. Clippy reuses these artifacts for deps
# that don't change between profiles.
- name: Build native extension
run: uv run maturin develop --release

# Install Python dependencies
- name: Install Python dependencies
run: uv sync --extra dev --extra test --extra examples

# Finally, do our final checks
# Run clippy using the same --release flag and features as the build
# above so that Cargo can reuse the already-compiled dependency
# artifacts and only checks our own crate.
- name: Check formatting
run: make format-check
- name: Run linting
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ lint: fastly_compute/runtime_patching/patches.py | $(STUBS_DIR)
uv run --extra dev ruff check .
uv run --extra dev --extra test pyrefly check
@echo "Linting Rust code..."
cd crates/fastly-compute-py && cargo clippy -- -D warnings
cd crates/fastly-compute-py && cargo clippy --release --no-default-features --features binary -- -D warnings

lint-fix: fastly_compute/runtime_patching/patches.py
@echo "Fixing Python code..."
uv run --extra dev ruff check --fix .
@echo "Fixing Rust code..."
cd crates/fastly-compute-py && cargo clippy --fix --allow-dirty --allow-staged
cd crates/fastly-compute-py && cargo clippy --release --no-default-features --features binary --fix --allow-dirty --allow-staged

format:
@echo "Formatting Python code..."
Expand Down
Loading