Stream: componentize-the-world-2023

Topic: c-athon


view this post on Zulip Bailey Hayes (Sep 08 2023 at 17:12):

Zoom link incoming!

view this post on Zulip Bailey Hayes (Sep 08 2023 at 17:13):

https://cosmonic.zoom.us/j/81787322401?pwd=R2lIbmhNcWcvYVRkaGFQSDYraUwzZz09

view this post on Zulip Chris Woods (Sep 08 2023 at 17:18):

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.

view this post on Zulip Chris Woods (Sep 08 2023 at 17:19):

Step 1 : Required tooling....

view this post on Zulip Bailey Hayes (Sep 08 2023 at 17:20):

Install https://github.com/bytecodealliance/wasm-tools

Low level tooling for WebAssembly in Rust. Contribute to bytecodealliance/wasm-tools development by creating an account on GitHub.

view this post on Zulip Bailey Hayes (Sep 08 2023 at 17:21):

Install https://github.com/Webassembly/wasi-sdk

WASI-enabled WebAssembly C/C++ toolchain. Contribute to WebAssembly/wasi-sdk development by creating an account on GitHub.

view this post on Zulip Bailey Hayes (Sep 08 2023 at 17:21):

Install https://github.com/bytecodealliance/wit-bindgen/releases/tag/wit-bindgen-cli-0.11.0

A language binding generator for WebAssembly interface types - Release wit-bindgen-cli-0.11.0 · bytecodealliance/wit-bindgen

view this post on Zulip Chris Woods (Sep 08 2023 at 17:22):

make sure you have the wasi-sdk, wasm-tools, wit bind-gen

view this post on Zulip Chris Woods (Sep 08 2023 at 17:22):

Make sure you get version 20 of the wasi-sdk ...

view this post on Zulip Chris Woods (Sep 08 2023 at 17:25):

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 .

view this post on Zulip Dan Gohman (Sep 08 2023 at 17:26):

https://github.com/Kylebrown9/wasmcon2023/

Contribute to Kylebrown9/wasmcon2023 development by creating an account on GitHub.

view this post on Zulip Chris Woods (Sep 08 2023 at 17:28):

We are looking at this file...
https://github.com/Kylebrown9/wasmcon2023/blob/main/wit/greeter.wit

view this post on Zulip Chris Woods (Sep 08 2023 at 17:29):

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.

view this post on Zulip Chris Woods (Sep 08 2023 at 17:30):

Check out the c folder here -> https://github.com/Kylebrown9/wasmcon2023/tree/main/components/c

view this post on Zulip Ayako Akasaka (Sep 08 2023 at 17:33):

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
| ^------

view this post on Zulip Ayako Akasaka (Sep 08 2023 at 17:38):

I was using old version of wit-bindgen, with latest one, no problem
wit-bindgen-cli 0.11.0 (15907098d 2023-08-30)

view this post on Zulip Shravan Narayan (Sep 08 2023 at 17:55):

c-comp-install.sh

Script to setup and install the tools so far

view this post on Zulip Notification Bot (Sep 08 2023 at 17:56):

A message was moved here from #componentize-the-world-2023 > Install sc by Shravan Narayan.

view this post on Zulip Ayako Akasaka (Sep 08 2023 at 18:01):

cargo install wasmtime-cli --features=component-model

view this post on Zulip Shravan Narayan (Sep 08 2023 at 18:10):

cargo install wasmtime-cli --features=component-model --git https://github.com/bytecodealliance/wasmtime

A fast and secure runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.

view this post on Zulip Shravan Narayan (Sep 08 2023 at 18:13):

Latest work-in-progress script

c-comp-install.sh

view this post on Zulip Shravan Narayan (Sep 08 2023 at 18:56):

component-endpoint.c

Greeter

view this post on Zulip Chris Woods (Sep 08 2023 at 19:12):

@Bailey Hayes - help! how do we get wasm-compose working ? :)

view this post on Zulip Shravan Narayan (Sep 08 2023 at 19:19):

C-components-WIP.zip

Here is my WIP, Run the c-comp-install.sh

view this post on Zulip Dan Gohman (Sep 08 2023 at 20:01):

In a wasmtime git checkout: wit-bindgen c crates/wasi/wit --world=wasi:cli/command

