Skip to content

Commit ee857ca

Browse files
Phobos support for WASI
1 parent 56a1798 commit ee857ca

4 files changed

Lines changed: 31 additions & 11 deletions

File tree

.github/actions/5a-wasi/action.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "WASI: Cross-compile druntime incl. test runners, install libs + .conf, run druntime unittests"
1+
name: "WASI: Cross-compile druntime & phobos incl. test runners, install libs + .conf, run druntime & phobos unittests"
22
inputs:
33
os:
44
required: true
@@ -7,7 +7,7 @@ inputs:
77
runs:
88
using: composite
99
steps:
10-
- name: Cross-compile druntime incl. test runners & install libs + .conf
10+
- name: Cross-compile druntime & phobos incl. test runners & install libs + .conf
1111
shell: bash
1212
run: |
1313
set -eux
@@ -25,16 +25,16 @@ runs:
2525
toolchain_suffix=-`echo "$os" | cut -c 5-`
2626
fi
2727
28+
# -foptimize-nothrow required to work around #3504
2829
bootstrap-ldc/bin/ldc-build-runtime \
2930
--ninja \
30-
--dFlags="-mtriple=$triple" \
31+
--dFlags="-mtriple=$triple;-foptimize-nothrow" \
3132
--ldcSrcDir="$PWD/ldc" \
3233
--buildDir="ldc-build-runtime.$os-$arch" \
3334
--installWithSuffix="-$os-$arch" \
3435
--testrunners \
3536
CMAKE_INSTALL_PREFIX="$PWD/install" \
3637
RT_CONF_TRIPLE_REGEX="$arch-.*-$os" \
37-
PHOBOS2_DIR= \
3838
CMAKE_TOOLCHAIN_FILE="$PWD/wasi-sdk/share/cmake/wasi-sdk${toolchain_suffix}.cmake" \
3939
BUILD_LTO_LIBS=ON
4040
@@ -48,6 +48,26 @@ runs:
4848
../wasmtime/wasmtime -W exceptions ./druntime-test-runner-debug
4949
../wasmtime/wasmtime -W exceptions ./druntime-test-runner
5050
51+
- name: Run phobos unittests
52+
shell: bash
53+
run: |
54+
set -eux
55+
cd ../ldc-build-runtime.${{ inputs.os }}-${{ inputs.arch }}
56+
57+
mkdir -p testrunner_tmpdir/tmp
58+
59+
export WASMTIME_BACKTRACE_DETAILS=1
60+
61+
for testrunner in ./phobos2-test-runner*; do
62+
../wasmtime/wasmtime -W exceptions \
63+
--dir testrunner_tmpdir::/ \
64+
--dir /usr/share/zoneinfo::/tz \
65+
--env TZDIR=/tz/ \
66+
--env HOME=/tmp \
67+
-S inherit-network \
68+
$testrunner
69+
done
70+
5171
- name: Run `importc_compare`
5272
shell: bash
5373
run: |

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,12 @@ jobs:
407407
uses: ./.github/actions/1a-setup-wasi
408408
- name: Build bootstrap LDC
409409
uses: ./.github/actions/2-build-bootstrap
410-
- name: 'WASIp1: Cross-compile druntime incl. test runners & run druntime unittests'
410+
- name: 'WASIp1: Cross-compile druntime & phobos incl. test runners & run druntime & phobos unittests'
411411
uses: ./.github/actions/5a-wasi
412412
with:
413413
os: wasip1
414414
arch: ${{ matrix.arch }}
415-
- name: 'WASIp2: Cross-compile druntime incl. test runners & run druntime unittests'
415+
- name: 'WASIp2: Cross-compile druntime & phobos incl. test runners & run druntime & phobos unittests'
416416
uses: ./.github/actions/5a-wasi
417417
with:
418418
os: wasip2
@@ -432,13 +432,13 @@ jobs:
432432
cd ../bootstrap-ldc
433433
tar xf ${{ github.workspace }}/artifacts/*-addon-*.tar.xz
434434
# generate hello.d
435-
echo 'void main() { import core.stdc.stdio; printf("Hello world, %d bits\n", size_t.sizeof * 8); }' > hello.d
435+
echo 'void main() { import std.stdio; writefln!"Hello world, %d bits"(size_t.sizeof * 8); }' > hello.d
436436
# put WASI-SDK clang onto PATH
437437
export PATH="$PWD/../wasi-sdk/bin:$PATH"
438438
# build & run hello-world
439439
for os in wasip1 wasip2; do
440440
# test LTO too
441-
for args in "" "-O -flto=full -defaultlib=druntime-ldc-lto"; do
441+
for args in "" "-O -flto=full -defaultlib=druntime-ldc-lto,phobos2-ldc-lto"; do
442442
bin/ldc2 -mtriple=${{ matrix.arch }}-unknown-$os $args hello.d
443443
ls -l hello.wasm
444444
../wasmtime/wasmtime -W exceptions ./hello.wasm

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
- New prebuilt **addon packages** (`ldc2-*-addon-<target OS>.tar.xz`) for simple cross-compilation. Simply unpack them directly into your LDC installation directory, and then cross-compile via `-mtriple=…` (or `dub --target=…`): (#5240)
99
- Windows: `x86_64-windows-msvc`, `i686-windows-msvc`; no SDK required.
1010
- Android: `aarch64-linux-android30`, `armv7a-linux-androideabi29`, `x86_64-linux-android29`, `i686-linux-android29`; needs an [Android NDK](https://developer.android.com/ndk/downloads) (r27) and its `toolchains/llvm/prebuilt/*/bin/` dir in your PATH.
11-
- WASI: `wasm32-unknown-wasip1`, `wasm32-unknown-wasip2`; needs a [WASI SDK](https://github.com/webassembly/wasi-sdk) and its `bin/` dir in your PATH. Phobos support is coming, currently druntime only. (#5207)
11+
- WASI: `wasm32-unknown-wasip1`, `wasm32-unknown-wasip2`; needs a [WASI SDK](https://github.com/webassembly/wasi-sdk) and its `bin/` dir in your PATH. (#5207, #5242)
1212
- The `@ldc.attributes.restrict` UDA is now supported for dynamic-array parameters too. Builtin array ops (`c[] = a[] * b[]` etc.) use it, enabling auto-vectorization. Note that for such array ops, the dlang spec prescribes that the slice on the left and any slices on the right must not overlap (https://dlang.org/spec/arrays.html#array-operations), and this knowledge is now used by the optimizer; e.g., `x[] *= x[]` is invalid. (#5148, #5168, #5176)
1313
- DMD-style inline assembly: `asm { naked; }` is now much less of a special case wrt. codegen - such naked functions are now emitted as if `asm { naked; }` was replaced with the `@naked` function UDA. IR-wise, they are not emitted as module-level asm blobs anymore, but regular IR functions. This should lift a few former `asm { naked; }`-specific restrictions and fixed at least one LTO issue. (#5041)
1414
- **dcompute**: Added support for Native device code Embedding (PTX and SPIR-V) into the host executable's `.rodata` section. (#5140)
1515
- WebAssembly:
1616
- The default `-fvisibility` setting was changed to `hidden`, like clang, so that only explicit `export`ed symbols are not hidden. And `-L--export-dynamic` isn't used by default for linking anymore either; add it manually to export all non-hidden symbols, as for normal Posix targets. The net effect is that the size of linked wasm binaries shrinks significantly by default. (#5216)
1717
- Exceptions are now supported. Currently, using D and C++ exceptions are mutually exclusive. If linking in DRuntime, you cannot link in C++ code relying on `libunwind` (exceptions), due to the hacks required to convince LLVM to use D's EH personality. A future LLVM release may help remove the constraint. (#5162)
1818
- In order to allow the GC to function correctly, a new pass is run after optimizations, to spill potential pointers onto the "stack". This pass is enabled by default for all Wasm targets, but can be disabled with `-betterC` or the new `-disable-wasm-ptrs-spill`. (#5178)
19-
- DRuntime now supports [WASI](https://github.com/WebAssembly/WASI) preview levels 1 and 2, based on [`wasi-libc`](https://github.com/WebAssembly/wasi-libc). Two caveats being that WASI is strictly single-threaded (currently), and that fibers are unavailable. (#5186, #5229, #5230)
19+
- DRuntime and Phobos now support [WASI](https://github.com/WebAssembly/WASI) preview levels 1 and 2, based on [`wasi-libc`](https://github.com/WebAssembly/wasi-libc). Two caveats being that WASI is strictly single-threaded (currently), and that fibers are unavailable. (#5186, #5229, #5230, #5242)
2020
- A new `-fno-moduleinfo-localclasses` switch has been added. This disables populating `ModuleInfo.localClasses` for each module. This can help eliminate/strip more dead-code (thus decreasing binary sizes), but breaks `Object.factory` and any other code relying on iterating over said `localClasses`. Enabled by default for Wasm targets. (#5224, #5231)
2121
- Predefined version `LDC_LLVM_*` now only contains the LLVM major version, i.e., former `version (LDC_LLVM_1801)` with LLVM v18.1 is now `version (LDC_LLVM_18)`. Use `ldc.intrinsics.LLVM_version` for backwards compatibility if really needed. (#5109)
2222

0 commit comments

Comments
 (0)