Skip to content

Commit 4ae7014

Browse files
authored
Develop bindings for WASI versions in parallel (#118)
* Develop bindings for WASI versions in parallel This commit is a reorganization of this crate to develop the WASIp{1,2,3} crate bindings in parallel with each other in separate crates. Historically the WASIp1 support ceased with the publication of 0.12.0 of the `wasi` crate which was the first release generated by `wit-bindgen` suitable for use with WASIp2. The rough idea was to do the same with WASIp3 at some point, but today it was realized that this probably won't work. Specifically the version number of the `wasi` crate right now is tied to not only the WASI API version that's being bound but addition to the `wit-bindgen` that is generating bindings. If either one updates in a breaking way then the crate number here needs to be bumped. This means that if we want to develop both WASIp2 and WASIp3 at the same time we'd have to somehow reserve a space of future version numbers for the WASIp2 track which would be a bit awkward. Additionally it's a bit awkward to have non-`main` development of WASIp2, a supported target, when WASIp3 wants to be added. This new crate organization is intended to solve this concerns and looks like so: * Each version of WASI now has its own crate. For example there's now a `wasip1` crate and a `wasip2` crate. Eventually there will be a `wasip3` crate. * A version-specific WASI crate is developed on `main` of this repository and gets CI run, auto-generated bindings verified, etc. Versions will be published as necessary for each version of each crate. * The `wasi` crate is now a small wrapper around the latest stable WASI release available. Currently this is a stable reexport of the `wasip2` crate. Various bits of README documentation have all been updated to reflect this new structure. The intention is that in the near-ish future a `wasip3` crate will be added which will contain auto-generated bindings for WASIp3 and its upcoming snapshots. This new `wasip3` crate would not be integrated into the `wasi` crate and the `wasi` crate would continue to reexport `wasip2`. In this manner we can develop `wasip3` more easily alongside the `wasip2` crate. * Fixes for CI * Update msrv to 78 * Cancel in-flight CI * Update msrv * Download precompiled binary of wit-bindgen * Downgrade one point * Remove version suffix
1 parent b17d34b commit 4ae7014

39 files changed

+5316
-494
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: 'Install Rust toolchain'
2+
description: 'Install a rust toolchain'
3+
4+
inputs:
5+
toolchain:
6+
description: 'Default toolchan to install'
7+
required: false
8+
default: 'stable'
9+
10+
runs:
11+
using: composite
12+
steps:
13+
- name: Install Rust
14+
shell: bash
15+
id: select
16+
run: |
17+
# Determine MSRV as N in `1.N.0` by looking at the `rust-version`
18+
# located in the root `Cargo.toml`.
19+
msrv=$(grep 'rust-version.*1' Cargo.toml | sed 's/.*\.\([0-9]*\)\..*/\1/')
20+
21+
if [ "${{ inputs.toolchain }}" = "msrv" ]; then
22+
echo "version=1.$msrv.0" >> "$GITHUB_OUTPUT"
23+
else
24+
echo "version=${{ inputs.toolchain }}" >> "$GITHUB_OUTPUT"
25+
fi
26+
27+
- name: Install Rust
28+
shell: bash
29+
run: |
30+
rustup set profile minimal
31+
rustup update "${{ steps.select.outputs.version }}" --no-self-update
32+
rustup default "${{ steps.select.outputs.version }}"
33+
34+
# Save disk space by avoiding incremental compilation. Also turn down
35+
# debuginfo from 2 to 0 to help save disk space.
36+
cat >> "$GITHUB_ENV" <<EOF
37+
CARGO_INCREMENTAL=0
38+
CARGO_PROFILE_DEV_DEBUG=0
39+
CARGO_PROFILE_TEST_DEBUG=0
40+
EOF
41+
42+
# Deny warnings on CI to keep our code warning-free as it lands in-tree.
43+
echo RUSTFLAGS="-D warnings" >> "$GITHUB_ENV"

.github/workflows/main.yml

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
name: CI
22
on: [push, pull_request]
33

4+
# Cancel any in-flight jobs for the same PR/branch so there's only one active
5+
# at a time
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.ref }}
8+
cancel-in-progress: true
9+
410
jobs:
5-
test:
6-
name: Test
11+
test_wasip2:
12+
name: Test WASIp2 on ${{ matrix.rust }}
713
runs-on: ubuntu-latest
814
strategy:
915
matrix:
1016
rust: [stable, beta, nightly]
1117
steps:
12-
- uses: actions/checkout@v4
13-
- name: Install Rust
14-
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }} && rustup component add rustfmt
15-
- run: rustup target add wasm32-wasip1 wasm32-unknown-unknown
16-
- run: cargo build --workspace
17-
- run: cargo build --workspace --no-default-features
18-
- run: cargo build --workspace --target wasm32-wasip1
19-
- run: cargo build --workspace --target wasm32-wasip1 --no-default-features
20-
- run: cargo test --workspace --doc
18+
- uses: actions/checkout@v5
19+
- uses: ./.github/actions/install-rust
20+
with:
21+
toolchain: ${{ matrix.rust }}
22+
- run: rustup target add wasm32-wasip2 wasm32-unknown-unknown
2123
- name: Install Wasmtime
2224
uses: bytecodealliance/actions/wasmtime/setup@v1
2325
with:
@@ -26,52 +28,71 @@ jobs:
2628
uses: bytecodealliance/actions/wasm-tools/setup@v1
2729
with:
2830
version: "1.224.0"
29-
- run: curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v30.0.2/wasi_snapshot_preview1.command.wasm
3031

