Skip to content

Commit 8788924

Browse files
committed
Add a wasip3 crate alongside others
This refactors the repository to move the WASIp2 WITs into the `wasip2` crate itself. A new `wasip3` crate is added and the CI scripts are updated to generate that crate as well. The `wasip3` crate is heavily reused from the `wasip2` crate with minor changes here and there.
1 parent 4ae7014 commit 8788924

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+20112
-18
lines changed

.gitattributes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# These are generated by `wit-bindgen`
2-
src/bindings.rs linguist-generated=true
2+
src/imports.rs linguist-generated=true
33
src/proxy.rs linguist-generated=true
44
src/command.rs linguist-generated=true
55

6+
lib_generated.rs linguist-generated=true
7+
68
# This is copied from other repos so diffs aren't super interesting by default
79
wit/deps linguist-generated=true

.github/workflows/main.yml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ jobs:
4040

4141
- run: cargo build -p wasip2 --examples --target wasm32-unknown-unknown --no-default-features
4242
- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/http_proxy_no_std.wasm -o component.wasm
43-
- run: wasm-tools component targets wit component.wasm -w wasi:http/proxy
43+
- run: wasm-tools component targets ./crates/wasip2/wit component.wasm -w wasi:http/proxy
4444

4545
- run: cargo build -p wasip2 --examples --target wasm32-unknown-unknown
4646
- 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
47+
- run: wasm-tools component targets ./crates/wasip2/wit component.wasm -w wasi:http/proxy
4848

4949
- run: cargo build -p wasi-ext --examples --target wasm32-wasip2 --features rand
5050
- run: wasmtime run ./target/wasm32-wasip2/debug/examples/rand.wasm
@@ -55,7 +55,12 @@ jobs:
5555
strategy:
5656
matrix:
5757
rust: [msrv, stable, beta, nightly]
58-
crate: [wasi, wasip1, wasip2]
58+
crate: [wasi, wasip1, wasip2, wasip3]
59+
exclude:
60+
# wasip3 bindings require a newer rust feature than msrv currently
61+
# allows.
62+
- rust: msrv
63+
crate: wasip3
5964
steps:
6065
- uses: actions/checkout@v5
6166
- uses: ./.github/actions/install-rust
@@ -96,3 +101,40 @@ jobs:
96101
working-directory: ${{ runner.tool_cache }}
97102
- run: ./ci/regenerate.sh
98103
- run: git diff --exit-code
104+
105+
test_wasip3:
106+
name: Test WASIp3 on ${{ matrix.rust }}
107+
runs-on: ubuntu-latest
108+
strategy:
109+
matrix:
110+
rust: [stable, beta, nightly]
111+
exclude:
112+
# rust stable is not yet new enough to support the
113+
# component-model-async features needed for testing, so temporarily
114+
# exclude it.
115+
- rust: stable
116+
steps:
117+
- uses: actions/checkout@v5
118+
- uses: ./.github/actions/install-rust
119+
with:
120+
toolchain: ${{ matrix.rust }}
121+
- run: rustup target add wasm32-wasip2 wasm32-unknown-unknown
122+
- run: |
123+
version=dev
124+
125+
mkdir wasmtime
126+
cd wasmtime
127+
curl -o wasmtime.tar.xz -L https://github.com/bytecodealliance/wasmtime/releases/download/$version/wasmtime-$version-x86_64-linux.tar.xz
128+
tar xf wasmtime.tar.xz
129+
echo "PATH=$PATH:`pwd`/wasmtime-$version-x86_64-linux" >> $GITHUB_ENV
130+
- name: Install wasm-tools
131+
uses: bytecodealliance/actions/wasm-tools/setup@v1
132+
with:
133+
version: "1.238.1"
134+
135+
- run: cargo build -p wasip3 --examples --target wasm32-wasip2
136+
- run: wasmtime run -Sp3 -Wcomponent-model-async ./target/wasm32-wasip2/debug/examples/cli_command.wasm
137+
138+
- run: cargo build -p wasip3 --examples --target wasm32-unknown-unknown
139+
- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/http_proxy.wasm -o component.wasm
140+
- run: wasm-tools component targets ./crates/wasip3/wit component.wasm -w wasi:http/proxy

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ rust-version = "1.82.0"
2020
[workspace.dependencies]
2121
rand = { version = "0.8.5", default-features = false }
2222
wasi = { version = "0.14.4", path = ".", default-features = false }
23+
wit-bindgen = { version = "0.45.0", default-features = false }
2324
wasip1 = { version = "1.0.0", path = "crates/wasip1", default-features = false }
2425
wasip2 = { version = "1.0.0", path = "crates/wasip2", default-features = false }
26+
wasip3 = { version = "0.1.0", path = "crates/wasip3", default-features = false }
2527
core = { version = "1.0", package = "rustc-std-workspace-core" }
2628
alloc = { version = "1.0", package = "rustc-std-workspace-alloc" }
2729

