-
Notifications
You must be signed in to change notification settings - Fork 126
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
Add WASI (WebAssembly) cross compile support #550
Conversation
I've also successfully tested this PR on linux. For what it's worth, here is the detailed script of what I ran to build (although I think @agoode 's existing documentation in this PR suffices) Additionally, I was able to build a fairly nontrivial project, namely the twelf logical framework, and it executed fine on a WASI runtime. A demo is available at https://jcreedcmu.github.io/twelf-wasm/ --- this was exactly the thing that I hoped this PR would enable. This exercises at least file IO as a proof of concept.
|
This looks very nice; I'm pleasantly surprised at how minimal the PR is to support WebAssembly/WASI. |
ce17fa2
to
af7f6ea
Compare
[This pull request against MLton](MLton/mlton#550) enables compiling to WebAssembly, so that twelf can be run from, e.g. inside a web browser. A demo can be seen at: https://jcreedcmu.github.io/twelf-wasm/ Test plan: - ensure that the make target `twelf-server-mlton` still produces a twelf-server binary - ensure that the make target `wasi` produces `bin/twelf.wasm`, when an appropriate version of `mlton` is installed. Detailed instructions for building follow. Comments on the above pull request have more details pertaining to build and install of GMP. Checked out https://github.com/agoode/mlton/tree/wasm2 at commit MLton/mlton@d2b9e5d put into `$BUILD/dev-mlton` and then did the following: ``` MLTON=$BUILD/mlton-wasm2-INSTALL cd $BUILD/dev-mlton make clean make CC=$WASISDK/bin/clang \ AR=$WASISDK/bin/ar \ RANLIB=$WASISDK/bin/ranlib \ TARGET_OS=wasi \ TARGET_ARCH=wasm32 \ TARGET=wasm32-unknown-wasi \ WITH_GMP_DIR=$BUILD/gmp-wasi-INSTALL \ PREFIX=$MLTON \ dirs runtime install-runtime cd $BUILD/dev-mlton make clean make all make PREFIX=$MLTON install cd $BUILD/twelf mlton=$BUILD/mlton-wasm2-INSTALL/bin/mlton make wasi ```
[This pull request against MLton](MLton/mlton#550) enables compiling to WebAssembly, so that twelf can be run from, e.g. inside a web browser. A demo can be seen at: https://jcreedcmu.github.io/twelf-wasm/ Test plan: - ensure that the make target `twelf-server-mlton` still produces a twelf-server binary - ensure that the make target `wasi` produces `bin/twelf.wasm`, when an appropriate version of `mlton` is installed. Detailed instructions for building follow. Comments on the above pull request have more details pertaining to build and install of GMP. Checked out https://github.com/agoode/mlton/tree/wasm2 at commit MLton/mlton@d2b9e5d put into `$BUILD/dev-mlton` and then did the following: ``` MLTON=$BUILD/mlton-wasm2-INSTALL cd $BUILD/dev-mlton make clean make CC=$WASISDK/bin/clang \ AR=$WASISDK/bin/ar \ RANLIB=$WASISDK/bin/ranlib \ TARGET_OS=wasi \ TARGET_ARCH=wasm32 \ TARGET=wasm32-unknown-wasi \ WITH_GMP_DIR=$BUILD/gmp-wasi-INSTALL \ PREFIX=$MLTON \ dirs runtime install-runtime cd $BUILD/dev-mlton make clean make all make PREFIX=$MLTON install cd $BUILD/twelf mlton=$BUILD/mlton-wasm2-INSTALL/bin/mlton make wasi ``` Co-authored-by: Jason Reed <jreed@gmail.com>
There are some improvements coming to the wasi-sdk (notably WebAssembly/wasi-sdk#388), so I would maybe avoid merging this PR right now in favor of a more simple one that may come soon. |
My goal is to set down once and for all a reproducible build process that shows how the `twelf.wasm` was constructed, instead of it existing ad hoc across my memory and comments on the PR MLton/mlton#550 . Already I discovered a couple of crucial omissions in those comments. This still deserves some cleanup, as the ordering of steps is not really a coherent narrative, because I added some as I discovered them. A cleaner one is forthcoming.
ce57803
to
dc9e1c5
Compare
@agoode is this PR ready to be merged? It seems that it is working well for the Twelf project. |
I'm going to split it up into a few smaller PRs. There are some good changes that can go in now, and a few others I want to revisit for the updated wasi-sdk-22. I'll send some new PRs when they are ready. |
811395d
to
f138ce9
Compare
This requires: - WASI SDK: https://github.com/WebAssembly/wasi-sdk - wasmtime: https://wasmtime.dev/
Looks good. (Either I missed it or changing to "ready for review" didn't re-raise the issue in my notifications.) |
Fixes #549.
See https://github.com/agoode/mlton/blob/wascally/doc/guide/src/RunningOnWASI.adoc for instructions.
I've only tested with macOS, but I could try Linux also.
This makes a bunch of improvements to cross compilation support in general, since WASI is really always going to be a cross target.
Potentially controversial is leaving unimplemented POSIX functions missing from wasi.c. I think it works well to have this become a linker error instead of a runtime error, but I am open to suggestions.
Thanks to @jcreedcmu for tricking me into doing this.