This function is only needed until rust can natively output a component. Generally embeddings should not be expected to do this programmatically, but instead language specific tooling should be used, for example in Rust `cargo component` is a good way of doing that: https://github.com/bytecodealliance/cargo-component In this example we convert the code here to simplify the testing process and bu
(path: impl AsRef<Path>)
| 27 | /// |
| 28 | /// In this example we convert the code here to simplify the testing process and build system. |
| 29 | fn convert_to_component(path: impl AsRef<Path>) -> Result<Vec<u8>> { |
| 30 | let bytes = &fs::read(&path).context("failed to read input file")?; |
| 31 | wit_component::ComponentEncoder::default() |
| 32 | .module(&bytes) |
| 33 | .to_wasmtime_result()? |
| 34 | .encode() |
| 35 | .to_wasmtime_result() |
| 36 | } |
| 37 | |
| 38 | fn main() -> Result<()> { |
| 39 | // Create an engine with the component model enabled (disabled by default). |