Skip to content

Commit

Permalink
Merge pull request #177 from itowlson/actually-composing-functions-is…
Browse files Browse the repository at this point in the history
…-fine-too

Remove claim that composition requires interfaces not functions
  • Loading branch information
kate-goldenring authored Nov 22, 2024
2 parents 088fe2a + b229be7 commit e747706
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions component-model/src/creating-and-consuming/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ wasmtime run <path-to-wasm-file>

If you're writing a library-style component - that is, one that exports a custom API - then you can run it in `wasmtime` by writing a "command" component that imports and invokes your custom API. By [composing](./composing.md) the command and the library, you can exercise the library in `wasmtime`.

1. Write your library component. The component's world (`.wit` file) must export an interface. (Do not export functions directly, only interfaces.) See the [language support guide](../language-support.md) for how to implement an export.
1. Write your library component. The component's world (`.wit` file) must export an interface and/or one or more functions through which a consumer can call it. See the [language support guide](../language-support.md) for how to implement an export.

2. Build your library component to a `.wasm` file.

3. Write your command component. The component's world (`.wit` file) must import the interface exported from the library. Write the command to call the library's API. See the [language support guide](../language-support.md) for how to call an imported interface.
3. Write your command component. The component's world (`.wit` file) must import the interface or functions exported from the library. Write the command to call the library's API. See the [language support guide](../language-support.md) for how to call an imported interface.

4. Build your command component to a `.wasm` file. You will not be able to run this in `wasmtime` yet, as its imports are not yet satisfied.

Expand Down
7 changes: 3 additions & 4 deletions component-model/src/language-support/csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ The component will be available at `bin/Debug/net9.0/wasi-wasm/native/adder.wasm

## Building a component that exports an interface

The previous example uses a WIT file that exports a function. However, to use your component from
another component, it must export an interface. That being said, you rarely find WIT that does not
contain an interface. (Most WITs you'll see in the wild do use interfaces; we've been simplifying by
exporting a function.) Let's expand our `example` world to export an interface rather than directly
The previous example uses a WIT file that exports a function. However, you'll often prefer to export an interface,
either to comply with an existing specification or to capture a set of functions and types that tend to go
together. Let's expand our `example` world to export an interface rather than directly
export the function. We are also adding the `hostapp` world to our WIT file which we will implement
in [the next section](#building-a-component-that-imports-an-interface) to demonstrate how to build a
component that *imports* an interface.
Expand Down
2 changes: 1 addition & 1 deletion component-model/src/language-support/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ See [`componentize-py`'s examples](https://github.com/bytecodealliance/component

### Building a Component that Exports an Interface

The [sample `add.wit` file](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/example-host/add.wit) exports a function. However, to use your component from another component, it must export an interface. That being said, you rarely find WIT that does not contain an interface. (Most WITs you'll see in the wild do use interfaces; we've been simplifying by exporting a function.) Let's expand our example world to export an interface rather than directly export the function.
The [sample `add.wit` file](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/example-host/add.wit) exports a function. However, you'll often prefer to export an interface, either to comply with an existing specification or to capture a set of functions and types that tend to go together. Let's expand our example world to export an interface rather than directly export the function.

```wit
// add-interface.wit
Expand Down
2 changes: 1 addition & 1 deletion component-model/src/language-support/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ $ cargo run --release -- 1 2 ../add/target/wasm32-wasip1/release/add.wasm

## Exporting an interface with `cargo component`

The [sample `add.wit` file](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/example-host/add.wit) exports a function. However, to use your component from another component, it must export an interface. This results in slightly fiddlier bindings. For example, to implement the following world:
The [sample `add.wit` file](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/example-host/add.wit) exports a function. However, you'll often prefer to export an interface, either to comply with an existing specification or to capture a set of functions and types that tend to go together. For example, to implement the following world:

```wit
package docs:[email protected];
Expand Down

0 comments on commit e747706

Please sign in to comment.