31-
- run: cargo build --examples --target wasm32-wasip1 --no-default-features
32+
- run: cargo build -p wasip2 --examples --target wasm32-wasip2 --no-default-features
33+
- run: wasmtime run ./target/wasm32-wasip2/debug/examples/hello-world-no_std.wasm
34+
- run: wasmtime run ./target/wasm32-wasip2/debug/examples/cli_command_no_std.wasm
3235

33-
- run: wasm-tools component new ./target/wasm32-wasip1/debug/examples/hello-world-no_std.wasm --adapt ./wasi_snapshot_preview1.command.wasm -o component.wasm
34-
- run: wasmtime run component.wasm
36+
- run: cargo build -p wasip2 --examples --target wasm32-wasip2
37+
- run: wasmtime run ./target/wasm32-wasip2/debug/examples/hello-world.wasm
38+
- run: wasmtime run ./target/wasm32-wasip2/debug/examples/cli_command.wasm
3539

36-
- run: cargo build --examples --target wasm32-unknown-unknown --no-default-features
37-
38-
- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/cli_command_no_std.wasm -o component.wasm
39-
- run: wasmtime run component.wasm
4040

41+
- run: cargo build -p wasip2 --examples --target wasm32-unknown-unknown --no-default-features
4142
- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/http_proxy_no_std.wasm -o component.wasm
4243
- run: wasm-tools component targets wit component.wasm -w wasi:http/proxy
4344

44-
- run: cargo build --examples --target wasm32-wasip1
45-
46-
- run: wasm-tools component new ./target/wasm32-wasip1/debug/examples/hello-world.wasm --adapt ./wasi_snapshot_preview1.command.wasm -o component.wasm
47-
- run: wasmtime run component.wasm
45+
- run: cargo build -p wasip2 --examples --target wasm32-unknown-unknown
46+
- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/http_proxy.wasm -o component.wasm
47+
- run: wasm-tools component targets wit component.wasm -w wasi:http/proxy
4848

49-
- run: cargo build --examples --target wasm32-unknown-unknown
49+
- run: cargo build -p wasi-ext --examples --target wasm32-wasip2 --features rand
50+
- run: wasmtime run ./target/wasm32-wasip2/debug/examples/rand.wasm
5051

51-
- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/cli_command.wasm -o component.wasm
52-
- run: wasmtime run component.wasm
52+
build:
53+
name: Build ${{ matrix.crate }} on ${{ matrix.rust }}
54+
runs-on: ubuntu-latest
55+
strategy:
56+
matrix:
57+
rust: [msrv, stable, beta, nightly]
58+
crate: [wasi, wasip1, wasip2]
59+
steps:
60+
- uses: actions/checkout@v5
61+
- uses: ./.github/actions/install-rust
62+
with:
63+
toolchain: ${{ matrix.rust }}
64+
- run: rustup target add wasm32-wasip1 wasm32-wasip2
5365

54-
- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/http_proxy.wasm -o component.wasm
55-
- run: wasm-tools component targets wit component.wasm -w wasi:http/proxy
66+
- run: cargo build -p ${{ matrix.crate }}
67+
- run: cargo build -p ${{ matrix.crate }} --target wasm32-wasip1
68+
- run: cargo build -p ${{ matrix.crate }} --target wasm32-wasip2
5669

