47 releases (8 stable)

new 1.0.7 Oct 23, 2024
1.0.3 Sep 23, 2024
0.0.41 Aug 14, 2024
0.0.36 Jul 31, 2024
0.0.16 Mar 30, 2024

#130 in WebAssembly

Download history 433/week @ 2024-07-03 434/week @ 2024-07-10 370/week @ 2024-07-17 341/week @ 2024-07-24 477/week @ 2024-07-31 429/week @ 2024-08-07 1132/week @ 2024-08-14 749/week @ 2024-08-21 599/week @ 2024-08-28 432/week @ 2024-09-04 379/week @ 2024-09-11 283/week @ 2024-09-18 185/week @ 2024-09-25 53/week @ 2024-10-02 650/week @ 2024-10-09 172/week @ 2024-10-16

1,134 downloads per month
Used in 2 crates

Apache-2.0

660KB
15K SLoC

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

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 version
  • source-wit-root: The root directory of the component's WIT definition to be called via RPC
  • dest-crate-root: The target path to generate a new stub crate to
  • world: 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 crate
  • wasm-rpc-path-override: The path to the wasm-rpc crate to be used in the generated stub crate. If not specified, the latest version of wasm-rpc will be used.

The command creates a new Rust crate that is ready to be compiled with

cargo component build --release

The 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.

Build

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 RPC
  • dest-wasm: The name of the stub WASM file to be generated
  • dest-wit-root: The directory name where the generated WIT files should be placed
  • world: 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 crate
  • wasm-rpc-path-override: The path to the wasm-rpc crate to be used in the generated stub crate. If not specified, the latest version of wasm-rpc will be used. It needs to be an absolute path.

Add stub WIT dependency

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 version

The 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 either generate or build command
  • 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.

Compose the stub with the caller component

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. Multiple stubs can be listed.
  • dest-wasm: The name of the composed WASM file to be generated

Initialize cargo make tasks for a workspace

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

Dependencies

~33–49MB
~806K SLoC