Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1431c4b
Update `http` WASI package to the version used in wasiless.
erikrose Oct 8, 2025
53c121e
Add a wac file for satisfying Flask and Bottle's apps with wasiless' …
erikrose Oct 8, 2025
5db229b
Regularize wac based on an examination of the `compute` package and t…
erikrose Oct 8, 2025
94d2b33
Update compute.wit to match Viceroy `main` at f6b6b1045ce5e1f61cbecf4…
erikrose Oct 8, 2025
14af8d3
Add `poll` to compute.wit.
erikrose Oct 8, 2025
bbdfa5c
Say "python" rather than "app".
erikrose Oct 8, 2025
f63a042
Sync up `viceroy` world with Viceroy.
erikrose Oct 9, 2025
156c02e
Vendor wasiless and model wac composition in Makefile
posborne Oct 9, 2025
f9a0bea
Target wasm32-unknown-unknown with wasiless
posborne Oct 9, 2025
d743cc4
Comment out WAC mappings that result in link errors.
erikrose Oct 9, 2025
d812c6c
Remove export of things we don't need.
erikrose Oct 9, 2025
01cc2f9
Switch to a WAC file and version of wasiless that allows the app to l…
erikrose Oct 16, 2025
018855d
Allow a locally built Viceroy to be subbed in via env var.
erikrose Oct 16, 2025
887260f
Clean up WAC exports.
erikrose Oct 16, 2025
190f764
Flask and Bottle examples now work!
erikrose Oct 16, 2025
bfb2e86
Make tests pass.
erikrose Oct 16, 2025
aa42fa1
Stop ignoring top-level wasms, which we don't make anymore.
erikrose Oct 16, 2025
ac698e8
Ditch an unused import.
erikrose Oct 16, 2025
2844623
Switch to the 2-memories-having version of Viceroy in CI so the `wasi…
erikrose Oct 16, 2025
6776b89
Switch to self-hosted CI runners.
erikrose Oct 17, 2025
7c4339c
Check out `wasiless` using a deploy key.
erikrose Oct 17, 2025
1f3ec06
Add what we need to build `wasiless`.
erikrose Oct 17, 2025
5def5e2
Cache Viceroy build, because it takes 10 minutes.
erikrose Oct 17, 2025
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
29 changes: 26 additions & 3 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: forge-amd64-medium
steps:
- uses: actions/checkout@v4
- name: Set Up Rust Toolchain
- 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.86.0'
target: wasm32-unknown-unknown
- name: Set up Python
uses: actions/setup-python@v5
with:
Expand All @@ -25,8 +36,20 @@ jobs:
run: pip install uv
- name: Install dependencies
run: uv sync
- name: Cache viceroy, wasm-tools, etc.
id: cache-cargo
uses: actions/cache@v4
with:
key: python-sdk-compatible-1
path: |
~/.cargo/bin/
- name: Install wasm-tools and wac
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: cargo install wasm-tools wac-cli
- name: Install viceroy
run: cargo install --git https://github.com/fastly/Viceroy.git --branch sunfishcode/sync-wit viceroy
if: steps.cache-cargo.outputs.cache-hit != 'true'
# When you switch tags, update the cache key in the cache-cargo step.
run: cargo install --git https://github.com/fastly/Viceroy.git --tag erik/python-sdk-compatible-1 viceroy
- name: Install dependencies
run: uv sync --extra dev --extra test
- name: Check formatting
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ __pycache__

# Build artifacts
/build/
*.wasm
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vendor/wasiless"]
path = vendor/wasiless
url = git@github.com:fastly/wasiless.git
35 changes: 26 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Fastly Compute Python SDK

# Default Viceroy location. Set VICEROY env var to change.
VICEROY ?= viceroy

# Configuration
STUBS_DIR := stubs
BUILD_DIR := build
Expand All @@ -10,20 +13,35 @@ EXAMPLES := wit-bottle flask-app

# Default example for serve target
EXAMPLE ?= wit-bottle
WASM_FILE := $(BUILD_DIR)/$(EXAMPLE).wasm
WASM_FILE := $(BUILD_DIR)/$(EXAMPLE).composed.wasm

TARGET_WORLD := fastly:compute/service

# Generate WASM file paths for all examples
EXAMPLE_WASMS := $(foreach example,$(EXAMPLES),$(BUILD_DIR)/$(example).wasm)

# Composed wasm for each example
COMPOSED_WASMS := $(foreach example,$(EXAMPLES),$(BUILD_DIR)/$(example).composed.wasm)

WASILESS_ROOT := vendor/wasiless
WASILESS_WASM := $(WASILESS_ROOT)/wasiless.wasm

# Default target builds all examples
all: $(EXAMPLE_WASMS)
all: $(COMPOSED_WASMS)

$(BUILD_DIR)/%.composed.wasm: $(BUILD_DIR)/%.wasm $(WASILESS_WASM)
@echo "Composing $* example"
wac compose --dep fastly:wasiless=$(WASILESS_WASM) --dep app:component=$< -o $@ wrap_app_in_wasiless.wac

# Pattern rule for building any example
$(BUILD_DIR)/%.wasm: $(EXAMPLES_DIR)/%.py wit/viceroy.wit wit/deps/fastly/compute.wit | $(BUILD_DIR)
$(BUILD_DIR)/%.wasm: $(EXAMPLES_DIR)/%.py wit/viceroy.wit wit/deps/fastly/compute.wit fastly_compute/wsgi.py | $(BUILD_DIR)
@echo "Building $* example..."
rm -rf $(STUBS_DIR)
uv run componentize-py -d wit -w viceroy bindings $(STUBS_DIR)
uv run componentize-py -d wit -w viceroy componentize $* -p $(EXAMPLES_DIR) -p . -o $@
uv run componentize-py -d wit -w $(TARGET_WORLD) bindings $(STUBS_DIR)
uv run componentize-py -d wit -w $(TARGET_WORLD) componentize $* -p $(EXAMPLES_DIR) -p . -o $@

$(WASILESS_WASM):
$(MAKE) -C $(WASILESS_ROOT) wasiless.wasm

# Create build directory
$(BUILD_DIR):
Expand All @@ -32,10 +50,10 @@ $(BUILD_DIR):
# Serve the specified example (default: wit-bottle)
serve: $(WASM_FILE)
@echo "Serving $(EXAMPLE) example on http://127.0.0.1:7676"
viceroy serve $(WASM_FILE)
$(VICEROY) serve $(WASM_FILE)

# Test all examples (requires all WASM files to be built)
test: $(EXAMPLE_WASMS)
test: $(COMPOSED_WASMS)
uv run --extra test pytest

# List available examples
Expand Down Expand Up @@ -87,5 +105,4 @@ help:
@echo ""
@echo "Available examples: $(EXAMPLES)"

.PHONY: all serve test list-examples build-all clean lint lint-fix format format-check help

.PHONY: all serve test list-examples build-all clean lint lint-fix format format-check help $(WASILESS_WASM)
2 changes: 1 addition & 1 deletion fastly_compute/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_my_endpoint(self):
"""

REQUEST_TIMEOUT = 10
WASM_FILE = "build/wit-bottle.wasm" # Default to the main example
WASM_FILE = "build/wit-bottle.composed.wasm" # Default to the main example
server: ViceroyServer = None # Will be set by the fixture

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion fastly_compute/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def serve_wsgi_request(

def write(body_data: bytes) -> None:
"""Write response body data (deprecated WSGI mechanism)."""
http_body.write(response_body, body_data, http_body.WriteEnd.BACK)
http_body.write(response_body, body_data)

def start_response(
status: str, headers: list[tuple[str, str]], exc_info: Any | None = None
Expand Down
4 changes: 1 addition & 3 deletions tests/test_flask_example.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""Tests for the Flask example application."""

import pytest

from fastly_compute.testing import ViceroyTestBase


class TestFlaskApp(ViceroyTestBase):
"""Integration tests for the Flask example application."""

WASM_FILE = "build/flask-app.wasm"
WASM_FILE = "build/flask-app.composed.wasm"

def test_hello_endpoint(self):
"""Test the hello endpoint returns expected content."""
Expand Down
1 change: 1 addition & 0 deletions vendor/wasiless
Submodule wasiless added at 4c9ac5
Loading