#wasm-component #component #codec #component-model

wac-graph

一个用于定义、编码和解码WebAssembly组合图的库

6个版本 (破坏性更新)

0.5.0 2024年7月22日
0.4.0 2024年7月9日
0.3.0 2024年5月20日
0.2.0 2024年5月16日
0.0.0 2024年4月16日

#1508 in WebAssembly

Download history 9/week @ 2024-05-03 213/week @ 2024-05-10 278/week @ 2024-05-17 64/week @ 2024-05-24 84/week @ 2024-05-31 95/week @ 2024-06-07 90/week @ 2024-06-14 155/week @ 2024-06-21 41/week @ 2024-06-28 235/week @ 2024-07-05 79/week @ 2024-07-12 435/week @ 2024-07-19 261/week @ 2024-07-26 42/week @ 2024-08-02 73/week @ 2024-08-09 122/week @ 2024-08-16

每月528次下载
3 crate 中使用

Apache-2.0 WITH LLVM-exception

245KB
5K SLoC

一个用于定义、编码和解码WebAssembly组合图的库。

使用CompositionGraph组合两个组件的示例

use wac_graph::{CompositionGraph, EncodeOptions, types::Package};

let mut graph = CompositionGraph::new();

// Register the packages with the graph
// It is assumed that `my:package1` exports a function named `a`,
// while `my:package2` imports a function named `b`.
let pkg = Package::from_file("my:package1", None, "package1.wasm", graph.types_mut())?;
let package1 = graph.register_package(pkg)?;
let pkg = Package::from_file("my:package2", None, "package2.wasm", graph.types_mut())?;
let package2 = graph.register_package(pkg)?;

// Instantiate package `my:package1`
let instantiation1 = graph.instantiate(package1);

// Alias the `a` export of the `my:package1` instance
let a = graph.alias_instance_export(instantiation1, "a")?;

// Instantiate package `my:package2`
let instantiation2 = graph.instantiate(package2);

// Set argument `b` of the instantiation of `my:package2` to `a`
graph.set_instantiation_argument(instantiation2, "b", a)?;

// Finally, encode the graph into a new component
let bytes = graph.encode(EncodeOptions::default())?;

依赖关系

~7MB
~117K SLoC