view this post on Zulip Bailey Hayes (Sep 08 2023 at 20:08):

Chris Woods said:

Bailey Hayes - help! how do we get wasm-compose working ? :)

Let's do it! Where are we building?

view this post on Zulip Bailey Hayes (Sep 08 2023 at 20:13):

I like to use https://wasmbuilder.app when I'm composing

view this post on Zulip Dan Gohman (Sep 08 2023 at 20:37):

$ 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

view this post on Zulip Dan Gohman (Sep 08 2023 at 20:49):

$ target/debug/wasmtime --wasm-features component-model component.wasm

view this post on Zulip Mats Brorsson (Sep 08 2023 at 20:56):

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

A simple wasm component example in C. Contribute to matsbror/wasm-c-component-example development by creating an account on GitHub.

view this post on Zulip Christof Petig (Sep 08 2023 at 20:57):

: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.

A demo showing WASM component model resources in various environments - GitHub - cpetig/resource-demo: A demo showing WASM component model resources in various environments
A language binding generator for WebAssembly interface types - GitHub - cpetig/wit-bindgen: A language binding generator for WebAssembly interface types

view this post on Zulip Christof Petig (Sep 08 2023 at 20:59):

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

view this post on Zulip Christof Petig (Sep 08 2023 at 21:10):

(and sorry for joining late) zoom feels a bit lonely right now

view this post on Zulip Mats Brorsson (Sep 08 2023 at 21:14):

Has anyone tried wasmflow: https://wasmflow.com/docs/getting-started/native-components/

Building native components from scratch.

view this post on Zulip Shravan Narayan (Sep 08 2023 at 21:14):

Example of c wasm components
https://github.com/shravanrn/wasm-c-comp-example

Contribute to shravanrn/wasm-c-comp-example development by creating an account on GitHub.

view this post on Zulip Christof Petig (Sep 08 2023 at 21:20):

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

view this post on Zulip Chris Woods (Sep 08 2023 at 21:32):

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 !

view this post on Zulip Chris Woods (Sep 08 2023 at 21:35):

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.

view this post on Zulip Christof Petig (Sep 08 2023 at 21:39):

@Dan Gohman what I am working on https://github.com/cpetig/wit-bindgen/blob/main/autosar/radar.wit

view this post on Zulip Christof Petig (Sep 08 2023 at 21:46):

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.

view this post on Zulip Christof Petig (Sep 08 2023 at 21:46):

But be careful doing this, the adapter is very complex due to its memory allocation tricks.

view this post on Zulip Christof Petig (Sep 08 2023 at 21:50):

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.

view this post on Zulip Chris Woods (Sep 08 2023 at 21:57):

Things we've learnt so far:

  1. worlds only contain what you specify, so there is no "printf" unless you include the wasi::cli world
  2. the wasi::cli world in wasmtime is the currently active version, it is what wastime implements and is slightly ahead of the not-yet stable standard.
  3. the wasm-tools compose takes a yaml file, there are plans to drop the yaml file and replace it with something else, but not sure what that is at the moment.
  4. wit-bindgen c produces function stubs, in a header file only, but doesn't generate the implementation *.c file. which you need to create yourself.
  5. wit-bindgen c as a string type, which is intended to be UTF8, but is specified in c as a char* -> we should log an issue to change this to a uint8_t so that is is clear that this is not a typical ASCII null terminated string, strlen will not work. (create an issue on github for this)
  6. wit-bindgen c generates stub functions for imported functions, these should be denoted with an "extern" keyword to indicate that they are not to be implemented in the implementation *.c file by the developer.

view this post on Zulip Mats Brorsson (Sep 09 2023 at 14:16):

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!

A simple wasm component example in C. Contribute to matsbror/wasm-c-component-example development by creating an account on GitHub.

view this post on Zulip Ayako Akasaka (Sep 18 2023 at 08:40):

@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?

A language binding generator for WebAssembly interface types - GitHub - cpetig/wit-bindgen: A language binding generator for WebAssembly interface types

view this post on Zulip Christof Petig (Sep 20 2023 at 21:05):

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?

view this post on Zulip Milan (Sep 20 2023 at 23:04):

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

view this post on Zulip Ayako Akasaka (Sep 22 2023 at 13:36):

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: Oct 23 2024 at 20:03 UTC