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

Document using wit-components for C and C++ programs. #1355

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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: 24 additions & 0 deletions crates/wit-component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,27 @@ $ wasm-tools component wit demo.component.wasm

Here the `demo.component.wasm` can now be shipped to a component runtime or
embedded into hosts.

## Building a component from C/C++ using `wasm-tools component new`

Use [wasi-sdk] to build a C/C++ application. Currently this produces a
preview1 core wasm binary. To convert it to a preview2 component, first
obtain a preview1-to-preview2 adapter module, such as by downloading a
pre-built version from the [jco] repository, which has adpaters at
[lib/wasi_snapshot_preview1.command.wasm].

Then, run `wasm-tools component new` and pass it your preview1 core wasm
application module and the adapter:

```sh
$ wasm-tools component new my-application.wasm --adapt=path/to/jco/lib/wasi_snapshot_preview1.command.wasm -o component.wasm
```

This produces a preview2 component. Currently it's necessary to ensure
that the WASI version of the adapter matches the WASI version of the
host. If you use jco's adapter, it can at least be run in that version
of jco.

[wasi-sdk]: https://github.com/WebAssembly/wasi-sdk/
[jco]: https://github.com/bytecodealliance/jco
[lib/lib/wasi_snapshot_preview1.command.wasm]: https://github.com/bytecodealliance/jco/blob/main/lib/wasi_snapshot_preview1.command.wasm