About supporting EMScripten

Sebastiaan Koppe mail at skoppe.eu
Thu Aug 6 10:15:54 UTC 2020

On Wednesday, 5 August 2020 at 21:46:49 UTC, Hipreme wrote:
> If I have some way to test and help, I would be happy already.
> Is there some built libraries already? Or I'll need to run 
> ldc-build-runtime myself?

You need to run it yourself. Very manual at the moment. Here are 
some very rough instructions.

1) Clone ldc and checkout my PR mentioned above.

2) Download and extract 
https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-8/wasi-sdk-8.0-linux.tar.gz somewhere.

3) export WASI_SDK_PREFIX=<path/to/wasi-sdk-8.0>

4) go into the ldc's runtime folder and run `ldc-build-runtime 
--ninja "--dFlags=-mtriple=wasm32-wasi" --ldcSrcDir=../ 
CMAKE_TOOLCHAIN_FILE="$WASI_SDK_PREFIX/share/cmake/wasi-sdk.cmake" WASI_SDK_PREFIX=$WASI_SDK_PREFIX BUILD_SHARED_LIBS=OFF` (you may need to build ldc-build-runtime first).

That should get you a wasm build of druntime and phobos in 

5) Add this to ldc2.conf and fix the folders for your install

     switches = [
     post-switches = [
     lib-dirs = 
6) create a dub project somewhere, add `buildRequirements 
"allowWarnings"` to the dub.sdl

   void main() {
     import core.stdc.stdio;

7) compile that with `dub --arch=wasm32-unknown-unknown-wasm 
--build-mode=allAtOnce` (from memory).

8) run with wasmtime or wasmer

To get it to run in the browser you need a WASI loader, as it 
will depend on several WASI runtime functions.

If in doubt consult the `azure-pipelines/posix.yml` and search 
for wasm (it will have everything until the dub project).

> So, is it possible to integrate the EMScripten SDL port with 
> what you're doing?

I rather not, but I guess it is possible.

More information about the digitalmars-d-ldc mailing list