Skip to content

Add build file for mlton wasm compilation#4

Merged
robsimmons merged 1 commit into
standardml:masterfrom
jcreedcmu:jcreed/mlton-wasm
Feb 29, 2024
Merged

Add build file for mlton wasm compilation#4
robsimmons merged 1 commit into
standardml:masterfrom
jcreedcmu:jcreed/mlton-wasm

Conversation

@jcreedcmu
Copy link
Copy Markdown
Collaborator

Since compilation to webassembly with MLTon is demonstrably feasible, I would like to upstream the minor change that was required to get it to work.

Copy link
Copy Markdown
Member

@robsimmons robsimmons left a comment

Choose a reason for hiding this comment

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

In general I'm totally on board here, but is there any chance those huge MLB files can be refactored and shared with other mlb files?

@jcreedcmu
Copy link
Copy Markdown
Collaborator Author

You're right, that would be better, will do.

[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
```
Copy link
Copy Markdown
Member

@robsimmons robsimmons left a comment

Choose a reason for hiding this comment

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

❤️ 🚢 🧝

@robsimmons robsimmons merged commit d357dbe into standardml:master Feb 29, 2024
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.

2 participants