-
Notifications
You must be signed in to change notification settings - Fork 15
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
New wac plug
command
#93
Conversation
The goal of the command is to treat one component as a plug which will have all of its exports that match the imports of another component, the socket, plugged into the socket component. The exports of the socket will be re-exported.
Signed-off-by: Ryan Levick <[email protected]>
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.
Nice work!
It's great to see how relatively easy it was to implement this on top of the CompositionGraph
API.
In addition to my two comments, I have some general feedback:
-
Regarding the "plug" and "socket" nomenclature (including the
plug
subcommand name), I wonder if perhaps we use a "link" verb which takes a "root" component and a set of "dependencies" to satisfy instantiations with; to me there's enough of a distinction between this and "composing" (i.e. using a WAC source file). -
While this implementation is definitely a step forward (truly!), it differs in a significant way from the
-d
option towasm-tools compose
; chiefly, the-d
option registers a component to use as an argument to any instantiation being processed. This is especially required for awasi-virt
use case where you might have a component that exports WASI instances and want that plugged into every other instantiation (including dependencies) to get the same WASI implementation used.
With the second point above in mind, I'm thinking this command might work like this:
-
Load each dependency package and walk its exports, registering each one in an "exports" map and treat it as an error if more than one dependency exports the same name.
-
Starting with the root component, satisfy any arguments with the registered exports while keeping track of a singular instantiation for each dependency (when used); for each of those connected arguments, recursively walk those instantiations and satisfy their arguments from the registered exports, with any unsatisfied argument remaining an outer import.
-
Gracefully handle a graph cycle error during encoding as it is certainly possible to form a cycle this way (dependency
A
importsi
and exportse
, dependencyB
importse
and exportsi
, root componentC
importsi
, invoked with, perhaps,wac link -d a.wasm -d b.wasm c.wasm
):flowchart TD A[A] -->|e| B[B] B -->|i| C[C] B -->|i| A
What are your thoughts on this?
Also, it would also be great if this command could additionally support the That could potentially be a follow-up feature and doesn't necessarily need to be part of this PR, though! |
Thanks for the feedback!
So I suppose the following are the questions now at hand:
|
Food for thought on the name: |
Cool, I'm onboard with this; we can always change it in the near future if it proves confusing to users.
Gotcha. I originally thought it was meant to be a 1:1 replacement of
Yes, I think "plug" makes sense in this context.
I'm fine with it; it feels like "plug" is simpler but more explicit while the "link" command I propose above is more complex but magical (and may not get everything right). I think there's room for two commands should need arise.
That is indeed a tradeoff; many users will probably expect the "plug" behavior to start with. My thoughts on this is that we move forward with your implementation and see if there is additional need for automatic composition. |
Signed-off-by: Ryan Levick <[email protected]>
@peterhuene awesome! I've addressed the small feedback you left inline. I can add registry support in a follow on PR. |
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.
Just a few more feedback comments, but otherwise looks great!
Signed-off-by: Ryan Levick <[email protected]>
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.
Looks great, thanks for adding this!
Closes #80
This PR introduces the
wac plug
command.wac plug
takes any number of "plug" components and a single "socket" component. It then attempts to find all exports in each plug that have a matching import (both by name and type) in the socket. It then composes all the components together by filling in the sockets imports with the exports from the plugs.All the exports of socket will be exported from the composition, and any unused exports of the plugs will be dropped. All imports from the plugs and any unplugged imports from the socket will be imported into the composition.
Example
We want to compose these two components into a component with the following wit:
To do this, we can run: