Skip to content

Commit

Permalink
Update in-tree wit-bindgen to 0.11.0 (bytecodealliance#6947)
Browse files Browse the repository at this point in the history
This only affects tests and the adapter itself, but not in any breaking
way. The tests for wasi-http are reorganized to be commands which is
also required to not have any exports currently since wit-bindgen for
Rust guests doesn't support generating bindings in one crate and
exporting in another.
  • Loading branch information
alexcrichton authored Sep 6, 2023
1 parent 6ca7493 commit e4fbf97
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 267 deletions.
171 changes: 53 additions & 118 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ io-extras = "0.18.0"
rustix = "0.38.8"
is-terminal = "0.4.0"
# wit-bindgen:
wit-bindgen = { version = "0.9.0", default-features = false }
wit-bindgen = { version = "0.11.0", default-features = false }

# wasm-tools family:
wasmparser = "0.112.0"
Expand Down Expand Up @@ -328,3 +328,10 @@ debug-assertions = false
# Omit integer overflow checks, which include failure messages which require
# string initializers.
overflow-checks = false

# Same as `wasi-preview1-component-adapter` above
[profile.dev.package.wit-bindgen]
incremental = false
debug-assertions = false
overflow-checks = false
opt-level = 's'
2 changes: 1 addition & 1 deletion crates/test-programs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn build_and_generate_tests() {

if BUILD_WASI_HTTP_TESTS {
modules_rs(&meta, "wasi-http-tests", "bin", &out_dir);
components_rs(&meta, "wasi-http-tests", "bin", &reactor_adapter, &out_dir);
components_rs(&meta, "wasi-http-tests", "bin", &command_adapter, &out_dir);
}

components_rs(&meta, "command-tests", "bin", &command_adapter, &out_dir);
Expand Down
12 changes: 8 additions & 4 deletions crates/test-programs/reactor-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
wit_bindgen::generate!("test-reactor" in "../../wasi/wit");

export_test_reactor!(T);
wit_bindgen::generate!({
world: "test-reactor",
path: "../../wasi/wit",
exports: {
world: T,
}
});

struct T;

static mut STATE: Vec<String> = Vec::new();

impl TestReactor for T {
impl Guest for T {
fn add_strings(ss: Vec<String>) -> u32 {
for s in ss {
match s.split_once("$") {
Expand Down
6 changes: 2 additions & 4 deletions crates/test-programs/tests/wasi-http-modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async fn instantiate_module(module: Module, ctx: Ctx) -> Result<(Store<Ctx>, Fun
let mut store = Store::new(&ENGINE, ctx);

let instance = linker.instantiate_async(&mut store, &module).await?;
let command = instance.get_func(&mut store, "wasi:cli/run#run").unwrap();
let command = instance.get_func(&mut store, "_start").unwrap();
Ok((store, command))
}

Expand Down Expand Up @@ -103,9 +103,7 @@ async fn run(name: &str) -> anyhow::Result<()> {
},
)
.await?;
command
.call_async(&mut store, &[], &mut [wasmtime::Val::null()])
.await
command.call_async(&mut store, &[], &mut []).await
};
r.map_err(move |trap: anyhow::Error| {
let stdout = stdout.try_into_inner().expect("single ref to stdout");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use anyhow::{Context, Result};
use anyhow::Context;
use wasi_http_tests::bindings::wasi::http::types::{Method, Scheme};

struct Component;

fn main() {}
fn main() {
wasi_http_tests::in_tokio(async { run().await })
}

async fn run() -> Result<(), ()> {
async fn run() {
let res = wasi_http_tests::request(
Method::Get,
Scheme::Http,
Expand All @@ -28,14 +28,4 @@ async fn run() -> Result<(), ()> {
"http://localhost:3000/get?some=arg&goes=here"
);
assert_eq!(res.body, b"");

Ok(())
}

impl wasi_http_tests::bindings::exports::wasi::cli::run::Run for Component {
fn run() -> Result<(), ()> {
wasi_http_tests::in_tokio(async { run().await })
}
}

wasi_http_tests::export_command_extended!(Component);
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use anyhow::Result;
use wasi_http_tests::bindings::wasi::http::types::{Method, Scheme};

struct Component;

fn main() {}
fn main() {
wasi_http_tests::in_tokio(async { run().await })
}

async fn run() -> Result<(), ()> {
async fn run() {
let res = wasi_http_tests::request(
Method::Get,
Scheme::Http,
Expand All @@ -18,14 +17,4 @@ async fn run() -> Result<(), ()> {

let error = res.unwrap_err();
assert_eq!(error.to_string(), "Error::InvalidUrl(\"invalid dnsname\")");

Ok(())
}

impl wasi_http_tests::bindings::exports::wasi::cli::run::Run for Component {
fn run() -> Result<(), ()> {
wasi_http_tests::in_tokio(async { run().await })
}
}

wasi_http_tests::export_command_extended!(Component);
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use anyhow::Result;
use wasi_http_tests::bindings::wasi::http::types::{Method, Scheme};

struct Component;

fn main() {}
fn main() {
wasi_http_tests::in_tokio(async { run().await })
}

async fn run() -> Result<(), ()> {
async fn run() {
let res = wasi_http_tests::request(
Method::Get,
Scheme::Http,
Expand All @@ -21,14 +20,4 @@ async fn run() -> Result<(), ()> {
error.to_string(),
"Error::InvalidUrl(\"invalid port value\")"
);

Ok(())
}

impl wasi_http_tests::bindings::exports::wasi::cli::run::Run for Component {
fn run() -> Result<(), ()> {
wasi_http_tests::in_tokio(async { run().await })
}
}

wasi_http_tests::export_command_extended!(Component);
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use anyhow::Result;
use wasi_http_tests::bindings::wasi::http::types::{Method, Scheme};

struct Component;

fn main() {}
fn main() {
wasi_http_tests::in_tokio(async { run().await })
}

async fn run() -> Result<(), ()> {
async fn run() {
let res = wasi_http_tests::request(
Method::Connect,
Scheme::Http,
Expand All @@ -27,14 +26,4 @@ async fn run() -> Result<(), ()> {
or `"Error::ProtocolError(\"operation was canceled\")"`)"#
)
}

Ok(())
}

impl wasi_http_tests::bindings::exports::wasi::cli::run::Run for Component {
fn run() -> Result<(), ()> {
wasi_http_tests::in_tokio(async { run().await })
}
}

wasi_http_tests::export_command_extended!(Component);
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use anyhow::{Context, Result};
use anyhow::Context;
use wasi_http_tests::bindings::wasi::http::types::{Method, Scheme};

struct Component;

fn main() {}
fn main() {
wasi_http_tests::in_tokio(async { run().await })
}

async fn run() -> Result<(), ()> {
async fn run() {
let res = wasi_http_tests::request(
Method::Post,
Scheme::Http,
Expand All @@ -23,14 +23,4 @@ async fn run() -> Result<(), ()> {
let method = res.header("x-wasmtime-test-method").unwrap();
assert_eq!(std::str::from_utf8(method).unwrap(), "POST");
assert_eq!(res.body, b"{\"foo\": \"bar\"}");

Ok(())
}

impl wasi_http_tests::bindings::exports::wasi::cli::run::Run for Component {
fn run() -> Result<(), ()> {
wasi_http_tests::in_tokio(async { run().await })
}
}

wasi_http_tests::export_command_extended!(Component);
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use wasi_http_tests::bindings::wasi::http::types::{Method, Scheme};

struct Component;

fn main() {}
fn main() {
wasi_http_tests::in_tokio(async { run().await })
}

async fn run() -> Result<(), ()> {
async fn run() {
const LEN: usize = 4000;
let mut buffer = [0; LEN];
io::repeat(0b001).read_exact(&mut buffer).unwrap();
Expand All @@ -27,14 +29,4 @@ async fn run() -> Result<(), ()> {
let method = res.header("x-wasmtime-test-method").unwrap();
assert_eq!(std::str::from_utf8(method).unwrap(), "POST");
assert_eq!(res.body.len(), LEN);

Ok(())
}

impl wasi_http_tests::bindings::exports::wasi::cli::run::Run for Component {
fn run() -> Result<(), ()> {
wasi_http_tests::in_tokio(async { run().await })
}
}

wasi_http_tests::export_command_extended!(Component);
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use anyhow::{Context, Result};
use anyhow::Context;
use wasi_http_tests::bindings::wasi::http::types::{Method, Scheme};

struct Component;

fn main() {}
fn main() {
wasi_http_tests::in_tokio(async { run().await })
}

async fn run() -> Result<(), ()> {
async fn run() {
let res = wasi_http_tests::request(
Method::Put,
Scheme::Http,
Expand All @@ -23,14 +23,4 @@ async fn run() -> Result<(), ()> {
let method = res.header("x-wasmtime-test-method").unwrap();
assert_eq!(std::str::from_utf8(method).unwrap(), "PUT");
assert_eq!(res.body, b"");

Ok(())
}

impl wasi_http_tests::bindings::exports::wasi::cli::run::Run for Component {
fn run() -> Result<(), ()> {
wasi_http_tests::in_tokio(async { run().await })
}
}

wasi_http_tests::export_command_extended!(Component);
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use anyhow::Result;
use wasi_http_tests::bindings::wasi::http::types::{Method, Scheme};

struct Component;

fn main() {}
fn main() {
wasi_http_tests::in_tokio(async { run().await })
}

async fn run() -> Result<(), ()> {
async fn run() {
let res = wasi_http_tests::request(
Method::Other("OTHER".to_owned()),
Scheme::Http,
Expand All @@ -21,14 +20,4 @@ async fn run() -> Result<(), ()> {
error.to_string(),
"Error::InvalidUrl(\"unknown method OTHER\")"
);

Ok(())
}

impl wasi_http_tests::bindings::exports::wasi::cli::run::Run for Component {
fn run() -> Result<(), ()> {
wasi_http_tests::in_tokio(async { run().await })
}
}

wasi_http_tests::export_command_extended!(Component);
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use anyhow::Result;
use wasi_http_tests::bindings::wasi::http::types::{Method, Scheme};

struct Component;

fn main() {}
fn main() {
wasi_http_tests::in_tokio(async { run().await })
}

async fn run() -> Result<(), ()> {
async fn run() {
let res = wasi_http_tests::request(
Method::Get,
Scheme::Other("WS".to_owned()),
Expand All @@ -21,14 +20,4 @@ async fn run() -> Result<(), ()> {
error.to_string(),
"Error::InvalidUrl(\"unsupported scheme WS\")"
);

Ok(())
}

impl wasi_http_tests::bindings::exports::wasi::cli::run::Run for Component {
fn run() -> Result<(), ()> {
wasi_http_tests::in_tokio(async { run().await })
}
}

wasi_http_tests::export_command_extended!(Component);
4 changes: 2 additions & 2 deletions crates/test-programs/wasi-http-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pub mod bindings {
wit_bindgen::generate!({
path: "../../wasi-http/wit",
world: "wasmtime:wasi/command-extended",
macro_call_prefix: "::wasi_http_tests::bindings::",
macro_export,
// macro_call_prefix: "::wasi_http_tests::bindings::",
// macro_export,
});
}

Expand Down
2 changes: 0 additions & 2 deletions crates/wasi-http/wit/command-extended.wit
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ world command-extended {
import wasi:cli/terminal-stdout
import wasi:cli/terminal-stderr

export wasi:cli/run

// We should replace all others with `include self.command`
// as soon as the unioning of worlds is available:
// https://github.com/WebAssembly/component-model/issues/169
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-preview1-component-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ compile_error!("only one of the `command` and `reactor` features may be selected
mod macros;

mod descriptors;
use crate::descriptors::{Descriptor, Descriptors, IsATTY, StreamType, Streams};
use crate::descriptors::{Descriptor, Descriptors, StreamType, Streams};

pub mod bindings {
#[cfg(feature = "command")]
Expand Down
2 changes: 0 additions & 2 deletions crates/wasi/wit/command-extended.wit
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ world command-extended {
import wasi:cli/terminal-stdout
import wasi:cli/terminal-stderr

export wasi:cli/run

// We should replace all others with `include self.command`
// as soon as the unioning of worlds is available:
// https://github.com/WebAssembly/component-model/issues/169
Expand Down
Loading

0 comments on commit e4fbf97

Please sign in to comment.