Zoom link incoming!
https://cosmonic.zoom.us/j/81787322401?pwd=R2lIbmhNcWcvYVRkaGFQSDYraUwzZz09
Hi Folks - We've got a table of 'C' and 'C++' folks here, we are going to walk through the creation of two C components and trying to show case the two components linked together and running.
We are setting up the Zoom call so you can follow along. Any questions, please ask here in this channel and I'll bring it up as we go along.
Step 1 : Required tooling....
Install https://github.com/bytecodealliance/wasm-tools
Install https://github.com/Webassembly/wasi-sdk
Install https://github.com/bytecodealliance/wit-bindgen/releases/tag/wit-bindgen-cli-0.11.0
make sure you have the wasi-sdk, wasm-tools, wit bind-gen
Make sure you get version 20 of the wasi-sdk ...
There is no way to check what version of the wasi-sdk installed, but, if you check that you have clang version 16, that should be WASI SDK 20 .
https://github.com/Kylebrown9/wasmcon2023/
We are looking at this file...
https://github.com/Kylebrown9/wasmcon2023/blob/main/wit/greeter.wit
It contains a line like this - > interface %interface. The weird precentage inside of the name is a bit confusing. Interface is a keyword. Normally you wouldn't be able to use a keyword as an indentifier in your interface name, but the percentage symbol allows you to overcome this problem.
Check out the c folder here -> https://github.com/Kylebrown9/wasmcon2023/tree/main/components/c
I am getting error .
wit-bindgen c ../../wit/greeter.wit --world proxy-greeter
Error: expected default
, world
or interface
, found an identifier
--> ../../wit/greeter.wit:1:1
|
1 | package wasmcon2023:greet
| ^------
I was using old version of wit-bindgen, with latest one, no problem
wit-bindgen-cli 0.11.0 (15907098d 2023-08-30)
Script to setup and install the tools so far
A message was moved here from #componentize-the-world-2023 > Install sc by Shravan Narayan.
cargo install wasmtime-cli --features=component-model
cargo install wasmtime-cli --features=component-model --git https://github.com/bytecodealliance/wasmtime
Latest work-in-progress script
Greeter
@Bailey Hayes - help! how do we get wasm-compose working ? :)
Here is my WIP, Run the c-comp-install.sh
In a wasmtime git checkout: wit-bindgen c crates/wasi/wit --world=wasi:cli/command
Chris Woods said:
Bailey Hayes - help! how do we get wasm-compose working ? :)
Let's do it! Where are we building?
I like to use https://wasmbuilder.app when I'm composing
$ wit-bindgen c crates/wasi/wit --world=wasi:cli/command
$ cat > implementation.c
#include "command.h"
bool exports_wasi_cli_run_run(void) {
return true;
}
$ clang implementation.c command.c command_component_type.o -mexec-model=reactor -o core.wasm
$ wasm-tools component new core.wasm -o component.wasm
$ cargo run --features=component-model -- --wasm-features component-model component.wasm
$ target/debug/wasmtime --wasm-features component-model component.wasm
Here is a simple one component example not using a runner but only relying on wasmtime: https://github.com/matsbror/wasm-c-component-example.git
:wave: if you, like me, are desperate to use classes with WIT from C++ (guest or host side), I created a host/guest combination matrix at https://github.com/cpetig/resource-demo/ - and I am hacking together a wit-bindgen for C++ at https://github.com/cpetig/wit-bindgen - it is far from finished, but I at least understood how to combine the existing tooling for WIT autocode generation and the easy examples in the first repo work already.
Also feel free to ask me more questions in this chat.
Guest code example https://github.com/cpetig/resource-demo/blob/main/guest-cpp/main.cpp, host code example https://github.com/cpetig/resource-demo/blob/main/host-wamr/implementations.cpp
(and sorry for joining late) zoom feels a bit lonely right now
Has anyone tried wasmflow: https://wasmflow.com/docs/getting-started/native-components/
Example of c wasm components
https://github.com/shravanrn/wasm-c-comp-example
Sadly WAMR won't support real components soon, for now I work with modules containing wit information until full support is available.
Example with resouces: https://github.com/cpetig/resource-demo/blob/main/guest-c/main.c
Christof Petig said:
(and sorry for joining late) zoom feels a bit lonely right now
I'm sorry about that! :( - But thank you for joining !
Christof Petig said:
Sadly WAMR won't support real components soon, for now I work with modules containing wit information until full support is available.
Example with resouces: https://github.com/cpetig/resource-demo/blob/main/guest-c/main.c
Yeah, unfortunatley this is true for the WAMR tool. - I'm trying to understand the component model and get some stdout working at the moment. There is no preview2 libc implementation at the moment.
@Dan Gohman what I am working on https://github.com/cpetig/wit-bindgen/blob/main/autosar/radar.wit
Chris Woods said:
Yeah, unfortunatley this is true for the WAMR tool. - I'm trying to understand the component model and get some stdout working at the moment. There is no preview2 libc implementation at the moment.
I modified the preview2 adapter to link statically to libc to generate preview2 modules - which should work nicely with WAMR once I add the new interfaces.
But be careful doing this, the adapter is very complex due to its memory allocation tricks.
And I got a modified wasm-threads wit file which I got working with jco in the browser :ghost: , so I will have some upstreaming to do once I feel confident enough with the solution.
Things we've learnt so far:
I updated my repo with an example with multiple components: https://github.com/matsbror/wasm-c-component-example
It was great meeting you all yesterday and to play with components. Thanks @Dan Gohman for all the support!
@Christof Petig
I saw your great work(https://github.com/cpetig/resource-demo/blob/main/guest-cpp/main.cpp) and https://github.com/cpetig/wit-bindgen.git. It worked well for my project.
Are you going to push "wit-bindgen cpp-host/c-host" to main wit-bindgen? And can we contribute if it can help you to accelerate?
Ayako Akasaka said:
Are you going to push "wit-bindgen cpp-host/c-host" to main wit-bindgen? And can we contribute if it can help you to accelerate?
I replied in the SIG-Guest-Languages stream (Topic: C++ language binding) but saw no further reactions. Is is possible that you can't see this reply?
I'm subscribed to SIG-Guest-Languages generally but the C++ topic was muted for me for some reason, maybe happened to others as well
Thank you for replying my request @Christof Petig and @Milan
Since I haven't subscribed to the "SIG-Guest-Languages" Channel, I haven't noticed. But now I can. So, let me move to there about this topic. Thanks!
Last updated: Nov 22 2024 at 16:03 UTC