ericgregory/adding-component

★ 0Forks 0GoGitHub ↗Compare

README

Component example

This example implements a Go-based adding component example from the Component Model Book with the washCloud Shell (wash) CLI. The repo includes:

  • add.go - The Go code for the component
  • wit/world.wit - The WebAssembly Interface Type (WIT) file defining the add interface
  • wasmcloud.toml - A TOML file defining metadata and configuring the build process for wash build

Clone the repo and wash build from the project repo:

wash build

This will generate bindings in the gen directory and create a Wasm binary in the build directory. (Actually, it will create two binaries, but for our purposes we're only interested in the final output, adder_s.wasm.)

Once the component is built, use wash inspect to view the component's imports and exports:

wash inspect --wit ./build/adder_s.wasm
package root:component;

world root {
  import wasi:io/[email protected];
  import wasi:io/[email protected];
  import wasi:cli/[email protected];
  import wasi:cli/[email protected];
  import wasi:cli/[email protected];
  import wasi:clocks/[email protected];
  import wasi:filesystem/[email protected];
  import wasi:filesystem/[email protected];

  export docs:adder/[email protected];
}

We're exporting the add function.

Contributors

ericgregory

Issues