Skip to content

Commit

Permalink
add host instructions to README.md example (bytecodealliance#90)
Browse files Browse the repository at this point in the history
Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej authored Apr 23, 2024
1 parent 013d51b commit c6c8447
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ If you're using an IDE or just want to examine the bindings produced for the WIT
world, you can generate them using the `bindings` subcommand:

```shell
componentize-py -d hello.wit -w hello bindings .
componentize-py -d hello.wit -w hello bindings hello_guest
```

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

```shell
componentize-py -d hello.wit -w hello componentize app -o app.wasm
componentize-py -d hello.wit -w hello componentize --stub-wasi app -o app.wasm
```

To test it, you can install `wasmtime-py` and use it to generate host-side
bindings for the component:

```shell
pip install wasmtime
python3 -m wasmtime.bindgen app.wasm --out-dir hello_host
```

Now we can write a simple host app using those bindings:

```shell
cat >host.py <<EOF
from hello_host import Root
from wasmtime import Config, Engine, Store
config = Config()
config.cache = True
engine = Engine(config)
store = Store(engine)
hello = Root(store)
print(f"component says: {hello.hello(store)}")
EOF
```

And finally run it:

```shell
$ python3 host.py
component says: Hello, World!
```

See the
Expand Down
3 changes: 2 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,8 @@ pub extern "C" fn componentize_py_to_canon_handle(
}
}

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

0 comments on commit c6c8447

Please sign in to comment.