Repository navigation
Conversation
|
Thanks for putting this together, @simolus3! Having Dart covered across all four guides (especially alongside Rust on the HTTP service page!) is awesome. 1. Timing: Hold for Dart 3.14 Beta (Oct 6) +
|
|
Hey @simolus3, is this PR still up for review or are we still waiting on 3.14 changes to land? |
|
Package updates (and ideally a Dart beta) should land before this is merged and haven't yet. I don't think that prevents a review since the content wouldn't change after the release, but I also don't want to waste your time. So if you prefer to wait until everything is ready from mine and Kevin's perspective, that's fine. |
|
@vados-cosmonic any thoughts on @simolus3's response? We can start reviewing now and just remove/modify callouts when 3.14 and deps are stable: |
|
Hey @mkatychev @simolus3 yeah I think that makes sense -- we'll go ahead and do a review so that we're unblocked when we are ready to merge once stuff lands upstream. I'll get to this today! |
There was a problem hiding this comment.
This is a great start, thanks @simolus3 -- did an initial review and left some thoughts!
|
|
||
| This guide walks through building a Dart component that implements | ||
| the `adder` world defined in the [`adder/world.wit` package][docs-adder]. | ||
| The component will implement the `adder` world, which contains an `add` interface with an `add` function. |
There was a problem hiding this comment.
NIT: I think just pasting the WIT here (we can use a reference so the file stays in sync) would be easier than reading through this prose.
| If you still have questions, feel free to open an issue on [the repository][wasm_tools] | ||
| or reach out on [Zulip][chat]. | ||
|
|
||
| ## 1. Create your Dart project |
There was a problem hiding this comment.
We might want to include a section about tooling/setup here, and that would be a good place for the warning to go
| cd dart_wasm_adder | ||
| ``` | ||
|
|
||
| ## 2. Install the tools |
There was a problem hiding this comment.
| ## 2. Install the tools | |
| ## 2. Install Dart tooling for Wasm |
Something like this?
|
|
||
| ## 2. Install the tools | ||
|
|
||
| All tools requires to create WebAssembly components from Dart can be installed via pub: |
There was a problem hiding this comment.
| All tools requires to create WebAssembly components from Dart can be installed via pub: | |
| All tools required to create WebAssembly components from Dart can be installed via `dart pub`: |
Maybe it's more normal to refer to it as just "pub", but in that case I think even pub nicely indicates that it's a command/binary of some sort.
| dart run wasm_tools witgen -i adder.wit | ||
| ``` | ||
|
|
||
| This generates: |
There was a problem hiding this comment.
This would be a good place to maybe add a blub about what witgen does as a part of wasm_tools
It might also be nice if where we introduce wasm_tools we add an admonition that notes the difference/contrast to @bytecodealliance/wasm-tools.
| ```sh | ||
| wasmtime run bin/dart_wasm_cli.wasm | ||
| ``` | ||
|
|
There was a problem hiding this comment.
NIT: Expected output might be nice to include here
| ``` | ||
|
|
||
| To configure this package for WebAssembly components, add tooling dependencies. | ||
| Additionally, the `wasi` package provides generated bindings to WASI definitions, |
There was a problem hiding this comment.
| Additionally, the `wasi` package provides generated bindings to WASI definitions, | |
| Additionally, the `wasi` package provides generated bindings to WASI definitions (in this case, `wasi:http`), |
Same note about this callout being in the "Writing the HTTP Handler" section
|
|
||
| ## Importing an interface | ||
|
|
||
| The world file (`wit/world.wit`) we generated doesn't specify any imports. |
There was a problem hiding this comment.
NIT: We might do well to link to the previous guide page here -- my first thought might be "which world WIT that we already generated?"
|
|
||
| ### Calling the import from Dart | ||
|
|
||
| Now the declaration of `add` in the adder's WIT file is visible as an import when |
There was a problem hiding this comment.
| Now the declaration of `add` in the adder's WIT file is visible as an import when | |
| Because the `calculator` world imports the `add` interface, the declaration of `add` in the adder's WIT file is visible as an import when |
|
|
||
| ### Fulfilling the import | ||
|
|
||
| When you build this using `dart run wasm_tools compile`, the `add` interface remains unsatisfied |
There was a problem hiding this comment.
| When you build this using `dart run wasm_tools compile`, the `add` interface remains unsatisfied | |
| After building a component with `dart run wasm_tools compile`, the `add` interface remains unsatisfied |
This documents how to create components with the Dart programming language.
Dart compiles to WebAssembly, but has no support for the component model. Instead, it uses Dart-specific set of host imports to implement its functionality. I maintain a toolchain that eliminates these imports by implementing them in plain WebAssembly, and to create WebAssembly components.
This adds Dart pages for functionality that is currently supported (simple components, custom imports, wasi cli and http service).
A lot of this is mildly broken, e.g. this requires a development version of the Dart SDK that hasn't been released yet and my tools are still highly buggy. But this is enough to get components to work, so I think it's worth adding documentation for that.