57-
- run: cargo build --examples --workspace --target wasm32-wasip1 --features rand
70+
- run: cargo build --no-default-features -p ${{ matrix.crate }}
71+
- run: cargo build --no-default-features -p ${{ matrix.crate }} --target wasm32-wasip1
72+
- run: cargo build --no-default-features -p ${{ matrix.crate }} --target wasm32-wasip2
5873

59-
- run: wasm-tools component new ./target/wasm32-wasip1/debug/examples/rand.wasm --adapt ./wasi_snapshot_preview1.command.wasm -o component.wasm
60-
- run: wasmtime run component.wasm
74+
- run: cargo test -p ${{ matrix.crate }} --doc
6175

6276
generate:
6377
name: Ensure generated code up-to-date
6478
runs-on: ubuntu-latest
6579
steps:
66-
- uses: actions/checkout@v4
67-
- name: Install Rust
68-
run: rustup update stable && rustup default stable
80+
- uses: actions/checkout@v5
81+
- uses: ./.github/actions/install-rust
6982
# Re-vendor all WIT files and ensure that they're all up-to-date by ensuring
7083
# that there's no git changes.
7184
- name: Re-vendor WIT
7285
run: |
7386
./ci/vendor-wit.sh
7487
git diff --exit-code
75-
- run: cargo install wit-bindgen-cli@0.45.0 --locked
88+
- run: |
89+
version=0.45.0
90+
91+
mkdir wit-bindgen
92+
cd wit-bindgen
93+
curl -o wit-bindgen.tar.gz -L https://github.com/bytecodealliance/wit-bindgen/releases/download/v$version/wit-bindgen-$version-x86_64-linux.tar.gz
94+
tar xf wit-bindgen.tar.gz
95+
echo "PATH=$PATH:`pwd`/wit-bindgen-$version-x86_64-linux" >> $GITHUB_ENV
96+
working-directory: ${{ runner.tool_cache }}
7697
- run: ./ci/regenerate.sh
7798
- run: git diff --exit-code

.gitmodules

Whitespace-only changes.

Cargo.toml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "wasi"
33
version = "0.14.4+wasi-0.2.4"
4-
authors = ["The Cranelift Project Developers"]
54
description = "WASI API bindings for Rust"
65
categories = ["no-std", "wasm"]
76
keywords = ["webassembly", "wasm"]
@@ -10,32 +9,32 @@ documentation = "https://docs.rs/wasi"
109
license.workspace = true
1110
edition.workspace = true
1211
repository.workspace = true
12+
rust-version.workspace = true
1313

1414
[workspace.package]
1515
edition = "2021"
1616
license = "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT"
1717
repository = "https://github.com/bytecodealliance/wasi-rs"
18+
rust-version = "1.82.0"
1819

1920
[workspace.dependencies]
2021
rand = { version = "0.8.5", default-features = false }
21-
wasi = { version = "0.14", path = ".", default-features = false }
22+
wasi = { version = "0.14.4", path = ".", default-features = false }
23+
wasip1 = { version = "1.0.0", path = "crates/wasip1", default-features = false }
24+
wasip2 = { version = "1.0.0", path = "crates/wasip2", default-features = false }
25+
core = { version = "1.0", package = "rustc-std-workspace-core" }
26+
alloc = { version = "1.0", package = "rustc-std-workspace-alloc" }
2227

2328
[workspace]
2429
members = ["./crates/*"]
2530

2631
[dependencies]
27-
wit-bindgen = { version = "0.45.0", default-features = false }
28-
29-
# When built as part of libstd
30-
core = { version = "1.0", optional = true, package = "rustc-std-workspace-core" }
31-
alloc = { version = "1.0", optional = true, package = "rustc-std-workspace-alloc" }
32+
wasip2 = { workspace = true }
3233

3334
[features]
34-
default = ["std", "bitflags"]
35-
std = []
36-
bitflags = ["wit-bindgen/bitflags"]
37-
# Unstable feature to support being a libstd dependency
38-
rustc-dep-of-std = ["core", "alloc", "wit-bindgen/rustc-dep-of-std"]
35+
default = ["wasip2/default"]
36+
std = ["wasip2/std"]
37+
bitflags = ["wasip2/bitflags"]
3938

4039
[[example]]
4140
name = "cli-command-no_std"

0 commit comments

Comments
 (0)