Skip to content

Commit 7a28de9

Browse files
authored
update and fix examples (#120)
An earlier commit which updated various dependencies (most notably, Wasmtime) unmasked a bug in `add_wasi_and_stubs` such that we were overwriting the host functions added by `wasmtime-wasi` with trapping stubs. This wasn't a problem previously because there was only one version of WASIp2: 0.2.0. Now that we have 0.2.1, 0.2.2, etc., with corresponding support in Wasmtime, we need to be a bit more careful. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent e92b223 commit 7a28de9

File tree

9 files changed

+59
-42
lines changed

9 files changed

+59
-42
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "componentize-py"
3-
version = "0.15.0"
3+
version = "0.15.1"
44
edition = "2021"
55
exclude = ["cpython"]
66

examples/cli/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ run a Python-based component targetting the [wasi-cli] `command` world.
99

1010
## Prerequisites
1111

12-
* `Wasmtime` 18.0.0 or later
13-
* `componentize-py` 0.15.0
12+
* `Wasmtime` 26.0.0 or later
13+
* `componentize-py` 0.15.1
1414

1515
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
1616
you don't have `cargo`, you can download and install from
17-
https://github.com/bytecodealliance/wasmtime/releases/tag/v18.0.0.
17+
https://github.com/bytecodealliance/wasmtime/releases/tag/v26.0.0.
1818

1919
```
20-
cargo install --version 18.0.0 wasmtime-cli
21-
pip install componentize-py==0.15.0
20+
cargo install --version 26.0.0 wasmtime-cli
21+
pip install componentize-py==0.15.1
2222
```
2323

2424
## Running the demo

examples/http/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ run a Python-based component targetting the [wasi-http] `proxy` world.
99

1010
## Prerequisites
1111

12-
* `Wasmtime` 18.0.0 or later
13-
* `componentize-py` 0.15.0
12+
* `Wasmtime` 26.0.0 or later
13+
* `componentize-py` 0.15.1
1414

1515
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
1616
you don't have `cargo`, you can download and install from
17-
https://github.com/bytecodealliance/wasmtime/releases/tag/v18.0.0.
17+
https://github.com/bytecodealliance/wasmtime/releases/tag/v26.0.0.
1818

1919
```
20-
cargo install --version 18.0.0 wasmtime-cli
21-
pip install componentize-py==0.15.0
20+
cargo install --version 26.0.0 wasmtime-cli
21+
pip install componentize-py==0.15.1
2222
```
2323

2424
## Running the demo

examples/matrix-math/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ within a guest component.
1010

1111
## Prerequisites
1212

13-
* `wasmtime` 18.0.0 or later
14-
* `componentize-py` 0.15.0
13+
* `wasmtime` 26.0.0 or later
14+
* `componentize-py` 0.15.1
1515
* `NumPy`, built for WASI
1616

1717
Note that we use an unofficial build of NumPy since the upstream project does
1818
not yet publish WASI builds.
1919

2020
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
2121
you don't have `cargo`, you can download and install from
22-
https://github.com/bytecodealliance/wasmtime/releases/tag/v18.0.0.
22+
https://github.com/bytecodealliance/wasmtime/releases/tag/v26.0.0.
2323

2424
```
25-
cargo install --version 18.0.0 wasmtime-cli
26-
pip install componentize-py==0.15.0
25+
cargo install --version 26.0.0 wasmtime-cli
26+
pip install componentize-py==0.15.1
2727
curl -OL https://github.com/dicej/wasi-wheels/releases/download/v0.0.1/numpy-wasi.tar.gz
2828
tar xf numpy-wasi.tar.gz
2929
```

examples/sandbox/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ sandboxed Python code snippets from within a Python app.
77

88
## Prerequisites
99

10-
* `wasmtime-py` 18.0.0 or later
11-
* `componentize-py` 0.15.0
10+
* `wasmtime-py` 25.0.0 or later
11+
* `componentize-py` 0.15.1
1212

1313
```
14-
pip install componentize-py==0.15.0 wasmtime==18.0.2
14+
pip install componentize-py==0.15.1 wasmtime==25.0.0
1515
```
1616

1717
## Running the demo

examples/tcp/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ making an outbound TCP request using `wasi-sockets`.
1010

1111
## Prerequisites
1212

13-
* `Wasmtime` 18.0.0 or later
14-
* `componentize-py` 0.15.0
13+
* `Wasmtime` 26.0.0 or later
14+
* `componentize-py` 0.15.1
1515

1616
Below, we use [Rust](https://rustup.rs/)'s `cargo` to install `Wasmtime`. If
1717
you don't have `cargo`, you can download and install from
18-
https://github.com/bytecodealliance/wasmtime/releases/tag/v18.0.0.
18+
https://github.com/bytecodealliance/wasmtime/releases/tag/v26.0.0.
1919

2020
```
21-
cargo install --version 18.0.0 wasmtime-cli
22-
pip install componentize-py==0.15.0
21+
cargo install --version 26.0.0 wasmtime-cli
22+
pip install componentize-py==0.15.1
2323
```
2424

2525
## Running the demo

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ features = ["pyo3/extension-module"]
77

88
[project]
99
name = "componentize-py"
10-
version = "0.15.0"
10+
version = "0.15.1"
1111
description = "Tool to package Python applications as WebAssembly components"
1212
readme = "README.md"
1313
license = { file = "LICENSE" }

src/lib.rs

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -601,25 +601,32 @@ fn add_wasi_and_stubs(
601601

602602
for (interface_name, stubs) in stubs {
603603
if let Some(interface_name) = interface_name {
604-
if let Ok(mut instance) = linker.instance(&interface_name) {
605-
for stub in stubs {
606-
let interface_name = interface_name.clone();
607-
match stub {
608-
Stub::Function(name) => instance.func_new(name, {
609-
let name = name.clone();
610-
move |_, _, _| {
611-
Err(anyhow!("called trapping stub: {interface_name}#{name}"))
612-
}
613-
}),
614-
Stub::Resource(name) => instance
615-
.resource(name, ResourceType::host::<()>(), {
604+
// Note that we do _not_ stub interfaces which appear to be part of WASIp2 since those should be
605+
// provided by the `wasmtime_wasi::add_to_linker_async` call above, and adding stubs to those same
606+
// interfaces would just cause trouble.
607+
if !is_wasip2_cli(&interface_name) {
608+
if let Ok(mut instance) = linker.instance(&interface_name) {
609+
for stub in stubs {
610+
let interface_name = interface_name.clone();
611+
match stub {
612+
Stub::Function(name) => instance.func_new(name, {
616613
let name = name.clone();
617-
move |_, _| {
614+
move |_, _, _| {
618615
Err(anyhow!("called trapping stub: {interface_name}#{name}"))
619616
}
620-
})
621-
.map(drop),
622-
}?;
617+
}),
618+
Stub::Resource(name) => instance
619+
.resource(name, ResourceType::host::<()>(), {
620+
let name = name.clone();
621+
move |_, _| {
622+
Err(anyhow!(
623+
"called trapping stub: {interface_name}#{name}"
624+
))
625+
}
626+
})
627+
.map(drop),
628+
}?;
629+
}
623630
}
624631
}
625632
} else {
@@ -643,3 +650,13 @@ fn add_wasi_and_stubs(
643650

644651
Ok(())
645652
}
653+
654+
fn is_wasip2_cli(interface_name: &str) -> bool {
655+
(interface_name.starts_with("wasi:cli/")
656+
|| interface_name.starts_with("wasi:clocks/")
657+
|| interface_name.starts_with("wasi:random/")
658+
|| interface_name.starts_with("wasi:io/")
659+
|| interface_name.starts_with("wasi:filesystem/")
660+
|| interface_name.starts_with("wasi:sockets/"))
661+
&& interface_name.contains("@0.2.")
662+
}

0 commit comments

Comments
 (0)