Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from golemcloud/compose-command
Browse files Browse the repository at this point in the history
GOL-226 Added a new compose command to the stub generator
  • Loading branch information
vigoo authored Feb 29, 2024
2 parents 51c0b80 + 2fd9d1e commit fbc708a
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 19 deletions.
128 changes: 117 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ Defines data types for [Golem](https://golem.cloud)'s remote function invocation

- `WitValue` is the WIT-defined generic data type capable of representing an arbitrary value, generated by `wit-bindgen`
- A builder and an extractor API for `WitValue`
- `Value` is a recursive Rust type which is more convenient to work with than `WitValue`. Conversion between `WitValue` and `Value` is implemented in both directions.
- Protobuf message types for describing values and types, and a protobuf version of `WitValue` itself and conversion from and to `Value` and `WitValue`
- `Value` is a recursive Rust type which is more convenient to work with than `WitValue`. Conversion between `WitValue`
and `Value` is implemented in both directions.
- Protobuf message types for describing values and types, and a protobuf version of `WitValue` itself and conversion
from and to `Value` and `WitValue`
- JSON representation of WIT values, as defined in [the Golem docs](https://learn.golem.cloud/docs/template-interface).
- Conversion of `Value` to and from `wasmtime` values

The JSON representation requires additional type information which can be extracted using the [golem-wasm-ast](https://crates.io/crates/golem-wasm-ast) crate.
The JSON representation requires additional type information which can be extracted using
the [golem-wasm-ast](https://crates.io/crates/golem-wasm-ast) crate.

## Host and stub mode

Expand All @@ -30,19 +33,21 @@ cargo component build -p wasm-rpc --no-default-features --features stub
```

## Feature flags

- `arbitrary` adds an `Arbitrary` instance for `Value`
- `json` adds conversion functions for mapping of a WIT value and type definition to/from JSON
- `protobuf` adds the protobuf message types
- `wasmtime` adds conversion to `wasmtime` `Val` values
- `host` enables all features: `arbitrary`, `json`, `protobuf`, `typeinfo`, and `wasmtime`
- `stub` is to be used in generated WASM stubs and disables all features, and generates guest bindings instead of host bindings

- `stub` is to be used in generated WASM stubs and disables all features, and generates guest bindings instead of host
bindings

## golem-wasm-rpc-stubgen

The `golem-wasm-rpc-stubgen` is a CLI tool to generate the RPC stubs from a component's WIT definition.

## Generate

```shell
Usage: wasm-rpc-stubgen generate [OPTIONS] --source-wit-root <SOURCE_WIT_ROOT> --dest-crate-root <DEST_CRATE_ROOT>

Expand Down Expand Up @@ -76,6 +81,7 @@ target directory's
interface via WASM RPC.

## Build

```
Usage: wasm-rpc-stubgen build [OPTIONS] --source-wit-root <SOURCE_WIT_ROOT> --dest-wasm <DEST_WASM> --dest-wit-root <DEST_WIT_ROOT>
Expand Down Expand Up @@ -119,4 +125,25 @@ The command merges a generated RPC stub as a WIT dependency into an other compon
- `dest-wit-root`: The WIT root of the component where the stub should be added as a dependency
- `overwrite`: This command would not do anything if it detects that it would change an existing WIT file's contents at
the destination. With this flag, it can be forced to overwrite those files.
- `update-cargo-toml`: Enables updating the Cargo.toml file in the parent directory of `dest-wit-root` with the copied dependencies.ation. With this flag, it can be forced to overwrite those files.
- `update-cargo-toml`: Enables updating the Cargo.toml file in the parent directory of `dest-wit-root` with the copied
dependencies.

## Compose the stub with the caller component

```shell
Usage: wasm-rpc-stubgen compose --source-wasm <SOURCE_WASM> --stub-wasm <STUB_WASM> --dest-wasm <DEST_WASM>

Options:
--source-wasm <SOURCE_WASM>
--stub-wasm <STUB_WASM>
--dest-wasm <DEST_WASM>
-h, --help Print help
-V, --version Print version
```

The command composes a caller component's WASM (which uses the generated stub to call a remote worker) with the
generated stub WASM, writing out a composed WASM which no longer depends on the stub interface, ready to use.

- `source-wasm`: The WASM file of the caller component
- `stub-wasm`: The WASM file of the generated stub
- `dest-wasm`: The name of the composed WASM file to be generated
5 changes: 4 additions & 1 deletion wasm-rpc-stubgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ cargo-component-core = "=0.7.0"
cargo-component = "=0.7.0"
dir-diff = "0.3.3"
fs_extra = "1.3.0"
golem-wasm-ast = "0.2.1"
golem-wasm-rpc = { path = "../wasm-rpc", version = "0.0.0" }
heck = "0.4.1"
id-arena = "2.2.1"
indexmap = "2.0.0"
pretty_env_logger = "0.5.0"
prettyplease = "0.2.16"
proc-macro2 = "1.0.78"
quote = "1.0.35"
Expand All @@ -30,5 +32,6 @@ syn = "2.0.48"
tempdir = "0.3.7"
tokio = "1.36.0"
toml = "0.8.10"
wasm-compose = "0.201.0"
wit-bindgen-rust = "=0.17.0"
wit-parser = "0.14.0"
wit-parser = "0.201.0"
22 changes: 21 additions & 1 deletion wasm-rpc-stubgen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,24 @@ The command merges a generated RPC stub as a WIT dependency into an other compon
- `dest-wit-root`: The WIT root of the component where the stub should be added as a dependency
- `overwrite`: This command would not do anything if it detects that it would change an existing WIT file's contents at
the destination. With this flag, it can be forced to overwrite those files.
- `update-cargo-toml`: Enables updating the Cargo.toml file in the parent directory of `dest-wit-root` with the copied dependencies.
- `update-cargo-toml`: Enables updating the Cargo.toml file in the parent directory of `dest-wit-root` with the copied dependencies.
-
## Compose the stub with the caller component

```shell
Usage: wasm-rpc-stubgen compose --source-wasm <SOURCE_WASM> --stub-wasm <STUB_WASM> --dest-wasm <DEST_WASM>

Options:
--source-wasm <SOURCE_WASM>
--stub-wasm <STUB_WASM>
--dest-wasm <DEST_WASM>
-h, --help Print help
-V, --version Print version
```

The command composes a caller component's WASM (which uses the generated stub to call a remote worker) with the
generated stub WASM, writing out a composed WASM which no longer depends on the stub interface, ready to use.

- `source-wasm`: The WASM file of the caller component
- `stub-wasm`: The WASM file of the generated stub
- `dest-wasm`: The name of the composed WASM file to be generated
Loading

0 comments on commit fbc708a

Please sign in to comment.