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
`runtime/ldc-build-runtime.tmp/lib`.
5) Add this to ldc2.conf and fix the folders for your install
```
"^wasm(32|64)-":
{
switches = [
"-defaultlib=c,druntime-ldc,phobos2-ldc",
"-link-internally",
];
post-switches = [
"-I<path/to/runtime/druntime/src>",
"-I<path/to/runtime/phobos>",
],
lib-dirs =
["<path/to/runtime/ldc-build-runtime.tmp/lib>","<path/to/wasi-sdk-8.0/share/wasi-sysroot/lib/wasm32-wasi/>"];
};
```
6) create a dub project somewhere, add `buildRequirements
"allowWarnings"` to the dub.sdl
app.d
```
void main() {
import core.stdc.stdio;
printf("exit");
}
```
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