Skip to content

Commit e62af39

Browse files
authored
Update to wit-bindgen 0.20.0 (#80)
* Update to wit-bindgen 0.20.0 This commit updates the bindings generator to 0.20.0 and refactors the existing support for exporting macros to use the new features of 0.20.0 as well. The `macros` crate feature is now no longer required (yay!) and all the traits to implement are already present in the crate now. * Add more generated files to gitattributes * Remove macros feature from CI * Fix regenerate script * Rename macros back to their old names * Document some internal structure * More internal comments * Rename command macro * Fix doc test
1 parent ded1722 commit e62af39

File tree

11 files changed

+4633
-3431
lines changed

11 files changed

+4633
-3431
lines changed

.gitattributes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# This is generated by `wit-bindgen`
1+
# These are generated by `wit-bindgen`
22
src/bindings.rs linguist-generated=true
3+
src/proxy.rs linguist-generated=true
4+
src/command.rs linguist-generated=true
35

46
# This is copied from other repos so diffs aren't super interesting by default
57
wit/deps linguist-generated=true

.github/workflows/main.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
- run: cargo build --no-default-features
1818
- run: cargo build --target wasm32-wasi
1919
- run: cargo build --target wasm32-wasi --no-default-features
20+
- run: cargo test --doc
2021
- name: Install Wasmtime
2122
uses: bytecodealliance/actions/wasmtime/setup@v1
2223
with:
@@ -29,7 +30,7 @@ jobs:
2930
- run: curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v17.0.0/wasi_snapshot_preview1.command.wasm
3031
- run: wasm-tools component new ./target/wasm32-wasi/debug/examples/hello-world.wasm --adapt ./wasi_snapshot_preview1.command.wasm -o component.wasm
3132
- run: wasmtime run component.wasm
32-
- run: cargo build --examples --target wasm32-unknown-unknown --features macros
33+
- run: cargo build --examples --target wasm32-unknown-unknown
3334
- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/cli_command.wasm -o component.wasm
3435
- run: wasmtime run component.wasm
3536
- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/http_proxy.wasm -o component.wasm
@@ -52,6 +53,6 @@ jobs:
5253
- uses: actions/checkout@v4
5354
- name: Install Rust
5455
run: rustup update stable && rustup default stable
55-
- run: cargo install wit-bindgen-cli@0.19.2 --locked
56+
- run: cargo install wit-bindgen-cli@0.20.0 --locked
5657
- run: ./ci/regenerate.sh
5758
- run: git diff --exit-code

Cargo.toml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,26 @@ readme = "README.md"
1212
documentation = "https://docs.rs/wasi"
1313

1414
[dependencies]
15-
wit-bindgen = { version = "0.19.1", default-features = false, features = ['realloc'] }
15+
wit-bindgen = { version = "0.20.0", default-features = false, features = ['realloc'] }
1616

1717
# When built as part of libstd
1818
compiler_builtins = { version = "0.1", optional = true }
1919
core = { version = "1.0", optional = true, package = "rustc-std-workspace-core" }
2020
rustc-std-workspace-alloc = { version = "1.0", optional = true }
2121

22-
[build-dependencies]
23-
quote = { version = "1.0", optional = true }
24-
2522
[features]
2623
default = ["std"]
2724
std = []
28-
macros = ["quote", "wit-bindgen/macros"]
2925
# Unstable feature to support being a libstd dependency
3026
rustc-dep-of-std = ["compiler_builtins", "core", "rustc-std-workspace-alloc"]
3127

32-
[package.metadata.docs.rs]
33-
features = ["macros"]
34-
3528
[[example]]
3629
name = "cli-command"
3730
crate-type = ["cdylib"]
38-
required-features = ["macros"]
3931

4032
[[example]]
4133
name = "http-proxy"
4234
crate-type = ["cdylib"]
43-
required-features = ["macros"]
4435

4536
[badges]
46-
maintenance = { status = "experimental" }
37+
maintenance = { status = "experimental" }

build.rs

Lines changed: 0 additions & 105 deletions
This file was deleted.

ci/regenerate.sh

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,81 @@
22

33
set -ex
44

5-
wit-bindgen rust wit --out-dir src --std-feature --type-section-suffix rust-wasi-from-crates-io
5+
generate() {
6+
file="$1"
7+
shift
8+
wit-bindgen rust wit --out-dir src --std-feature "$@"
69

7-
# rustfmt chokes on the raw output of wit-bindgen right now due to trailling
8-
# whitespace (unsure as to why), so format it with some options first to get it
9-
# into a better state before applying the final format with default options
10-
# which gets this to succeed.
10+
# rustfmt chokes on the raw output of wit-bindgen right now due to trailling
11+
# whitespace (unsure as to why), so format it with some options first to get it
12+
# into a better state before applying the final format with default options
13+
# which gets this to succeed.
14+
#
15+
# NB: this should be considered a bug in wit-bindgen that this is required to do
16+
# twice. Passing `--rustfmt` to `wit-bindgen` should work.
17+
rustfmt $file --edition 2021 --config-path ./ci/rustfmt-bindings.toml
18+
rustfmt $file --edition 2021
19+
}
20+
21+
# Generate the main body of the bindings which includes all imports from the two
22+
# worlds below.
23+
generate src/bindings.rs --type-section-suffix rust-wasi-from-crates-io
24+
25+
# Generate bindings for the `wasi:cli/command` world specifically, namely the
26+
# macro `export_command`.
1127
#
12-
# NB: this should be considered a bug in wit-bindgen that this is required to do
13-
# twice. Passing `--rustfmt` to `wit-bindgen` should work.
14-
rustfmt src/bindings.rs --edition 2021 --config-path ./ci/rustfmt-bindings.toml
15-
rustfmt src/bindings.rs --edition 2021
28+
# Note that `--with` is used to point at the previously generated bindings.
29+
with="wasi:cli/[email protected]=crate::cli::environment"
30+
with="$with,wasi:cli/[email protected]=crate::cli::exit"
31+
with="$with,wasi:cli/[email protected]=crate::cli::stdin"
32+
with="$with,wasi:cli/[email protected]=crate::cli::stdout"
33+
with="$with,wasi:cli/[email protected]=crate::cli::stderr"
34+
with="$with,wasi:cli/[email protected]=crate::cli::terminal_input"
35+
with="$with,wasi:cli/[email protected]=crate::cli::terminal_output"
36+
with="$with,wasi:cli/[email protected]=crate::cli::terminal_stdin"
37+
with="$with,wasi:cli/[email protected]=crate::cli::terminal_stdout"
38+
with="$with,wasi:cli/[email protected]=crate::cli::terminal_stderr"
39+
with="$with,wasi:clocks/[email protected]=crate::clocks::monotonic_clock"
40+
with="$with,wasi:clocks/[email protected]=crate::clocks::wall_clock"
41+
with="$with,wasi:filesystem/[email protected]=crate::filesystem::types"
42+
with="$with,wasi:filesystem/[email protected]=crate::filesystem::preopens"
43+
with="$with,wasi:io/[email protected]=crate::io::error"
44+
with="$with,wasi:io/[email protected]=crate::io::poll"
45+
with="$with,wasi:io/[email protected]=crate::io::streams"
46+
with="$with,wasi:random/[email protected]=crate::random::random"
47+
with="$with,wasi:random/[email protected]=crate::random::insecure"
48+
with="$with,wasi:random/[email protected]=crate::random::insecure_seed"
49+
with="$with,wasi:sockets/[email protected]=crate::sockets::network"
50+
with="$with,wasi:sockets/[email protected]=crate::sockets::instance_network"
51+
with="$with,wasi:sockets/[email protected]=crate::sockets::tcp"
52+
with="$with,wasi:sockets/[email protected]=crate::sockets::tcp_create_socket"
53+
with="$with,wasi:sockets/[email protected]=crate::sockets::udp"
54+
with="$with,wasi:sockets/[email protected]=crate::sockets::udp_create_socket"
55+
with="$with,wasi:sockets/[email protected]=crate::sockets::ip_name_lookup"
56+
generate src/command.rs \
57+
--world wasi:cli/command \
58+
--with "$with" \
59+
--type-section-suffix rust-wasi-from-crates-io-command-world \
60+
--default-bindings-module wasi \
61+
--pub-export-macro \
62+
--export-macro-name _export_command
63+
64+
# Same as the `command` world, but for the proxy world.
65+
with="wasi:cli/[email protected]=crate::cli::stdin"
66+
with="$with,wasi:cli/[email protected]=crate::cli::stdout"
67+
with="$with,wasi:cli/[email protected]=crate::cli::stderr"
68+
with="$with,wasi:clocks/[email protected]=crate::clocks::monotonic_clock"
69+
with="$with,wasi:clocks/[email protected]=crate::clocks::wall_clock"
70+
with="$with,wasi:io/[email protected]=crate::io::error"
71+
with="$with,wasi:io/[email protected]=crate::io::poll"
72+
with="$with,wasi:io/[email protected]=crate::io::streams"
73+
with="$with,wasi:random/[email protected]=crate::random::random"
74+
with="$with,wasi:http/[email protected]=crate::http::types"
75+
with="$with,wasi:http/[email protected]=crate::http::outgoing_handler"
76+
generate src/proxy.rs \
77+
--world wasi:http/proxy \
78+
--with "$with" \
79+
--type-section-suffix rust-wasi-from-crates-io-proxy-world \
80+
--default-bindings-module wasi \
81+
--pub-export-macro \
82+
--export-macro-name _export_proxy

examples/cli-command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
wasi::cli::run::export!(Example);
1+
wasi::cli::command::export!(Example);
22

33
struct Example;
44

5-
impl exports::wasi::cli::run::Guest for Example {
5+
impl wasi::exports::cli::run::Guest for Example {
66
fn run() -> Result<(), ()> {
77
let stdout = wasi::cli::stdout::get_stdout();
88
stdout.blocking_write_and_flush(b"Hello, WASI!").unwrap();

examples/http-proxy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use wasi::http::types::{
22
Fields, IncomingRequest, OutgoingBody, OutgoingResponse, ResponseOutparam,
33
};
44

5-
wasi::http::incoming_handler::export!(Example);
5+
wasi::http::proxy::export!(Example);
66

77
struct Example;
88

9-
impl exports::wasi::http::incoming_handler::Guest for Example {
9+
impl wasi::exports::http::incoming_handler::Guest for Example {
1010
fn handle(_request: IncomingRequest, response_out: ResponseOutparam) {
1111
let resp = OutgoingResponse::new(Fields::new());
1212
let body = resp.body().unwrap();

0 commit comments

Comments
 (0)