Skip to content

Commit cef148b

Browse files
authored
add support for the wasm32-wasip3 target and ABI (#242)
* add support for the `wasm32-wasip3` target and ABI This paves the way for supporting cooperative mulithreading. Currently, we embed two copies of each library: one for p2 and one for p3, selecting which to use based on whether the target world uses any async features. In order to avoid even longer build times, I've published a pre-built CPython WASI tarball which we use by default instead of building from source. This also adds support for testing WIT maps in the test generator, which I meant to include in an earlier commit. Co-authored-by: Alex Crichton <alex@alexcrichton.com> enable multithreading and add example This required updates to the CPython fork used, and also switching to a temporary fork of WASI-SDK which enables Wasm exception handling + cooperative multithreading + shared libraries. * switch back to Rust stable in CI * pin Linux CI runner to `ubuntu-24.04` `ubuntu-latest` now points to `ubuntu-26.04`, which doesn't have Python 3.14. We can upgrade once we're on Python 3.15.
1 parent 5382383 commit cef148b

25 files changed

Lines changed: 814 additions & 595 deletions

File tree

‎.github/workflows/release.yaml‎

Lines changed: 8 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -12,65 +12,21 @@ on:
1212

1313
env:
1414
CARGO_TERM_COLOR: always
15-
WASI_SDK_VERSION: 34
1615

1716
permissions:
1817
contents: write
1918
pull-requests: write
2019

2120
jobs:
22-
linux:
23-
name: Populate cache
24-
runs-on: ubuntu-latest
25-
steps:
26-
- name: Checkout
27-
uses: actions/checkout@v4
28-
with:
29-
submodules: "recursive"
30-
31-
- uses: actions/setup-python@v5
32-
with:
33-
python-version: "3.14.0"
34-
35-
- name: Install latest Rust stable toolchain
36-
uses: dtolnay/rust-toolchain@stable
37-
with:
38-
targets: wasm32-wasip2
39-
components: clippy, rustfmt
40-
41-
- uses: Swatinem/rust-cache@v2
42-
with:
43-
shared-key: "rust-cache-${{ hashFiles('./Cargo.lock') }}"
44-
cache-on-failure: false
45-
46-
- name: Install WASI-SDK
47-
shell: bash
48-
run: |
49-
cd /tmp
50-
curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-x86_64-linux.tar.gz
51-
tar xf wasi-sdk-${WASI_SDK_VERSION}.0-x86_64-linux.tar.gz
52-
mv wasi-sdk-${WASI_SDK_VERSION}.0-x86_64-linux /opt/wasi-sdk
53-
54-
- name: Build
55-
shell: bash
56-
run: cargo build --release
57-
58-
- name: Upload CPython builddir
59-
uses: actions/upload-artifact@v4
60-
with:
61-
name: cpython-wasi
62-
path: cpython/builddir/wasi
63-
6421
release:
6522
name: Build and release
66-
needs: linux
6723
runs-on: ${{ matrix.config.os }}
6824
strategy:
6925
fail-fast: false
7026
matrix:
7127
config:
7228
- {
73-
os: "ubuntu-latest",
29+
os: "ubuntu-24.04",
7430
arch: "amd64",
7531
maturin_target: "x86_64",
7632
wasiSDK: "x86_64-linux",
@@ -80,7 +36,7 @@ jobs:
8036
targetDir: "target/release",
8137
}
8238
- {
83-
os: "ubuntu-latest",
39+
os: "ubuntu-24.04",
8440
arch: "aarch64",
8541
maturin_target: "aarch64",
8642
wasiSDK: "x86_64-linux",
@@ -129,13 +85,13 @@ jobs:
12985
with:
13086
python-version: "3.14.0"
13187

132-
- name: Install latest Rust stable toolchain
88+
- name: Install latest Rust toolchain
13389
uses: dtolnay/rust-toolchain@stable
13490
with:
135-
targets: wasm32-wasip2 ${{ matrix.config.target }}
91+
targets: wasm32-wasip2 wasm32-wasip3 ${{ matrix.config.target }}
13692

13793
- uses: Swatinem/rust-cache@v2
138-
if: matrix.config.os == 'ubuntu-latest' && matrix.config.arch == 'amd64'
94+
if: matrix.config.os == 'ubuntu-24.04' && matrix.config.arch == 'amd64'
13995
with:
14096
shared-key: "rust-cache-${{ hashFiles('./Cargo.lock') }}"
14197
cache-on-failure: "false"
@@ -157,36 +113,12 @@ jobs:
157113
OS=$(echo "${{ runner.os }}" | tr '[:upper:]' '[:lower:]')
158114
echo "RUNNER_OS=$OS" >> $GITHUB_ENV
159115
160-
- name: Download WASI-SDK
161-
shell: bash
162-
run: |
163-
cd /tmp
164-
curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-${{ matrix.config.wasiSDK }}.tar.gz
165-
tar xf wasi-sdk-${WASI_SDK_VERSION}.0-${{ matrix.config.wasiSDK }}.tar.gz
166-
167-
- name: Install WASI-SDK
168-
if: runner.os != 'Windows'
169-
shell: bash
170-
run: sudo mv /tmp/wasi-sdk-${WASI_SDK_VERSION}.0-${{ matrix.config.wasiSDK }} /opt/wasi-sdk
171-
172-
- name: Install WASI-SDK on Windows
173-
if: runner.os == 'Windows'
174-
shell: bash
175-
run: echo "WASI_SDK_PATH=$(cygpath -m /tmp/wasi-sdk-${WASI_SDK_VERSION}.0-${{ matrix.config.wasiSDK }})" >> ${GITHUB_ENV}
176-
177-
- name: Restore CPython
178-
uses: actions/download-artifact@v5
179-
with:
180-
name: cpython-wasi
181-
path: cpython/builddir/wasi
182-
183116
- name: Build wheels
184117
uses: PyO3/maturin-action@v1
185118
with:
186119
target: ${{ matrix.config.maturin_target }}
187120
args: --release --out dist --features pyo3
188121
manylinux: 2_28
189-
docker-options: -v /opt/wasi-sdk:/opt/wasi-sdk
190122
before-script-linux: |
191123
rustup target add wasm32-wasip2
192124
@@ -234,7 +166,7 @@ jobs:
234166

235167
checksums:
236168
name: Generate checksums
237-
runs-on: ubuntu-latest
169+
runs-on: ubuntu-24.04
238170
needs: release
239171
steps:
240172
- name: Set the release version (tag)
@@ -272,7 +204,7 @@ jobs:
272204

273205
sdist:
274206
name: Build Python sdist
275-
runs-on: ubuntu-latest
207+
runs-on: ubuntu-24.04
276208
steps:
277209
- name: Checkout
278210
uses: actions/checkout@v4
@@ -294,7 +226,7 @@ jobs:
294226
name: Update canary release
295227
needs: [checksums, sdist]
296228
if: github.ref == 'refs/heads/main'
297-
runs-on: ubuntu-latest
229+
runs-on: ubuntu-24.04
298230
steps:
299231
- name: Checkout
300232
uses: actions/checkout@v4

‎.github/workflows/test.yaml‎

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -14,59 +14,15 @@ concurrency:
1414

1515
env:
1616
CARGO_TERM_COLOR: always
17-
WASI_SDK_VERSION: 34
1817

1918
jobs:
20-
linux:
21-
name: Populate cache
22-
runs-on: ubuntu-latest
23-
steps:
24-
- name: Checkout
25-
uses: actions/checkout@v4
26-
with:
27-
submodules: "recursive"
28-
29-
- uses: actions/setup-python@v5
30-
with:
31-
python-version: "3.14.0"
32-
33-
- name: Install latest Rust stable toolchain
34-
uses: dtolnay/rust-toolchain@stable
35-
with:
36-
targets: wasm32-wasip2
37-
components: clippy, rustfmt
38-
39-
- uses: Swatinem/rust-cache@v2
40-
with:
41-
shared-key: "rust-cache-${{ hashFiles('./Cargo.lock') }}"
42-
cache-on-failure: false
43-
44-
- name: Install WASI-SDK
45-
shell: bash
46-
run: |
47-
cd /tmp
48-
curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-x86_64-linux.tar.gz
49-
tar xf wasi-sdk-${WASI_SDK_VERSION}.0-x86_64-linux.tar.gz
50-
mv wasi-sdk-${WASI_SDK_VERSION}.0-x86_64-linux /opt/wasi-sdk
51-
52-
- name: Build
53-
shell: bash
54-
run: cargo build --release
55-
56-
- name: Upload CPython builddir
57-
uses: actions/upload-artifact@v4
58-
with:
59-
name: cpython-wasi
60-
path: cpython/builddir/wasi
61-
6219
test:
6320
name: Test
64-
needs: linux
6521
strategy:
6622
fail-fast: false
6723
matrix:
6824
config:
69-
- { os: "ubuntu-latest", wasiSDK: "x86_64-linux" }
25+
- { os: "ubuntu-24.04", wasiSDK: "x86_64-linux" }
7026
- { os: "macos-latest", wasiSDK: "arm64-macos" }
7127
- { os: "windows-latest", wasiSDK: "x86_64-windows" }
7228
runs-on: ${{ matrix.config.os }}
@@ -76,47 +32,24 @@ jobs:
7632
with:
7733
submodules: "recursive"
7834

79-
- name: Install latest Rust stable toolchain
35+
- name: Install latest Rust toolchain
8036
uses: dtolnay/rust-toolchain@stable
8137
with:
82-
targets: wasm32-wasip2
38+
targets: wasm32-wasip2 wasm32-wasip3
8339
components: clippy, rustfmt
8440

8541
- uses: Swatinem/rust-cache@v2
8642
with:
8743
shared-key: "rust-cache-${{ hashFiles('./Cargo.lock') }}"
8844
cache-on-failure: false
8945

90-
- name: Download WASI-SDK
91-
shell: bash
92-
run: |
93-
cd /tmp
94-
curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-${{ matrix.config.wasiSDK }}.tar.gz
95-
tar xf wasi-sdk-${WASI_SDK_VERSION}.0-${{ matrix.config.wasiSDK }}.tar.gz
96-
97-
- name: Install WASI-SDK
98-
if: runner.os != 'Windows'
99-
shell: bash
100-
run: sudo mv /tmp/wasi-sdk-${WASI_SDK_VERSION}.0-${{ matrix.config.wasiSDK }} /opt/wasi-sdk
101-
102-
- name: Install WASI-SDK on Windows
103-
if: runner.os == 'Windows'
104-
shell: bash
105-
run: echo "WASI_SDK_PATH=$(cygpath -m /tmp/wasi-sdk-${WASI_SDK_VERSION}.0-${{ matrix.config.wasiSDK }})" >> ${GITHUB_ENV}
106-
107-
- name: Restore CPython
108-
uses: actions/download-artifact@v5
109-
with:
110-
name: cpython-wasi
111-
path: cpython/builddir/wasi
112-
11346
- name: Lint
11447
shell: bash
11548
run: bash .github/workflows/lint.sh
11649

11750
- uses: taiki-e/install-action@v2
11851
with:
119-
tool: wasmtime-cli@46.0.1
52+
tool: wasmtime-cli@48.0.2
12053

12154
- uses: actions/setup-python@v5
12255
with:

‎.gitignore‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,17 @@ target
22
__pycache__
33
.mypy_cache
44
.venv
5-
bacon.toml
65
dist
7-
examples/matrix-math/*.wasm
6+
examples/*/*.wasm
87
examples/matrix-math/numpy*
98
examples/matrix-math/matrix_math
109
examples/matrix-math/wasmtime-py
11-
examples/http/.spin
12-
examples/http/http.wasm
1310
examples/http/proxy
1411
examples/http/poll_loop.py
15-
examples/http-p3/http.wasm
16-
examples/tcp-p3/tcp.wasm
17-
examples/tcp/tcp.wasm
1812
examples/tcp/command
19-
examples/cli-p3/cli.wasm
20-
examples/cli/cli.wasm
2113
examples/cli/command
2214
examples/sandbox/sandbox
23-
examples/sandbox/sandbox.wasm
15+
examples/multithreading/*.wasm
16+
examples/multithreading/command
2417
wasi-sdk
2518
cpython

‎CONTRIBUTING.md‎

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,35 @@ channel](https://bytecodealliance.zulipchat.com/#narrow/stream/394175-SIG-Guest-
1616

1717
### Prerequisites
1818

19-
- Tools needed to build [CPython](https://github.com/python/cpython) (Make, Clang, etc.)
20-
- [Rust](https://rustup.rs/) stable 1.94 or later, including the `wasm32-wasip2` target
19+
- (optional) Tools needed to build [CPython](https://github.com/python/cpython)
20+
(Make, Clang, etc.)
21+
- [Rust](https://rustup.rs/) stable 1.100 or later, including the
22+
`wasm32-wasip2` and `wasm32-wasip3` targets
2123

2224
For Rust, something like this should work once you have `rustup`:
2325

2426
```shell
2527
rustup update
26-
rustup target add wasm32-wasip2
28+
rustup target add wasm32-wasip2 wasm32-wasip3
2729
```
2830

29-
### Building and Running
31+
### Building and Running Tests
3032

31-
First, make sure you've got all the submodules cloned.
33+
To build the project and run the tests, use:
3234

3335
```shell
34-
git submodule update --init --recursive
36+
cargo test --release
3537
```
3638

37-
Next, install WASI-SDK 33 to `/opt/wasi-sdk` (alternatively, you can specify a
38-
different location and reference it later using the `WASI_SDK_PATH` environment
39-
variable). Replace `arm64-linux` with `x86_64-linux`, `arm64-macos`,
40-
`x86_64-macos`, `arm64-windows`, or `x86_64-windows` below depending on your
41-
architecure and OS, if necessary.
39+
By default, `build.rs` will download and use pre-built WASI-SDK and Cpython
40+
binaries. If you'd like to supply your own version of WASI-SDK and use it to
41+
build CPython from source, install
42+
[WASI-SDK](https://github.com/WebAssembly/wasi-sdk/releases) 34 or later, then
43+
run:
4244

4345
```shell
44-
curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-33/wasi-sdk-33.0-arm64-linux.tar.gz
45-
tar xf wasi-sdk-33.0-arm64-linux.tar.gz
46-
sudo mv wasi-sdk-33.0-arm64-linux /opt/wasi-sdk
47-
export WASI_SDK_PATH=/opt/wasi-sdk
48-
```
49-
50-
Finally, build and run `componentize-py`.
51-
52-
```shell
53-
cargo run --release -- --help
46+
rm -rf cpython
47+
CPYTHON_BUILD_FROM_SOURCE=1 cargo test --release
5448
```
5549

5650
## Publishing Releases

0 commit comments

Comments
 (0)