MERGED TO THE https://github.com/golemcloud/golem/ REPOSITORY
Defines data types for Golem's remote function invocation and conversions between them.
WitValueis the WIT-defined generic data type capable of representing an arbitrary value, generated bywit-bindgen- A builder and an extractor API for
WitValue Valueis a recursive Rust type which is more convenient to work with thanWitValue. Conversion betweenWitValueandValueis implemented in both directions.- Protobuf message types for describing values and types, and a protobuf version of
WitValueitself and conversion from and toValueandWitValue - JSON representation of WIT values, as defined in the Golem docs.
- Conversion of
Valueto and fromwasmtimevalues
The JSON representation requires additional type information which can be extracted using the golem-wasm-ast crate.
The golem-wasm-rpc crate can be both used in host and guest environments:
To compile the host version:
cargo build -p wasm-rpc --no-default-features --features hostTo compile the guest version, has minimal dependencies and feature set to be used in generated stubs:
cargo component build -p wasm-rpc --no-default-features --features stubarbitraryadds anArbitraryinstance forValuejsonadds conversion functions for mapping of a WIT value and type definition to/from JSONprotobufadds the protobuf message typeswasmtimeadds conversion towasmtimeValvalueshostenables all features:arbitrary,json,protobuf,typeinfo, andwasmtimestubis to be used in generated WASM stubs and disables all features, and generates guest bindings instead of host bindings
The golem-wasm-rpc-stubgen is a CLI tool to generate the RPC stubs from a component's WIT definition.
Usage: wasm-rpc-stubgen generate [OPTIONS] --source-wit-root <SOURCE_WIT_ROOT> --dest-crate-root <DEST_CRATE_ROOT>
Options:
-s, --source-wit-root <SOURCE_WIT_ROOT>
-d, --dest-crate-root <DEST_CRATE_ROOT>
-w, --world <WORLD>
--stub-crate-version <STUB_CRATE_VERSION> [default: 0.0.1]
--wasm-rpc-path-override <WASM_RPC_PATH_OVERRIDE>
-h, --help Print help
-V, --version Print versionsource-wit-root: The root directory of the component's WIT definition to be called via RPCdest-crate-root: The target path to generate a new stub crate toworld: The world name to be used in the generated stub crate. If there is only a single world in the source root package, no need to specify.stub-crate-version: The crate version of the generated stub cratewasm-rpc-path-override: The path to thewasm-rpccrate to be used in the generated stub crate. If not specified, the latest version ofwasm-rpcwill be used.
The command creates a new Rust crate that is ready to be compiled with
cargo component build --releaseThe resulting WASM component implements the stub interface corresponding to the source interface, found in the
target directory's
wit/stub.wit file. This WASM component is to be composed together with another component that calls the original
interface via WASM RPC.
Usage: wasm-rpc-stubgen build [OPTIONS] --source-wit-root <SOURCE_WIT_ROOT> --dest-wasm <DEST_WASM> --dest-wit-root <DEST_WIT_ROOT>
Options:
-s, --source-wit-root <SOURCE_WIT_ROOT>
--dest-wasm <DEST_WASM>
--dest-wit-root <DEST_WIT_ROOT>
-w, --world <WORLD>
--stub-crate-version <STUB_CRATE_VERSION> [default: 0.0.1]
--wasm-rpc-path-override <WASM_RPC_PATH_OVERRIDE>
-h, --help Print help
-V, --version Print version
source-wit-root: The root directory of the component's WIT definition to be called via RPCdest-wasm: The name of the stub WASM file to be generateddest-wit-root: The directory name where the generated WIT files should be placedworld: The world name to be used in the generated stub crate. If there is only a single world in the source root package, no need to specify.stub-crate-version: The crate version of the generated stub cratewasm-rpc-path-override: The path to thewasm-rpccrate to be used in the generated stub crate. If not specified, the latest version ofwasm-rpcwill be used. It needs to be an absolute path.
Usage: wasm-rpc-stubgen add-stub-dependency [OPTIONS] --stub-wit-root <STUB_WIT_ROOT> --dest-wit-root <DEST_WIT_ROOT>
Options:
-s, --stub-wit-root <STUB_WIT_ROOT>
-d, --dest-wit-root <DEST_WIT_ROOT>
-o, --overwrite
-u, --update-cargo-toml
-h, --help Print help
-V, --version Print versionThe command merges a generated RPC stub as a WIT dependency into an other component's WIT root.
stub-wit-root: The WIT root generated by eithergenerateorbuildcommanddest-wit-root: The WIT root of the component where the stub should be added as a dependencyoverwrite: 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 ofdest-wit-rootwith the copied dependencies.
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 versionThe 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 componentstub-wasm: The WASM file of the generated stub. Multiple stubs can be listed.dest-wasm: The name of the composed WASM file to be generated
Usage: wasm-rpc-stubgen initialize-workspace [OPTIONS] --targets <TARGETS> --callers <CALLERS>
Options:
--targets <TARGETS>
List of subprojects to be called via RPC
--callers <CALLERS>
List of subprojects using the generated stubs for calling remote workers
--wasm-rpc-path-override <WASM_RPC_PATH_OVERRIDE>When both the target and the caller components are in the same Cargo workspace, this command can initialize a cargo-make file with dependent tasks
performing the stub generation, WIT merging and WASM composition.
Once the workspace is initialized, the following two commands become available:
cargo make build-flow
cargo make release-build-flow