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

wac-graph

A library for defining, encoding, and decoding WebAssembly composition graphs

8 releases (breaking)

0.6.1 Oct 21, 2024
0.6.0 Sep 5, 2024
0.5.0 Jul 22, 2024
0.4.0 Jul 9, 2024
0.0.0 Apr 16, 2024

#1328 in WebAssembly

Download history 434/week @ 2024-11-16 325/week @ 2024-11-23 801/week @ 2024-11-30 508/week @ 2024-12-07 981/week @ 2024-12-14 330/week @ 2024-12-21 521/week @ 2024-12-28 5688/week @ 2025-01-04 4731/week @ 2025-01-11 5819/week @ 2025-01-18 4946/week @ 2025-01-25 5327/week @ 2025-02-01 5142/week @ 2025-02-08 4790/week @ 2025-02-15 5032/week @ 2025-02-22 10522/week @ 2025-03-01

26,257 downloads per month
Used in 10 crates (7 directly)

Apache-2.0 WITH LLVM-exception

245KB
5K SLoC

A library for defining, encoding, and decoding WebAssembly composition graphs.

An example of composing two components together using a 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())?;

Dependencies

~7MB
~121K SLoC