Stream: wasmtime

Topic: top-level function composition


view this post on Zulip Ryan Levick (rylev) (Sep 12 2023 at 14:44):

@Peter Huene Do you know why wasm-tools compose doesn't support composing a component that has a top-level function import? Is this just because it hasn't been added yet or am I missing something more fundamental? My expectation would be that at the very least if I try to composed a component with a function import with an adapter that if the adapter doesn't have a function export that fits the composed component which just continue to import that function.

view this post on Zulip Ryan Levick (rylev) (Sep 12 2023 at 14:45):

(I should have posted this in #wasm - if anyone with permissions is able to move it there that would be great)

view this post on Zulip Peter Huene (Sep 12 2023 at 15:12):

The CLI was written at a time when only instances were imported and exported, so it simply isn't implemented yet. A workaround is to use wasmbuilder.app and manually connect things, as that can connect functions.

I'm working on a replacement to wasm-compose that will be more flexible and registry-aware.

view this post on Zulip Ryan Levick (rylev) (Sep 12 2023 at 15:18):

Happy to help with this - I'm working on a tool that would allow for iterative composition of components, and thus I need programmatic use of the compose library.

view this post on Zulip Ryan Levick (rylev) (Sep 12 2023 at 16:58):

@Peter Huene would it be possible to be able to do composition from components in memory instead of always needing to do it from a file?

view this post on Zulip Peter Huene (Sep 12 2023 at 16:59):

The graph API has https://docs.rs/wasm-compose/latest/wasm_compose/graph/struct.Component.html#method.from_bytes

view this post on Zulip Ryan Levick (rylev) (Sep 12 2023 at 17:07):

Ah somehow I missed that. Thanks!

view this post on Zulip Ryan Levick (rylev) (Sep 12 2023 at 17:10):

@Peter Huene oh I see now - I've been using the ComponentComposer API which only accepts a path

view this post on Zulip Peter Huene (Sep 12 2023 at 17:10):

yeah, that thing is just a simplistic interface that drives the CLI

view this post on Zulip Peter Huene (Sep 12 2023 at 17:10):

CompositionGraph underpins everything and is what wasmbuilder.app uses directly

view this post on Zulip Ryan Levick (rylev) (Sep 12 2023 at 17:23):

When you say you're rewriting wasm-tools compose, are you planning on doing that from the ground up or is the core going to stay the same? I'm just wondering how much time I should put into adding functionality to my tool rather than waiting for the replacement

view this post on Zulip Peter Huene (Sep 12 2023 at 17:59):

mostly found the ground-up, but keeping the parts that make sense (such as the composition graph); there's going to be a WIT-like composition language that is quite expressive in terms of composing components together, with built in support for the registry.

// create an instance of the `foo:bar` component and import the needed instantiation arguments into the composition
let bar = new foo:bar { ... }
// create an instance of the `foo:baz` component, passing `bar` as an instantiation argument, importing the rest
let baz = new foo:baz { bar, ... }
// alias the `run` function from instance `baz` and export it from the composition
export baz.run

view this post on Zulip Daniel Macovei (Sep 13 2023 at 16:20):

Not sure if you can do this for your use case... but I was encountering the same thing when bundling transitive registry dependencies, and inlined the components that were being imported... happy to share some of that if it could help you out for the time being.


Last updated: Nov 22 2024 at 17:03 UTC