Skip to content

Conversation

basicer
Copy link

@basicer basicer commented Sep 20, 2025

Adds WASM32 as a new platform, allowing it provide an implementation of the wasm-c-api interpreter to applications that themselves want to be compiled to wasm.

@yamt
Copy link
Collaborator

yamt commented Sep 22, 2025

what platform is your target?
eg. wasi, emscripten, ...
it's might be better to name the core/shared/platform bits accordingly.

do you have any plan for the CI?

@basicer
Copy link
Author

basicer commented Sep 22, 2025

I've been testing with emscripten, but targeting wasi-sdk.

@lum1n0us
Copy link
Collaborator

Sorry, but I don't fully understand the use case of this PR. Does it mean a wasm32-wasi version of wamr which is compiled by wasi-sdk or emscripten?

@basicer
Copy link
Author

basicer commented Sep 22, 2025

The idea is that for applications that use the wasm-c-api, those applications can still run in the browser by embedding WAMR as the wasm runtime, and allowing WARM to be built for the browser.

@lum1n0us
Copy link
Collaborator

A browser use the WASM runtime via wasm-c-api to execute wasm32-wasi or wasm32-emscripten? WAMR is still a native library for the browser.

@basicer
Copy link
Author

basicer commented Sep 22, 2025

Here is an example use case: ashtonmeuser/godot-wasm#78 That is a plugin for the Godot game engine that allows it to load gameplay logic written in webassembly. The game engine runs on many platforms, but also in the browser. To support running in the browser, some tweaks were needed to WAMR to add WASM32 as a platform.

Copy link
Collaborator

@lum1n0us lum1n0us left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • wasm32 is a target, but the platform name should be specific, like wasi or emscripten.
  • If it's not too much trouble, please create a mini product for the platform to demonstrate how it works. We can then add the corresponding steps in CI.

thread_manager_destroy();
#endif

#if WASM_ENABLE_INVOKE_NATIVE != 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC WASM_ENABLE_INVOKE_NATIVE is designed to prevent the involvement of runtime built-in functions. In that case, -DWAMR_BUILD_LIBC_BUILTIN=0 -DWAMR_BUILD_LIBC_WASI=0 can achieve the same effect, along with -DWAMR_BUILD_QUICK_AOT_ENTRY=0.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess it's a good opportunity to replace the heavy ifdef conditions with something easier to maintain.

@yamt
Copy link
Collaborator

yamt commented Sep 24, 2025

Here is an example use case: ashtonmeuser/godot-wasm#78 That is a plugin for the Godot game engine that allows it to load gameplay logic written in webassembly. The game engine runs on many platforms, but also in the browser. To support running in the browser, some tweaks were needed to WAMR to add WASM32 as a platform.

i'm a bit confused. the project states wasmtime and wasmer support. i don't think they (or any jit-based runtimes) can run on wasm. is the combination just currently not supported?

@basicer
Copy link
Author

basicer commented Sep 24, 2025

i'm a bit confused. the project states wasmtime and wasmer support. i don't think they (or any jit-based runtimes) can run on wasm. is the combination just currently not supported?

Right. Currently that plugin doesn't support the web build. I'm adding WAMR support to that project specifically because it seemed feasible to port WARM's faster interpreter to WASM.

@basicer
Copy link
Author

basicer commented Sep 24, 2025

  • wasm32 is a target, but the platform name should be specific, like wasi or emscripten.

I generally use emscripten's toolchain but pass the -sPURE_WASI=1 option such that it generates executables that can be run on the command line with WASI hosts. What platform would you consider that?

  • If it's not too much trouble, please create a mini product for the platform to demonstrate how it works. We can then add the corresponding steps in CI.

The posix mini target seems to work out of the box with WASI, I'll see about getting the build script setup for that.

#include "platform_common.h"

#if !defined(__wasm32__) && !defined(__EMSCRIPTEN__)
#include "platform_wasi_types.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you avoid using platform_wasi_types.h?

@ashtonmeuser
Copy link

  • wasm32 is a target, but the platform name should be specific, like wasi or emscripten.

I generally use emscripten's toolchain but pass the -sPURE_WASI=1 option such that it generates executables that can be run on the command line with WASI hosts. What platform would you consider that?

Seems like emscripten would be the correct choice for platform here. Practically, as it applies to https://github.com/ashtonmeuser/godot-wasm, emscripten is also what Godot uses to build for the web.

Although a case could be made for WAMR to have a generic unknown platform akin to Rust's wasm32-unknown-unknown target.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants