-
-
Notifications
You must be signed in to change notification settings - Fork 293
Emscripten: Add druntime & Phobos support #5259
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
base: master
Are you sure you want to change the base?
Changes from all commits
80bccc9
e5da7df
1f50a08
9ed0812
a4e9abd
f75de5e
a825d0c
834c6d1
918f918
8771d6e
e4616bf
f342c2c
06c29f2
346bf95
2d81f40
7ef92df
ca0e64f
4459e8d
2830c39
7cbdd31
9beaff6
33d6afb
aad1338
1956ff6
e18b055
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| name: "Emscripten: Install additional prerequisites" | ||
| inputs: | ||
| emsdk_version: | ||
| required: false | ||
| default: '6.0.6' | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: "Install emsdk" # into ../emsdk | ||
| shell: bash | ||
| run: | | ||
| set -eux | ||
| cd .. | ||
|
|
||
| git clone https://github.com/emscripten-core/emsdk.git | ||
| cd emsdk | ||
| ./emsdk install '${{ inputs.emsdk_version }}' | ||
| ./emsdk activate '${{ inputs.emsdk_version }}' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| name: "Emscripten: Cross-compile druntime & phobos incl. test runners, install libs + .conf, run druntime & phobos unittests" | ||
| inputs: | ||
| arch: | ||
| required: true | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Cross-compile druntime & phobos incl. test runners & install libs + .conf | ||
| shell: bash | ||
| run: | | ||
| set -eux | ||
| cd .. | ||
|
|
||
| os='emscripten' | ||
| arch='${{ inputs.arch }}' | ||
| triple="$arch-unknown-$os" | ||
|
|
||
| bootstrap-ldc/bin/ldc-build-runtime \ | ||
| --ninja \ | ||
| --dFlags="-mtriple=$triple" \ | ||
| --linkerFlags="--preload-file;/usr/share/zoneinfo" \ | ||
| --ldcSrcDir="$PWD/ldc" \ | ||
| --installWithSuffix="-$os-$arch" \ | ||
| --testrunners \ | ||
| CMAKE_INSTALL_PREFIX="$PWD/install" \ | ||
| RT_CONF_TRIPLE_REGEX="$arch-.*-$os" \ | ||
| CMAKE_TOOLCHAIN_FILE="$PWD/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" \ | ||
| BUILD_LTO_LIBS=ON | ||
|
|
||
| - name: Run druntime unittests | ||
| shell: bash | ||
| run: | | ||
| set -eux | ||
| cd ../ldc-build-runtime.tmp | ||
|
|
||
| ../emsdk/node/*/bin/node ./druntime-test-runner-debug.js | ||
| ../emsdk/node/*/bin/node ./druntime-test-runner.js | ||
|
|
||
| - name: Run phobos unittests | ||
| shell: bash | ||
| run: | | ||
| set -eux | ||
| cd ../ldc-build-runtime.tmp | ||
|
|
||
| ../emsdk/node/*/bin/node ./phobos2-test-runner-debug.js | ||
| ../emsdk/node/*/bin/node ./phobos2-test-runner.js | ||
|
|
||
| - name: Run `importc_compare` | ||
| shell: bash | ||
| run: | | ||
| set -eux | ||
| cd .. | ||
|
|
||
| os='emscripten' | ||
| arch='${{ inputs.arch }}' | ||
| triple="$arch-unknown-$os" | ||
|
|
||
| bootstrap-ldc/bin/ldc2 \ | ||
| -defaultlib=druntime-ldc -L-Linstall/lib-$os-$arch \ | ||
| -gcc="$PWD/emsdk/upstream/emscripten/emcc" \ | ||
| --mtriple=$triple \ | ||
| -I$PWD/ldc/runtime/druntime/test/importc_compare/src \ | ||
| $PWD/ldc/runtime/druntime/test/importc_compare/src/importc_compare.d | ||
|
|
||
| emsdk/node/*/bin/node ./importc_compare.js |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,6 +104,10 @@ if("${TARGET_SYSTEM}" MATCHES "WASI|Emscripten") | |
|
|
||
| append("-Wl,-z,stack-size=1048576 -Wl,--stack-first" LD_FLAGS) | ||
|
|
||
| if("${TARGET_SYSTEM}" MATCHES "Emscripten") | ||
| append("-sALLOW_MEMORY_GROWTH" LD_FLAGS) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to enable this by default in If not maybe this block should be moved outside of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I'm not sure how likely this is going to be needed for user apps as well. IIRC, Emscripten defaults to something like 20 MB, which does sound really low for D with GC.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know how wasmtime/wasi-libc handles this? All dynamic by default?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe so. |
||
| endif() | ||
|
|
||
| list(APPEND D_FLAGS --wasm-enable-eh) | ||
| if(LLVM_VERSION_MAJOR GREATER_EQUAL 20) | ||
| list(APPEND D_FLAGS --wasm-use-legacy-eh=false) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is e.g. also still to polish, causing the Alpine CI job failures (no integrated LLD, but external
wasm-ld).This all dates back to the very early wasm support, like the wasm-defaults .conf file - we used to only support bare-metal wasm, so no druntime and Phobos to link, and no need for a C compiler as linker driver, since there wasn't a wasm libc support either. So we used to invoke
wasm-ld(unless we have an integrated LLD) with the ld CLI interface, for all (non-WASI) wasm targets.We can keep this behavior for backwards-compatibility, but then only when targeting an unknown/none OS. We already do that in
55-target-wasm-naked.confnowadays, via the-link-internally(=> use integrated lld withwasm-ldCLI interface) - but only if LLD integration was enabled at build-time.So the compiler special case here would only be needed without LLD integration. Not sure that's worth the trouble, incl. the
link_WebAssemblylit complication (looking for an externalwasm-ld), which I haven't gotten rid of yet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, using most modern system
clangas link driver for bare-metal Wasm should be fine?wasm-ldis a standard part of LLVM distributions nowadays.One notable exception is (at least) macOS 15's clang. So you'll have to have either MacPorts/Homebrew LLVM/Clang available to use as
-gcc, or usewasi-sdk's (oremsdk's).But if we use
-link-internallyby default, then you probably won't notice the difference most of the time.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right - I've just tested this with my system-default clang 18, and it works with an extra
-Xcc=-nostdlib:So yeah, that should be good enough. Noone has requested an
ldCLI interface for other targets either, so...