1 unstable release
0.1.1 | Mar 27, 2024 |
---|
#32 in #capability-provider
Used in wasmcloud-provider-wit-bi…
140KB
2K
SLoC
wasmcloud-provider-wit-bindgen
This crate contains a macro that helps build Wasmcloud Capability Providers which are distributed as binaries and work with the WIT.
This crate leverages wit-bindgen
in it's generation of interfaces and code, but generates pure Rust code (i.e. for non-wasm32-*
Rust targets) that can be used in building a capability provider binary.
Usage
This crate can be be used similarly to wit-bindgen
, with the following syntax:
wasmcloud_provider_wit_bindgen::generate!(
YourProvider,
"wasmcloud:contract",
"your-world"
);
/// Implementation that you will contribute
struct YourProvider;
impl Trait for YourProvider {
...
}
Note that arguments after the second are similar to the options used by wit-bindgen
, but the code generated is meant for use in a Rust binary, managed by a wasmcloud
host.
For example, to build a provider for the wasmCloud keyvalue WIT interface:
/// Generate bindings for a wasmCloud provider
wasmcloud_provider_wit_bindgen::generate!(
MyKeyvalueProvider,
"wasmcloud:keyvalue",
"keyvalue"
);
Warning You'll need to have the appropriate WIT interface file (ex.
keyvalue.wit
) in your crate root, at<crate root>/wit/keyvalue.wit
Note that after you generate bindings appropriate for your WIT, you must:
- follow the compiler to implement the appropriate traits
- write a
main.rs
that properly sets up your provider - use the compiled binary for your provider on your wasmCloud lattice
Dependencies
~6.5–8.5MB
~154K SLoC