Skip to content
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

Investigate wasm32-wasi build support #1966

Open
lopopolo opened this issue Jul 23, 2022 · 2 comments
Open

Investigate wasm32-wasi build support #1966

lopopolo opened this issue Jul 23, 2022 · 2 comments
Labels
A-build-target Area: Support for builds of specific targets. O-wasm-wasi Target: Support for building the `wasm32-wasi` target. S-speculative Status: This is just an idea.

Comments

@lopopolo
Copy link
Member

lopopolo commented Jul 23, 2022

Investigate compiling Artichoke on the wasm32-wasi target. Such an artifact would be able to be run with wasmtime [GitHub] or wasmer [GitHub].

Notes

Since Artichoke has C dependencies (mruby, oniguruma) and depends on the cc crate, it is necessary to provide a C (or soon C++) compiler that can target wasm32-wasi as well as a suitable libc and sysroot.

wasi-sdk provides these things and bundles wasi-libc.

Status

2022-07-23

Artichoke is not able to build for WASI. Per WebAssembly/wasi-sdk#Notable Limitations:

This repository does not yet support C++ exceptions. C++ code is
supported only with -fno-exceptions for now. Similarly, there is not
yet support for setjmp/longjmp. Work on support for exception handling
is underway at the language level which will support both of these
features.

Currently, Artichoke's configuration of mruby uses setjmp/longjmp. After #1904 is merged, Artichoke's configuration of mruby will use C++ exceptions.

The compilation errors look like:

  running: "/wasi-sdk/wasi-sdk-16.0/bin/clang" "--sysroot=/wasi-sdk/wasi-sdk-16.0/share/wasi-sysroot" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-wasi" "-I" "/app2/artichoke-backend/vendor/mruby/include" "-I" "/app2/artichoke-backend/vendor/mruby/mrbgems/mruby-class-ext/include" "-I" "/app2/artichoke-backend/vendor/mruby/mrbgems/mruby-compiler/core" "-I" "/app2/artichoke-backend/vendor/mruby/mrbgems/mruby-error/include" "-I" "/app2/artichoke-backend/vendor/mruby/mrbgems/mruby-eval/include" "-I" "/app2/artichoke-backend/vendor/mruby/mrbgems/mruby-fiber/include" "-I" "/app2/artichoke-backend/vendor/mruby/mrbgems/mruby-metaprog/include" "-I" "/app2/artichoke-backend/vendor/mruby/mrbgems/mruby-method/include" "-I" "/app2/artichoke-backend/vendor/mruby/mrbgems/mruby-pack/include" "-I" "/app2/artichoke-backend/vendor/mruby/mrbgems/mruby-proc-ext/include" "-I" "/app2/artichoke-backend/vendor/mruby/mrbgems/mruby-sprintf/include" "-I" "/app2/artichoke-backend/vendor/mruby/include" "-I" "/app2/artichoke-backend/cext/mrbsys/include" "-I" "/app2/artichoke-backend/vendor/mruby/include" "-DARTICHOKE" "-DMRB_ARY_NO_EMBED" "-DMRB_GC_TURN_OFF_GENERATIONAL" "-DMRB_INT64" "-DMRB_NO_BOXING" "-DMRB_NO_PRESYM" "-DMRB_NO_STDIO" "-DMRB_UTF8_STRING" "-o" "/app2/target/wasm32-wasi/debug/build/artichoke-backend-128c0ff89637f957/out/vendor/mruby/src/error.o" "-c" "vendor/mruby/src/error.c"
  cargo:warning=In file included from vendor/mruby/src/error.c:17:
  cargo:warning=/app2/artichoke-backend/vendor/mruby/include/mruby/throw.h:33:10: fatal error: 'setjmp.h' file not found
  cargo:warning=#include <setjmp.h>
  cargo:warning=         ^~~~~~~~~~
  cargo:warning=1 error generated.
  exit status: 1

There is an open RFC against wasi-sdk to add support for Wasm exceptions:

Build Steps

I'm not sure whether the wasi-sdk works on non-Linux environments. The below steps use Docker on macOS.

lopopolo@macos:/path/to/artichoke# cargo clean
lopopolo@macos:/path/to/artichoke# docker run -it -v `pwd`:/app rust:1.62.1 bash
root@ec467dc9a04d:/# rustup target add wasm32-wasi
info: downloading component 'rust-std' for 'wasm32-wasi'
info: installing component 'rust-std' for 'wasm32-wasi'
 17.0 MiB /  17.0 MiB (100 %)  14.9 MiB/s in  1s ETA:  0s
root@ec467dc9a04d:/# mkdir /app2
root@ec467dc9a04d:/# cp -r app/* app2/
root@ec467dc9a04d:/# mkdir wasi-sdk
root@ec467dc9a04d:/# cd wasi-sdk/
root@ec467dc9a04d:/wasi-sdk# export WASI_VERSION=16
root@ec467dc9a04d:/wasi-sdk# export WASI_VERSION_FULL=${WASI_VERSION}.0
root@ec467dc9a04d:/wasi-sdk# wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz
... snip ...
root@ec467dc9a04d:/wasi-sdk# tar xvf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz
... snip ...
root@ec467dc9a04d:/wasi-sdk# export WASI_SDK_PATH=`pwd`/wasi-sdk-${WASI_VERSION_FULL}
root@ec467dc9a04d:/wasi-sdk# export CC="${WASI_SDK_PATH}/bin/clang --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot"
root@ec467dc9a04d:/wasi-sdk# cd /app2
root@ec467dc9a04d:/app2# cargo build --target wasm32-wasi --no-default-features --features kitchen-sink
... snip ...
The following warnings were emitted during compilation:

warning: In file included from vendor/mruby/src/error.c:17:
warning: /app2/artichoke-backend/vendor/mruby/include/mruby/throw.h:33:10: fatal error: 'setjmp.h' file not found
warning: #include <setjmp.h>
warning:          ^~~~~~~~~~
warning: 1 error generated.

error: failed to run custom build command for `artichoke-backend v0.13.0 (/app2/artichoke-backend)`
... snip ...
warning: build failed, waiting for other jobs to finish...
@lopopolo lopopolo added A-build-target Area: Support for builds of specific targets. S-speculative Status: This is just an idea. labels Jul 23, 2022
@lopopolo
Copy link
Member Author

TODO: add O-wasm-wasi label.

lopopolo added a commit that referenced this issue Jul 23, 2022
lopopolo added a commit that referenced this issue Jul 23, 2022
@lopopolo
Copy link
Member Author

This ticket is likely to be the solution to:

lopopolo added a commit that referenced this issue Jul 23, 2022
@lopopolo lopopolo added the O-wasm-wasi Target: Support for building the `wasm32-wasi` target. label Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-target Area: Support for builds of specific targets. O-wasm-wasi Target: Support for building the `wasm32-wasi` target. S-speculative Status: This is just an idea.
Development

No branches or pull requests

1 participant