This component showcases building WebAssembly components that line up with WebIDL interfaces by
using the experimental built-in support for WebIDL in jco.
We can accomplish this by:
- Writing WebIDL specifications
- Using
webidl2witto turn WebIDL specifications into WIT interfaces - Using
jco componentizeto build Javascript WebAssembly components that target the relevant WIT interfaces - Using
jco transpileto compile that component to run in a JS context (like NodeJS) - Writing host bindings (
demo.js) that WebAssembly cna use
A common use case for WebIDL is targeting browsers, as the WebIDL is primarily used there
to document interfaces for the web platform. This example stops short of using the web platform
WebIDL in favor of showing a simpler modeled interace with WebIDL: a book library (see ./book-library.webidl).
To run this example, you'll need the following tools
| Tool | Description | Install instructions |
|---|---|---|
jco |
Javascript WebAssembly toolcahin | npm install -g @bytecodealliance/jco |
webidl2wit |
Converts WebIDL to WIT | cargo install --locked webidl2wit-cli |
Once dependencies are installed, you can use your favorite NodeJS package manager to run the steps:
npm install
npm run generate:wit
npm run generate:types
npm run build
npm run transpileNote
To run all these steps at once, you can run npm run all
After running the component build, we can run the example code that uses our WebAssembly component, and the WebIDL interface & implementation we made:
node demo.js