Skip to content

Conversation

@rioam2
Copy link
Contributor

@rioam2 rioam2 commented Jul 22, 2024

Supersedes #9

This PR adds support for cross-compiling to wasm32-wasi as a CMake target. It builds on top of the wasm32-wasi toolchain here, and more accurately, wasi-sdk.

The example contained in this PR exposes a WebAssembly interface following the reactor model. In other words, it is an example module that exposes functions that can be called in reaction to events on the host.

Usage information from README:

If you wish to expose parts of your library as a WebAssembly module, you can add the extern "C" __attribute__((export_name("<my_function_name>"))) annotation to any function you wish to expose in src/wasm/interface.cpp, and compile using the wasm32-wasi-clang preset. This will generate a minimal WebAssembly binary exposing your exported functions at build/<PRESET>/src/wasm/<Debug|Release|RelWithDebInfo>/lib<PROJECT_NAME>.wasm. This binary conforms to the WASI WebAssembly standard, so it can be utilized in any WASI-supporting runtime like wasmer.io or wasmtime.

A WebAssembly version of your CLI will also be available:

wasmtime run build/<PRESET>/src/cli/<Debug|Release|RelWithDebInfo>/<PROJECT_NAME>_cli

# Prints:
# <PROJECT_NAME> version: 0.0.1

Note

Exposed WebAssembly functions currently only accept parameters and return values of numerical type. This is how core WebAssembly files work, and without additional glue-code or binding generators like wit-bindgen, complex data-types cannot be sent over the runtime's ABI boundary. Complex data must be transferred via pointer and serialized bytes in exported/shared memory.

Acknowledgements:

@rioam2 rioam2 force-pushed the rioam2/add-wasm32-wasi-target branch 9 times, most recently from 73fd21b to 9f9f295 Compare July 24, 2024 14:32
@rioam2 rioam2 force-pushed the rioam2/add-wasm32-wasi-target branch from 096dd02 to a3c7db1 Compare July 25, 2024 07:46
@rioam2 rioam2 marked this pull request as ready for review July 25, 2024 07:48
{ os: ubuntu-latest, preset: x64-linux-gcc-dynamic },
{ os: ubuntu-latest, preset: x86-linux-gcc-dynamic },
{ os: ubuntu-latest, preset: x64-linux-clang-dynamic },
{ os: ubuntu-latest, preset: x86-linux-clang-dynamic },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was removed from .github/ci.yaml in 5efee87, so I removed it here in .github/workflows/ci.yaml as well. It fails due to missing libc++abi on x86

with:
name: logs-${{matrix.target.preset}}
path: |
/usr/local/share/vcpkg/**/*.log
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessary for this PR, but adds a nice way to debug issues in CI.
Can be removed and put up as a separate PR.

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.

1 participant