-
Notifications
You must be signed in to change notification settings - Fork 2
Convert component resource to list<u8> #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,57 +3,31 @@ | |
| use wac_graph::{types::Package, CompositionGraph, EncodeOptions}; | ||
|
|
||
| use crate::exports::componentized::component::{ | ||
| types::{Component, ComponentBorrow, Error, Guest as TypesGuest, GuestComponent}, | ||
| types::{Component, Error}, | ||
| wac_loader::Guest, | ||
| }; | ||
|
|
||
| pub(crate) struct WacLoader; | ||
|
|
||
| impl TypesGuest for WacLoader { | ||
| type Component = WacComponent; | ||
| } | ||
|
|
||
| impl Guest for WacLoader { | ||
| #[allow(async_fn_in_trait)] | ||
| async fn plug( | ||
| socket: ComponentBorrow<'_>, | ||
| plugs: Vec<ComponentBorrow<'_>>, | ||
| ) -> Result<Component, Error> { | ||
| async fn plug(socket: Component, plugs: Vec<Component>) -> Result<Component, Error> { | ||
| let mut graph = CompositionGraph::new(); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this component also import a wasm-validator, or are the error messages from wac_graph just as useful?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if wac validates anything more that the interfaces being combined, plug even less so than graph. We can add explicit validation if it proves useful in the future. |
||
| let socket: &WacComponent = socket.get(); | ||
| let socket = Package::from_bytes("socket", None, socket.into_wasm(), graph.types_mut())?; | ||
| let socket = Package::from_bytes("socket", None, socket, graph.types_mut())?; | ||
| let socket = graph.register_package(socket)?; | ||
|
|
||
| let mut graph_plugs = Vec::new(); | ||
| for plug in plugs { | ||
| let plug: &WacComponent = plug.get(); | ||
| let plug = Package::from_bytes("plug", None, plug.into_wasm(), graph.types_mut())?; | ||
| let plug = Package::from_bytes("plug", None, plug, graph.types_mut())?; | ||
| let plug = graph.register_package(plug)?; | ||
| graph_plugs.push(plug); | ||
| } | ||
|
|
||
| wac_graph::plug(&mut graph, graph_plugs, socket)?; | ||
| let composed_wasm = graph.encode(EncodeOptions::default())?; | ||
|
|
||
| Ok(Component::new(WacComponent::new(composed_wasm))) | ||
| } | ||
| } | ||
| let component = graph.encode(EncodeOptions::default())?; | ||
|
|
||
| pub(crate) struct WacComponent { | ||
| wasm: Vec<u8>, | ||
| } | ||
|
|
||
| impl WacComponent { | ||
| fn new(wasm: Vec<u8>) -> Self { | ||
| Self { wasm } | ||
| } | ||
| } | ||
|
|
||
| impl GuestComponent for WacComponent { | ||
| #[allow(async_fn_in_trait)] | ||
| fn into_wasm(&self) -> Vec<u8> { | ||
| self.wasm.clone() | ||
| Ok(component) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,17 @@ | ||
| #![no_main] | ||
|
|
||
| use crate::{ | ||
| exports::componentized::component::types::{ | ||
| Component, Error, Guest as TypesGuest, GuestComponent, | ||
| }, | ||
| exports::componentized::component::types::{Component, Error}, | ||
| exports::componentized::component::wasm_loader::Guest, | ||
| }; | ||
| use wit_bindgen::rt::async_support::StreamReader; | ||
|
|
||
| pub(crate) struct WasmLoader; | ||
|
|
||
| impl TypesGuest for WasmLoader { | ||
| type Component = WasmComponent; | ||
| } | ||
|
|
||
| impl Guest for WasmLoader { | ||
| #[allow(async_fn_in_trait)] | ||
| async fn load(wasm: StreamReader<u8>) -> Result<Component, Error> { | ||
| let wasm = wasm.collect().await; | ||
| Ok(Component::new(WasmComponent::new(wasm))) | ||
| } | ||
| } | ||
|
|
||
| pub(crate) struct WasmComponent { | ||
| wasm: Vec<u8>, | ||
| } | ||
|
|
||
| impl WasmComponent { | ||
| fn new(wasm: Vec<u8>) -> Self { | ||
| Self { wasm } | ||
| } | ||
| } | ||
|
|
||
| impl GuestComponent for WasmComponent { | ||
| #[allow(async_fn_in_trait)] | ||
| fn into_wasm(&self) -> Vec<u8> { | ||
| self.wasm.clone() | ||
| Ok(wasm.collect().await) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that this is effectively a single-line implementation, is having it in a component justifiable? Why wouldn't a consuming component just call collect() itself instead of call this component's function?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea, can clean that up when restructuring the loaders |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ world extract-wit { | |
| } | ||
|
|
||
| world wac-loader { | ||
| import componentized:component/types@0.0.0-0; | ||
| export componentized:component/types@0.0.0-0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The explicit types export shouldn't be necessary.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is because of the error |
||
| export componentized:component/wac-loader@0.0.0-0; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function actually returns WIT for any valid bytes, including a package that has 0..N worlds, right? Maybe the extract func should be explicitly more general than "component". It looks like the Wit type itself already is.