Conversation
|
I'm not a C expert so it's probably going to take a while (and we probably need a set of different eyes on this) but thanks for this1 |
|
A bit late but looking some more at this, to get this across the line we would need to:
We will definitely step in to help finish this up @ohAitch so no need to worry about it -- after chatting it looks like there are a few more changes that need to be made documentation wise to make everything coherent. |
There was a problem hiding this comment.
Thank you for putting this together! I put copilot to work to help make this pretty close to ready, filling in the docs and making the Dockerfile cross arch. I PR'd it into your branch here ohAitch#1 for you to review. Feel free to pull that in instead of directly resolving my suggestions.
| @@ -0,0 +1,2 @@ | |||
| @_default: | |||
There was a problem hiding this comment.
Can you change this to a Makefile since those are used more broadly? Maybe add build and run targets. Or we remove it for now
There was a problem hiding this comment.
this file is more than the example host -- it is all in one, building the guest and the host, which i think is great, but a host-only one where you could pass in your adder.wasm may also be useful. I'll PR in a suggestion
There was a problem hiding this comment.
Yep with #333 in it should totally just use the checked in one.
|
Oh thanks for looking into this, I totally missed the first update comment. |
TODO deduplicate with add.wasm see bytecodealliance#333 ```sh cd component-model/examples/example-c-host gcc -o host host.c -lwasmtime && ./host 6 7 adder.wasm ``` Co-authored-by: Shelley <shelley@exe.dev>
I had some difficulty setting up the C toolchains, here's everything pinned down as a sanity check ```sh docker build -t example-c-host . docker run example-c-host ``` Co-authored-by: Shelley <shelley@exe.dev>
Documentation is not my forté but the current "running things from C is impossible due to #issue (closed)" is _definitely_ out of date. Needs revision into a more helpful pointer to the code introduced in this PR, whatever its project name and contents shall end up being. Possibly broken out into a separate .md fragments like the rust one, possibly that was only necessary to share instructions with rust.md and the existence of the c/c++ host can stay local to this file.
- Fills in documentation on how to use the C host - Updates Dockerfile to be cross architecture - Adds a new Dockerfile that is just the host Signed-off-by: Kate Goldenring <kgoldenr@akamai.com>
Signed-off-by: Kate Goldenring <kgoldenr@akamai.com>
…volume mount - Delete Dockerfile.guest_and_host (broken wasi-sdk arch mapping; unnecessary now that upstream add.wasm is available via rebase) - Rename Dockerfile.host → Dockerfile - Fix missing trailing newline - Update c.md: remove guest_and_host references, fix Docker instructions to use volume mount with $(pwd)-relative path Co-authored-by: Shelley <shelley@exe.dev>
Tests both the native build (gcc + wasmtime C API) and the Docker workflow against the checked-in add.wasm. Co-authored-by: Shelley <shelley@exe.dev>
kate-goldenring
left a comment
There was a problem hiding this comment.
@ohAitch thank you for getting these docs updated. This LGTM but I'll wait for your final thumbs up before merging
|
Changes incorporated and rebased, no more TODOs in files I've touched, host-only cross-platform dockerfile, tyvm kate. CI green though you may wish to drop one of the two. Seems like a good time to un How are we doing on
|
kate-goldenring
left a comment
There was a problem hiding this comment.
some suggestions of how to avoid "host" wording
| wasmtime --invoke 'add(2,2)' adder.wasm | ||
| ``` | ||
|
|
||
| ## 7. Run the component from the example C host |
There was a problem hiding this comment.
| ## 7. Run the component from the example C host | |
| ## 7. Run the component from C/C++ Applications |
|
|
||
| You can either use a Dockerfile to execute your add component with the C application or directly run the application. | ||
|
|
||
| ### Option A: Compile and run the host directly |
There was a problem hiding this comment.
| ### Option A: Compile and run the host directly | |
| ### Option A: Run the C application directly |
| ### Option A: Compile and run the host directly | ||
|
|
||
| If the Wasmtime C API headers and library are installed on your system, | ||
| you can compile and run the host directly: |
There was a problem hiding this comment.
| you can compile and run the host directly: | |
| you can compile and run the application directly: |
There was a problem hiding this comment.
can the "host" wording here be renamed "application" both in file naming and in content
| @@ -0,0 +1,127 @@ | |||
| /** | |||
| * C host for the adder WebAssembly component. | |||
There was a problem hiding this comment.
| * C host for the adder WebAssembly component. | |
| * C application that embeds Wasmtime and executes a component that does addition |
| ## 6. Run the component with `wasmtime --invoke` | ||
|
|
||
| The following section requires you to have [a Rust toolchain][rust] installed. | ||
| If you want to quickly run the `add` export without writing a host application that embeds Wasmtime, |
There was a problem hiding this comment.
| If you want to quickly run the `add` export without writing a host application that embeds Wasmtime, | |
| If you want to quickly run the `add` export without writing an application that embeds Wasmtime, |
| ## 7. Run the component from the example C host | ||
|
|
||
| This repository includes a C application that can execute components that implement the add interface. This application embeds Wasmtime using the Wasmtime C API: | ||
| `component-model/examples/example-c-host/host.c`. |
There was a problem hiding this comment.
| `component-model/examples/example-c-host/host.c`. | |
| `component-model/examples/example-c-application/app.c`. |
| The application expects three arguments: the two numbers to add and the Wasm component that executed the addition. For example: | ||
|
|
||
| ```sh | ||
| ./adder-host <x> <y> <path-to-component.wasm> |
There was a problem hiding this comment.
| ./adder-host <x> <y> <path-to-component.wasm> | |
| ./app <x> <y> <path-to-component.wasm> |
| cd component-model/examples/example-c-host | ||
| gcc -o adder-host host.c -lwasmtime | ||
| ./adder-host 1 2 /absolute/path/to/adder.wasm |
There was a problem hiding this comment.
| cd component-model/examples/example-c-host | |
| gcc -o adder-host host.c -lwasmtime | |
| ./adder-host 1 2 /absolute/path/to/adder.wasm | |
| cd component-model/examples/example-c-application | |
| gcc -o app app.c -lwasmtime | |
| ./app 1 2 /absolute/path/to/adder.wasm |
Previous discussion in bytecodealliance/wasmtime#6987 (comment)
Documentation in particular needs work.