Skip to content
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

fix(composition): replace deprecated wasm-tools compose with wac #154

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

kate-goldenring
Copy link
Collaborator

This updates the composition document and the calculator example to use wac plug and wac compose. The wac compose examples are fairly trivial but it is a start to what can become more robust documentation of it as registries support solidifies, which @macovedj is working on in #129

Copy link
Collaborator

@itowlson itowlson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great - your explanation helped me to click with what WAC is doing far better than the WAC documentation itself (although that was admittedly that was the old documentation!).

I did, inevitably, have a bunch of suggestions and questions, but I don't think any of them are blockers except for the possible issue around the name of deps subdirectory - the rest we can iterate on for sure.

cd ..
wasm-tools compose calculator/target/wasm32-wasi/release/calculator.wasm -d adder/target/wasm32-wasi/release/adder.wasm -o composed.wasm
wasm-tools compose command/target/wasm32-wasi/release/command.wasm -d composed.wasm -o final.wasm
wac plug calculator/target/wasm32-wasi/release/calculator.wasm --plug adder/target/wasm32-wasi/release/adder.wasm -o composed.wasm
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cd .. line has been removed - that was an error in the previous text right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the cd .. is necessary...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all of this is taking place in the tutorial directory, the cd .. was incorrect given that the previous 3 lines do not change your directory

component-model/examples/tutorial/README.md Show resolved Hide resolved
component-model/examples/tutorial/README.md Outdated Show resolved Hide resolved
component-model/examples/tutorial/README.md Outdated Show resolved Hide resolved
component-model/examples/tutorial/README.md Outdated Show resolved Hide resolved
component-model/examples/tutorial/composition.wac Outdated Show resolved Hide resolved
component-model/src/creating-and-consuming/composing.md Outdated Show resolved Hide resolved
```

Here `component.wasm` is the component that imports interfaces from `dep1.wasm` and `dep2.wasm`, which export them. The composed component, with those dependencies satisfied and tucked away inside it, is saved to `composed.wasm`.

> This syntax doesn't cover transitive dependencies. If, for example, `dep1.wasm` has unsatisfied imports that you want to satisfy from `dep3.wasm`, you'll need to use a [configuration file](https://github.com/bytecodealliance/wasm-tools/blob/main/crates/wasm-compose/CONFIG.md). (Or you can compose `dep1.wasm` with `dep3.wasm` first, then refer to that composed component instead of `dep1.wasm`. This doesn't scale to lots of transitive dependencies though!)
The `plug` syntax doesn't cover transitive dependencies. If, for example, `dep1.wasm` has unsatisfied imports that you want to satisfy from `dep3.wasm`, you'd need to be deliberate about the order of your composition. You could compose `dep1.wasm` with `dep3.wasm` first, then refer to that composed component instead of `dep1.wasm`. However, this doesn't scale to lots of transitive dependencies, which is why WAC files were created.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph, or somewhere within or around it, feels like it might be the start of a subsection, as it introduces and explains a significant new evolution or problem-solution scenario from what went before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you thinking we want a subsection on the WAC language?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kate-goldenring No, I was just suggesting a sub-heading signposting that the text is moving on from talking about plug, to talking about WAC files.

It won't let me leave a suggestion but e.g.

### Using WAC files to go beyond `plug`

or

### Advanced composition with the WAC language

or even

### WAC even the hairiest composition problems into shape with BA's powerful new tools

for the full "MSDN magazine circa 2001" experience

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see! Too many good suggestions to choose from! Updated the doc to use the middle suggestion and added an intro paragraph on "why wac"

component-model/src/creating-and-consuming/composing.md Outdated Show resolved Hide resolved
cd ..
wasm-tools compose calculator/target/wasm32-wasi/release/calculator.wasm -d adder/target/wasm32-wasi/release/adder.wasm -o composed.wasm
wasm-tools compose command/target/wasm32-wasi/release/command.wasm -d composed.wasm -o final.wasm
wac plug calculator/target/wasm32-wasi/release/calculator.wasm --plug adder/target/wasm32-wasi/release/adder.wasm -o composed.wasm
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the cd .. is necessary...

component-model/examples/tutorial/README.md Show resolved Hide resolved
component-model/examples/tutorial/README.md Outdated Show resolved Hide resolved
component-model/examples/tutorial/README.md Outdated Show resolved Hide resolved
component-model/src/creating-and-consuming/composing.md Outdated Show resolved Hide resolved
@kate-goldenring
Copy link
Collaborator Author

@rylev @itowlson I updated the docs to try to better explain how the wac language works for local components and use plug/socket terminology.

Copy link
Collaborator

@itowlson itowlson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is terrific, @kate-goldenring - thank you so much for working through this. This provides a great introduction and cookbook for common cases, and a clear conceptual framework for people to get deeper into WAC if they need to. Even having used WAC before, I feel way more confident after reading it!

@kate-goldenring kate-goldenring merged commit 120119d into bytecodealliance:main Sep 24, 2024
@kate-goldenring kate-goldenring deleted the wac-plug branch September 24, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants