-
Notifications
You must be signed in to change notification settings - Fork 9
feat(wasi): add wasm32-wasi as a compile target #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
becaf13 to
8d6516f
Compare
|
@msvetkin I've now added an overlay port to get the |
feat(wasi): add wasm32-wasi ci runner to template feat(wasi): fix missed rename feat(wasi): fix missing bracket feat(wasi): remove unrelated ninja-mc changes feat(wasi): do not overwrite system compilers feat(wasi): hoist -stdlib=libc++ flag in clang presets
feat(wasi): remove catch2 overlay port feat(wasi): add back usage file to fmt port
8d6516f to
6382531
Compare
feat(wasi): add wasm32-wasi as a compile target
17808b4 to
902d011
Compare
| sudo wget -qO /etc/apt/trusted.gpg.d/llvm.asc https://apt.llvm.org/llvm-snapshot.gpg.key | ||
| sudo apt-get update | ||
| sudo apt-get install -y -t llvm-toolchain-jammy-17 \ | ||
| clang-17 llvm-17 lld-17 lldb-17 libc++-17-dev \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it clang-17 minimum supported version?
| add_subdirectory(tests) | ||
| if (NOT WASI) | ||
| enable_testing() | ||
| add_subdirectory(tests) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the issue with tests?
src/cmake/add_cpp_pt_module.cmake
Outdated
| if (WASI) | ||
| file(APPEND ${export_file} "\ | ||
| \n#ifndef WASI_EXPORT\ | ||
| \n#define WASI_EXPORT(name) extern \"C\" __attribute__((export_name(name)))\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the issue with generated export macros?
902d011 to
21e4e10
Compare
01260f9 to
c9e34c2
Compare
654a893 to
cc2c32a
Compare
|
Superseded by #13 |
This PR adds support for cross-compiling to wasm32-wasi as a CMake target.
While WebAssembly has many ABI proposals (Emscripten and WASI being the most popular), I have evaluated WASI to be the most stable and future-proof, and therefore, have selected it as the preferred flavor of
wasm32. The selection criteria came down to the following points:The drawback of using WASI is that the proposed specification is not as mature as Emscripten. For example, neither exceptions nor
setjmp/longjmphave support as of now. Threading is supported, but requires a specific flavor of the wasi-sdk, which I have chosen not to implement in this PR for simplicity.Implementation
For this feature, I have bootstrapped
wasi-sdkas a CMake toolchain. The SDK is retrieved from the official Github release artifacts, and cached in the same cache directory asvcpkgis.Using this toolchain, I have integrated it with
vcpkgand added a CMake preset to build both the example CLI and module as WebAssembly binaries.These binaries can be run inside any supported WASI runtime, such as
wasmer.io.My preferred way of testing the CLI program is with wasmer's CLI tool:
This can be run on any host platform or architecture.
Acknowledged shortcomings
As of now, I have not been able to compile Catch2 for
wasm32-wasi. This can probably be done using a custom portfile for wasm32, but ends up being severely handicapped because of limited filesystem libc support. As such, the current CMake configuration disables tests when targetingwasm32-wasi. If the WASI standard matures to allow filesystem access, this can be revisited and added for CTest support on WebAssembly. Here is an example branch of how this would be done: https://github.com/rioam2/cpp-project-template/tree/feat-wasm32-wasi-catch2Exceptions are not specified by the WASI specification nor supported when compiling for
wasm32-wasi. This means code in your module cannot make use oftry..catchblocks, orthrow-ing exceptions. If these wish to be used on other targets, one might need to conditionally insert them using preprocessor checks. I have not yet investigated a better way for accomplishing this that does not degrade the experience for nonwasm32-wasitargets.