Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rust guest example comments in README.md #599

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</strong>
</p>

<strong>A <a href="https://bytecodealliance.org/">Bytecode Alliance</a> project</strong>
<strong>A <a href="https://bytecodealliance.org/">Bytecode Alliance</a> project</strong>

<p>
<a href="https://github.com/bytecodealliance/wit-bindgen/actions?query=workflow%3ACI"><img src="https://github.com/bytecodealliance/wit-bindgen/workflows/CI/badge.svg" alt="build status" /></a>
Expand Down Expand Up @@ -157,9 +157,8 @@ which has a `_start` entrypoint (e.g. a `src/main.rs` in Rust).
[non-command]: https://github.com/bytecodealliance/wasmtime/releases/latest/download/wasi_snapshot_preview1.reactor.wasm
[command]: https://github.com/bytecodealliance/wasmtime/releases/latest/download/wasi_snapshot_preview1.command.wasm



## Supported Guest Languages

[guests]: #supported-guest-languages

The `wit-bindgen` project is primarily focused on **guest** languages which are
Expand Down Expand Up @@ -215,7 +214,7 @@ file. Example code using this then looks like:
wit_bindgen::generate!("host");

// Define a custom type and implement the generated `Host` trait for it which
// represents implementing all the necesssary exported interfaces for this
// represents implementing all the necessary exported interfaces for this
// component.
struct MyHost;

Expand All @@ -225,6 +224,9 @@ impl Host for MyHost {
}
}

// The following is a generated macro and the name of it is formatted as `export_{}`.
// The parameter `{}` is the name of the world.
// This happens to be `host` in our example.
alisomay marked this conversation as resolved.
Show resolved Hide resolved
export_host!(MyHost);
```

Expand Down Expand Up @@ -301,7 +303,6 @@ Like with Rust, you can then inspect the output binary:
wasm-tools component wit ./my-component.wasm
```


### Guest: Java

Java bytecode can be compiled to WebAssembly using
Expand Down Expand Up @@ -380,6 +381,7 @@ ideally relatively quickly follow suit and stay within the confines of the
first design.

## CLI Installation

[cli-install]: #cli-installation

To install the CLI for this tool (which isn't the only way it can be used), run
Expand All @@ -394,8 +396,8 @@ This CLI **IS NOT** stable and may change, do not expect it to be or rely on it
being stable. Please reach out to us on [zulip] if you'd like to depend on it,
so we can figure out a better alternative for your use case.


## Host Runtimes for Components

[hosts]: #host-runtimes-for-components

The `wit-bindgen` project is intended to facilitate in generating a component,
Expand All @@ -404,31 +406,31 @@ execute that somewhere. This is not under the purview of `wit-bindgen` itself
but these are some resources and runtimes which can help you work with
components:

* Rust: the [`wasmtime` crate](https://docs.rs/wasmtime) is an implementation of
- Rust: the [`wasmtime` crate](https://docs.rs/wasmtime) is an implementation of
a native component runtime that can run any WIT `world`. It additionally comes
with a [`bindgen!`
macro](https://docs.rs/wasmtime/latest/wasmtime/component/macro.bindgen.html)
which acts similar to the `generate!` macro in this repository. This macro
takes a [WIT] package as input and generates `trait`-based bindings for the
runtime to implement and use.

* JS: the [`js-component-tools`] project can be used to execute components in JS
- JS: the [`js-component-tools`] project can be used to execute components in JS
either on the web or outside the browser in a runtime such as `node`. This
project generates a polyfill for a single concrete component to execute in a
JS environment by extracting the core WebAssembly modules that make up a
component and generating JS glue to interact between the host and these
modules.

* Python: the [`wasmtime`](https://github.com/bytecodealliance/wasmtime-py)
- Python: the [`wasmtime`](https://github.com/bytecodealliance/wasmtime-py)
project [on PyPI](https://pypi.org/project/wasmtime/) has a `bindgen` mode
that works similar to the JS integration. Given a concrete component this will
generate Python source code to interact with the component using an embedding
of Wasmtime for its core WebAssembly support.

* Tooling: the [`wasm-tools`] project can be used to inspect and modify
- Tooling: the [`wasm-tools`] project can be used to inspect and modify
low-level details of components. For example as previously mentioned you can
inspect the WIT-based interface of a component with `wasm-tools component
wit`. You can link two components together with `wasm-tools compose` as well.
wit`. You can link two components together with `wasm-tools compose` as well.

[`js-component-tools`]: https://github.com/bytecodealliance/js-component-tools

Expand Down