ci/regenerate.sh

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ set -ex
55
generate() {
66
file="$1"
77
shift
8-
wit-bindgen rust wit --out-dir crates/wasip2/src --std-feature "$@" --format
8+
wit-bindgen rust "$@" --format
9+
}
10+
11+
# ==============================================================================
12+
# WASIp2 bindings
13+
14+
generate_p2() {
15+
file="$1"
16+
17+
generate "$@" --std-feature ./crates/wasip2/wit --out-dir crates/wasip2/src
918

1019
sed -z -i 's/#\[unsafe(\n link_section = "\(.*\)"\n)\]/\
1120
#[cfg_attr(feature = "rustc-dep-of-std", unsafe(link_section = "\1-in-libstd"))]\
@@ -15,7 +24,8 @@ generate() {
1524

1625
# Generate the main body of the bindings which includes all imports from the two
1726
# worlds below.
18-
generate crates/wasip2/src/imports.rs --type-section-suffix rust-wasi-from-crates-io \
27+
generate_p2 crates/wasip2/src/imports.rs \
28+
--type-section-suffix rust-wasi-from-crates-io \
1929
--generate-all \
2030
--world wasi:cli/imports
2131

@@ -50,7 +60,7 @@ with="$with,wasi:sockets/tcp-create-socket@0.2.4=crate::sockets::tcp_create_sock
5060
with="$with,wasi:sockets/udp@0.2.4=crate::sockets::udp"
5161
with="$with,wasi:sockets/udp-create-socket@0.2.4=crate::sockets::udp_create_socket"
5262
with="$with,wasi:sockets/ip-name-lookup@0.2.4=crate::sockets::ip_name_lookup"
53-
generate crates/wasip2/src/command.rs \
63+
generate_p2 crates/wasip2/src/command.rs \
5464
--world wasi:cli/command \
5565
--with "$with" \
5666
--type-section-suffix rust-wasi-from-crates-io-command-world \
@@ -68,7 +78,61 @@ with="$with,wasi:io/error@0.2.4=crate::io::error"
6878
with="$with,wasi:io/poll@0.2.4=crate::io::poll"
6979
with="$with,wasi:io/streams@0.2.4=crate::io::streams"
7080
with="$with,wasi:random/random@0.2.4=crate::random::random"
71-
generate crates/wasip2/src/proxy.rs \
81+
generate_p2 crates/wasip2/src/proxy.rs \
82+
--world wasi:http/proxy \
83+
--with "$with" \
84+
--type-section-suffix rust-wasi-from-crates-io-proxy-world \
85+
--default-bindings-module '$crate' \
86+
--pub-export-macro \
87+
--export-macro-name _export_proxy
88+
89+
# ==============================================================================
90+
# WASIp3 bindings
91+
92+
generate_p3() {
93+
generate "$@" ./crates/wasip3/wit --out-dir crates/wasip3/src
94+
}
95+
96+
generate_p3 crates/wasip3/src/imports.rs \
97+
--type-section-suffix rust-wasi-from-crates-io \
98+
--generate-all \
99+
--world wasi:cli/imports
100+
101+
with="wasi:cli/environment@0.3.0-rc-2025-08-15=crate::cli::environment"
102+
with="$with,wasi:cli/exit@0.3.0-rc-2025-08-15=crate::cli::exit"
103+
with="$with,wasi:cli/stdin@0.3.0-rc-2025-08-15=crate::cli::stdin"
104+
with="$with,wasi:cli/stdout@0.3.0-rc-2025-08-15=crate::cli::stdout"
105+
with="$with,wasi:cli/stderr@0.3.0-rc-2025-08-15=crate::cli::stderr"
106+
with="$with,wasi:cli/terminal-input@0.3.0-rc-2025-08-15=crate::cli::terminal_input"
107+
with="$with,wasi:cli/terminal-output@0.3.0-rc-2025-08-15=crate::cli::terminal_output"
108+
with="$with,wasi:cli/terminal-stdin@0.3.0-rc-2025-08-15=crate::cli::terminal_stdin"
109+
with="$with,wasi:cli/terminal-stdout@0.3.0-rc-2025-08-15=crate::cli::terminal_stdout"
110+
with="$with,wasi:cli/terminal-stderr@0.3.0-rc-2025-08-15=crate::cli::terminal_stderr"
111+
with="$with,wasi:clocks/monotonic-clock@0.3.0-rc-2025-08-15=crate::clocks::monotonic_clock"
112+
with="$with,wasi:clocks/wall-clock@0.3.0-rc-2025-08-15=crate::clocks::wall_clock"
113+
with="$with,wasi:filesystem/types@0.3.0-rc-2025-08-15=crate::filesystem::types"
114+
with="$with,wasi:filesystem/preopens@0.3.0-rc-2025-08-15=crate::filesystem::preopens"
115+
with="$with,wasi:random/random@0.3.0-rc-2025-08-15=crate::random::random"
116+
with="$with,wasi:random/insecure@0.3.0-rc-2025-08-15=crate::random::insecure"
117+
with="$with,wasi:random/insecure-seed@0.3.0-rc-2025-08-15=crate::random::insecure_seed"
118+
with="$with,wasi:sockets/types@0.3.0-rc-2025-08-15=crate::sockets::types"
119+
with="$with,wasi:sockets/ip-name-lookup@0.3.0-rc-2025-08-15=crate::sockets::ip_name_lookup"
120+
generate_p3 crates/wasip3/src/command.rs \
121+
--world wasi:cli/command \
122+
--with "$with" \
123+
--type-section-suffix rust-wasi-from-crates-io-command-world \
124+
--default-bindings-module '$crate' \
125+
--pub-export-macro \
126+
--async 'wasi:cli/run@0.3.0-rc-2025-08-15#run' \
127+
--export-macro-name _export_command
128+
129+
with="wasi:cli/stdin@0.3.0-rc-2025-08-15=crate::cli::stdin"
130+
with="$with,wasi:cli/stdout@0.3.0-rc-2025-08-15=crate::cli::stdout"
131+
with="$with,wasi:cli/stderr@0.3.0-rc-2025-08-15=crate::cli::stderr"
132+
with="$with,wasi:clocks/monotonic-clock@0.3.0-rc-2025-08-15=crate::clocks::monotonic_clock"
133+
with="$with,wasi:clocks/wall-clock@0.3.0-rc-2025-08-15=crate::clocks::wall_clock"
134+
with="$with,wasi:random/random@0.3.0-rc-2025-08-15=crate::random::random"
135+
generate_p3 crates/wasip3/src/proxy.rs \
72136
--world wasi:http/proxy \
73137
--with "$with" \
74138
--type-section-suffix rust-wasi-from-crates-io-proxy-world \

ci/vendor-wit.sh

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,28 @@ set -ex
1313
# https://github.com/WebAssembly/wasi-$repo
1414
# and every repository has a tag `v$tag` here. That is currently done as part
1515
# of the WASI release process.
16-
repos="cli clocks filesystem http io random sockets"
1716
tag=0.2.4
1817
dst=wit/deps
1918

20-
rm -rf $dst
21-
mkdir -p $dst
19+
vendor() {
20+
dst="$1"
21+
tag="$2"
22+
subdir="$3"
23+
repos="$4"
2224

23-
for repo in $repos; do
24-
mkdir $dst/$repo
25-
curl -L https://github.com/WebAssembly/wasi-$repo/archive/refs/tags/v$tag.tar.gz | \
26-
tar xzf - --strip-components=2 -C $dst/$repo wasi-$repo-$tag/wit
27-
rm -rf $dst/$repo/deps*
28-
done
25+
rm -rf $dst
26+
mkdir -p $dst
27+
28+
for repo in $repos; do
29+
mkdir $dst/$repo
30+
curl -L https://github.com/WebAssembly/wasi-$repo/archive/refs/tags/v$tag.tar.gz | \
31+
tar xzf - --strip-components=2 -C $dst/$repo wasi-$repo-$tag/$subdir
32+
rm -rf $dst/$repo/deps*
33+
done
34+
}
35+
36+
vendor crates/wasip2/wit/deps 0.2.4 wit "cli clocks filesystem http io random sockets"
37+
vendor crates/wasip3/wit/deps 0.3.0-rc-2025-08-15 wit-0.3.0-draft "cli clocks filesystem http random sockets"
2938

3039
# WASIp1 vendoring logic
3140
wasip1_rev="0ba0c5e2"

crates/wasip2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repository.workspace = true
1212
rust-version.workspace = true
1313

1414
[dependencies]
15-
wit-bindgen = { version = "0.45.0", default-features = false }
15+
wit-bindgen = { workspace = true }
1616

1717
# When built as part of libstd
1818
core = { optional = true, workspace = true }
File renamed without changes.

0 commit comments

Comments
 (0)