Skip to content

Commit c6c8447

Browse files
authored
add host instructions to README.md example (#90)
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent 013d51b commit c6c8447

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ If you're using an IDE or just want to examine the bindings produced for the WIT
3939
world, you can generate them using the `bindings` subcommand:
4040

4141
```shell
42-
componentize-py -d hello.wit -w hello bindings .
42+
componentize-py -d hello.wit -w hello bindings hello_guest
4343
```
4444

4545
Then, use the `hello` module produced by the command above to write your app:
@@ -56,7 +56,38 @@ EOF
5656
And finally generate the component:
5757

5858
```shell
59-
componentize-py -d hello.wit -w hello componentize app -o app.wasm
59+
componentize-py -d hello.wit -w hello componentize --stub-wasi app -o app.wasm
60+
```
61+
62+
To test it, you can install `wasmtime-py` and use it to generate host-side
63+
bindings for the component:
64+
65+
```shell
66+
pip install wasmtime
67+
python3 -m wasmtime.bindgen app.wasm --out-dir hello_host
68+
```
69+
70+
Now we can write a simple host app using those bindings:
71+
72+
```shell
73+
cat >host.py <<EOF
74+
from hello_host import Root
75+
from wasmtime import Config, Engine, Store
76+
77+
config = Config()
78+
config.cache = True
79+
engine = Engine(config)
80+
store = Store(engine)
81+
hello = Root(store)
82+
print(f"component says: {hello.hello(store)}")
83+
EOF
84+
```
85+
86+
And finally run it:
87+
88+
```shell
89+
$ python3 host.py
90+
component says: Hello, World!
6091
```
6192

6293
See the

runtime/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,8 @@ pub extern "C" fn componentize_py_to_canon_handle(
10851085
}
10861086
}
10871087

1088-
// TODO: move this into `wasm-tools`
1088+
// TODO: Update to the latest `wit-component`, which has a `use_built_in_libdl` option that makes the following
1089+
// unecessary:
10891090
pub mod dl {
10901091
use std::{
10911092
ffi::{c_char, c_int, c_void, CStr},

0 commit comments

Comments
 (0)