Repository navigation
Evolution of Wasmer: UI solutions #6215
Replies: 8 comments
|
I don't know if it's very clear why I use gnome libs as examples but it is because I find that GObject introspection would be a perfect replacement for FFI for wasm because it itself contains the bindings and I think that this would be its ideal use case even better than native because in addition to bringing the gnome libraries now available for all bones it also provides the possibility of exposing its own API, in a way that I find much cleaner. I suppose you would like to implement this (if it is possible for you) as another wasm runner but I think that, on the contrary, this functionality would have much more to offer in addition to WASIX (afterwards, of course, it is It's up to you to decide how to do it if the idea of implementing this feature seems desirable to you) because it is not intrusive and extends wasm with what we, the developers, do we need it without having to wait 40 years (which, I find, is in line with the ideology of WASIX). |
|
Very interesting proposal, Felix. We will discuss this internally and get back to you. |
|
I'm very happy to hear that, and I hope a similar solution will be implemented. If you need any help, please don't hesitate to ask ;) |
|
@Felix-feles interesting proposal, indeed! I'll just do a preliminary brain dump here.
I find this to be at odds with WASIX's goal of complete portability. Today, a WASIX module can theoretically run anywhere: browser, command line, server, mobile phone; it makes no difference. It may or may not make sense to do something that could bind a WASIX module to a specific host environment. Even if something like this existed, WASIX modules using this capability would be host-specific and, worse, bound to a certain version of a host library; a module built for GTK 3 won't work with GTK 4. The core philosophy of WASIX is to be cross-platform by abstracting away differences across various environments. This is in direct conflict with that core philosophy. Not to say I'm 100% opposed to the idea, though.
This doesn't work because a WASIX module does not have to be coupled to a Wasmer manifest; any WASM module with WASIX imports is considered a WASIX module and can be run by Wasmer directly (e.g.,
This would have to be versatile enough to cover the entire C ABI; we can't semi-randomly classify native functions as "can be called from WASIX" or "can't be called from WASIX". For example, a This also raises another issue: how does one interact with pointers at all?
This has to be an imported function, since we can't just add instructions to the WASM spec. However, note that each call to an imported function creates considerable overhead and eventually involves pushing and popping some 10 stack frames.
Callbacks are generally not possible, since WASM code can't be interrupted; instead, the guest should poll for events at certain intervals. This is similar to, say, the
Wasmer does not have a GC at this point in time (also a problem for our EH implementation, since exception instances can't be cleaned up properly, leading to memory leaks).
The Wasmer APIs are already stable and only receive breaking changes in major versions. WASIX is still versioned at 0.x and doesn't have a stable API, and is a long way from having one. WASIX syscalls (i.e., the imports) are fully stable and never break. Having a fully stable API for either Wasmer or WASIX is a huge undertaking.
By "WASIX module", do you mean the host-side WASIX implementation? In that case, this is very hard, if not impossible, since WASIX relies on very Rust-specific things, such as async runtimes (mostly But this also creates the additional burden of implementing a WASIX compatibility adapter for any library you would wish to use. For example, one would require a (platform-specific) Still, I find this to be the best way for WASIX modules to interact with host libraries, due to the pointer issues discussed above. I'm just skeptical of the feasibility of developing such glue modules. Do note that the glue module would have to expose every GTK function anyway, since GTK functions can't be called directly by the WASIX runtime. The stack for such a call, from WASM to GTK, would look like this:
If a WASIX module needs to make repeated function calls to a native library, it would become quite slow. There are very few ways to optimize this situation.
WASIX does not expose any graphics-related functionality. If it did, this would probably be a write-once, run-everywhere thing, and much simpler still than implementing what is proposed here. |
|
It was only a proposal: my initial problem was the disproportionate difficulty of creating a clean graphical interface, which led me into the following issue: module imports do not interact directly with the host but rather within a separate box, according to my understanding of the error message generated by A solution to the graphical interface problem would be to add something like Winit + Wry to normalize the environment across platforms, which would then become a web UI + WASIX calls. It would then be necessary to add extended DOM support to wasmer-cli as well as web embedding, but this would provide a way to normalize the environment by bringing the best of both worlds (web + native). Of course, the WASM should continue to be executed by Wasmer, not by the webview, but only expose WASM → web view/browser calls. A solution to the other problem: for now, as I understand it, if I use a library in a WASM project and then compile with |
|
Well, GUIs are hard no matter how you go about it. Dynamic linking against other WASM libraries is already possible, but that doesn't eliminate the need for some sort of interface with the underlying OS and window manager. The real question is how one can set up a relatively cross-platform way to do GUI and expose it to wasm through some sort of standardised interface. |
Another solution would be:
My suggestion:
Core idea:(Instead of considering WASIX as “WASM with system calls”, we could see it as:) Using WASM Component Model / WIT as a stable and cross-platform portable ABI (well stability we are not there yet ;) Running on a universal instruction set: WASM (that is already the case) Distributed via a unified dependency and package system Executable on:
=> In this model, Wasmer is not only an execution environment; it becomes a portable execution platform. Architectural vision 1. Universal architecture: WebAssemblyWASM already offers:
It is currently the only realistic universal binary architecture functioning across browsers, servers, and native environments. This makes it an ideal foundation for a sustainable application platform. 2. Universal ABI and AbstractionsAs said above using Wasm Component Model and WIT as ABI, but:
In this model, applications are not “Linux applications” or “macOS applications”; they are WASM applications (source code written once without modifications but able to be distributed everywhere). 3. Unified package and dependency modelInstead of statically embedding everything into a single WASM binary:
Version resolution is handled by a standardized package system integrated into Wasmer (maybe based on the current one). This would allow:
while preserving the possibility to call wasm via embeddings for other languages. This model is conceptually similar to Flatpak/nix runtimes but being fully cross-platform. 4. Capability-based profilesTo preserve portability while optimizing power:
Wasmer determines the allowed functionalities This preserves the Wasmer philosophy while allowing the development of simple and functional all-in-one applications for desktop, web and mobile. 5. Browser, desktop and mobile compatibilityThe core architecture being WASM:
Why this is powerful?:
Conceptual analogy:
What this is not:
It is rather about elevating WASIX to the level of a stable and universal abstraction layer. Final visionA single source code → Wasmer compiler (like cargo wasix but with the addition of the things mentioned throughout this brilliant idea) → A package containing the wasm file and a manifest with permissions (like on Android) and dynamic dependencies (of course a standalone wasm can also function the same way as a standalone binary on Linux) → Wasmer → Executed on any environment ranging from the browser to the mobile device and including desktop. Wasmer therefore becomes a universal execution platform based on WASM with WASIX as POSIX implementation as well as graphical interface abstractions using Winit and Wry. I believe this direction could considerably expand the strategic role of Wasmer, and allow truly developing once to build an application for web mobile or desktop without doing bindings or glue code. I would be very interested in exploring this direction in more detail if it fits within the long-term vision of your project. |
|
I mean, almost all of this already exists in Wasmer today. The interesting additions are capability profiles and any sort of support for GUI stuff. |
Uh oh!
There was an error while loading. Please reload this page.
Motivation
Today, writing real “host bindings” from a WASIX/WASMER-WASI module to native system libraries (e.g. GTK4/GObject/Pango/Cairo, Vulkan, proprietary SDKs) requires shipping and maintaining a dedicated native “launcher host” binary (or a large amount of hand-written wrappers). This defeats the goal of distributing a single WASIX executable and makes many desktop-class use cases awkward:
.so/ELF) in a controlled, ergonomic way.In short: WASIX is close to being a portable “userland” runtime, but it lacks a generic, capability-controlled mechanism for invoking host-native APIs without requiring a bespoke host application per project. This is the blocker that prevents “single-file WASIX apps” from integrating with desktop stacks in a practical way.
Proposed solution
Introduce a capability-based “Native Host Binding Layer” for WASIX: a standardized, sandbox-respecting way for a WASIX module to request and use native library bindings that are implemented by the Wasmer runtime (host), without bundling a custom host binary.
The proposal has four parts:
Declarative native capabilities in the package/manifest
A standard “Variant + Handle” ABI for dynamic calls
extern "C"import per function does not scale.variantrepresentation plus opaquehandles to host objects.handle+error.A safe dynamic call surface implemented by the runtime
Expose runtime-provided imports such as (names are illustrative):
native.open(capability: string) -> handlenative.call(target: handle, symbol: string, args: list<variant>) -> variantnative.get(handle, property: string) -> variantnative.set(handle, property: string, value: variant)native.subscribe(handle, signal: string, callback_id: u64) -> subscription_handlenative.unsubscribe(subscription_handle)native.drop(handle)Crucially:
Event-loop / callback marshaling support
How this solves the motivating problem:
Other proposed solution (Part 2): Stable Host API Layer (WASIX-API), inspired by N-API
In addition to the dynamic binding layer described above, I propose introducing a stable, versioned Host API layer for WASIX, conceptually similar to Node.js’ N-API (and its Rust ecosystem counterpart,
napi-rs).The core idea is:
Today, if a developer writes a custom host binding by embedding Wasmer or exposing ad-hoc imports, that integration is tightly coupled to:
This creates fragility and discourages ecosystem-level host extensions.
A WASIX-API layer would:
Define a versioned, stable C-compatible ABI between the WASIX module and the host.
Provide runtime-managed:
variantvalue handling,Allow third-party “host extension modules” to be written once against this stable ABI.
Conceptually:
Similarly, WASIX-API would:
Separate Wasmer internals from host bindings.
Allow:
to be implemented once against a stable ABI.
This would enable an ecosystem model where:
This approach has several advantages:
Importantly, this remains compatible with the capability-based security model:
In short:
The dynamic binding layer enables what can be called.
The WASIX-API layer stabilizes how it is called across runtime versions.
Alternatives
Write a custom native host binary per application
IPC to an external “bridge service”
Port GTK and the whole GNOME stack to WASI/WASIX
Purely static bindings (one import per native function)
Why the proposed solution is better:
Additional context
A concrete motivating example is GTK4 via GObject Introspection. The GNOME ecosystem already provides machine-readable API metadata (GIR/typelib). In principle, a runtime-native binding layer could use this to expose GTK without generating thousands of hand-written wrappers, while still enforcing allowlists by namespace/version.
It may also be useful to compare this with Deno, which is likewise a sandboxed and security-focused runtime (for JavaScript/TypeScript). Deno enforces a strict capability model (e.g. --allow-read, --allow-net, etc.), yet it still provides controlled access to native functionality through mechanisms like FFI and dynamic library loading. While Deno’s FFI is relatively low-level and not ergonomically suited for large, dynamic ecosystems like GTK, it demonstrates that a sandboxed runtime can safely expose host-native functionality under explicit permission flags. The proposal here follows a similar philosophy, but aims to provide a higher-level, capability-driven and variant-based abstraction better suited for complex native APIs, rather than raw pointer-level FFI.
All reactions