wasmbind, js-sys and web-sys but for C++

19 views
Skip to first unread message

Mo_Al_

unread,
Aug 18, 2025, 3:58:28 PMAug 18
to emscripten-discuss
Hello all,

I always liked that Rust offered wasm-bindgen, along with js-sys and web-sys, which provided bindings generated from webidl. And I wanted the same thing for C++.

Wasmbind itself consists of 2 libraries:
- jsbind, provides some javascript interfaces required by webbind, with some sugar as well.
- webbind, which is generated  from webidl via the @webref/idl npm package.

This allows for a less stringly-typed api than for example directly using emscripten's val api.

I would appreciate your review and trial.


Note that wasmbind can also target wasm32-unknown-unknown and wasm32-wasi using wasi-libc, wasi-sysroot or the wasi-sdk.

The api looks like:
#include <jsbind/jsbind.hpp>
#include <webbind/webbind.hpp>

using jsbind::Console;
using jsbind::Function;
using namespace webbind;

int main() {
    emlite::init();
    Console con;
    auto document = window().document();
    auto bodies   = document.getElementsByTagName("body");
    if (bodies.length() == 0) {
        con.log("I Ain't got Nobody!");
        return -1;
    }
    auto body   = bodies.item(0);
    auto button = document.createElement("BUTTON")
                      .safe_cast<HTMLButtonElement>().unwrap();
    button.textContent("Click me");
    button.addEventListener(
        "click",
        Function::Fn<void(PointerEvent)>([=](auto e) {
            con.log(e.clientX());
        })
    );
    body.appendChild(button);
    auto style = button.style();
    style.setProperty("color", "red");
    style.setProperty("background-color", "#aaf");
    style.setProperty("border", "solid");
}

Alon Zakai

unread,
Aug 25, 2025, 2:26:38 PMAug 25
to emscripte...@googlegroups.com
Very cool!

I've wondered for a while if a wasm-bindgen-like approach would be useful for people. So I'm curious to see other people's feedback here.

- Alon


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/emscripten-discuss/c63b60a0-34d6-4f17-ba2b-987c73e3521bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages