Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions .github/actions/5a-wasi/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "WASI: Cross-compile druntime incl. test runners, install libs + .conf, run druntime unittests"
name: "WASI: Cross-compile druntime & phobos incl. test runners, install libs + .conf, run druntime & phobos unittests"
Comment thread
kinke marked this conversation as resolved.
inputs:
os:
required: true
Expand All @@ -7,7 +7,7 @@ inputs:
runs:
using: composite
steps:
- name: Cross-compile druntime incl. test runners & install libs + .conf
- name: Cross-compile druntime & phobos incl. test runners & install libs + .conf
shell: bash
run: |
set -eux
Expand All @@ -34,7 +34,6 @@ runs:
--testrunners \
CMAKE_INSTALL_PREFIX="$PWD/install" \
RT_CONF_TRIPLE_REGEX="$arch-.*-$os" \
PHOBOS2_DIR= \
CMAKE_TOOLCHAIN_FILE="$PWD/wasi-sdk/share/cmake/wasi-sdk${toolchain_suffix}.cmake" \
BUILD_LTO_LIBS=ON

Expand All @@ -48,6 +47,26 @@ runs:
../wasmtime/wasmtime -W exceptions ./druntime-test-runner-debug
../wasmtime/wasmtime -W exceptions ./druntime-test-runner

- name: Run phobos unittests
shell: bash
run: |
set -eux
cd ../ldc-build-runtime.${{ inputs.os }}-${{ inputs.arch }}

mkdir -p testrunner_tmpdir/tmp

export WASMTIME_BACKTRACE_DETAILS=1

for testrunner in ./phobos2-test-runner*; do
../wasmtime/wasmtime -W exceptions \
--dir testrunner_tmpdir::/ \
--dir /usr/share/zoneinfo::/tz \
--env TZDIR=/tz/ \
--env HOME=/tmp \
-S inherit-network \
$testrunner
done

- name: Run `importc_compare`
shell: bash
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,12 @@ jobs:
uses: ./.github/actions/1a-setup-wasi
- name: Build bootstrap LDC
uses: ./.github/actions/2-build-bootstrap
- name: 'WASIp1: Cross-compile druntime incl. test runners & run druntime unittests'
- name: 'WASIp1: Cross-compile druntime & phobos incl. test runners & run druntime & phobos unittests'
uses: ./.github/actions/5a-wasi
with:
os: wasip1
arch: ${{ matrix.arch }}
- name: 'WASIp2: Cross-compile druntime incl. test runners & run druntime unittests'
- name: 'WASIp2: Cross-compile druntime & phobos incl. test runners & run druntime & phobos unittests'
uses: ./.github/actions/5a-wasi
with:
os: wasip2
Expand All @@ -432,13 +432,13 @@ jobs:
cd ../bootstrap-ldc
tar xf ${{ github.workspace }}/artifacts/*-addon-*.tar.xz
# generate hello.d
echo 'void main() { import core.stdc.stdio; printf("Hello world, %d bits\n", size_t.sizeof * 8); }' > hello.d
echo 'void main() { import std.stdio; writefln!"Hello world, %d bits"(size_t.sizeof * 8); }' > hello.d
# put WASI-SDK clang onto PATH
export PATH="$PWD/../wasi-sdk/bin:$PATH"
# build & run hello-world
for os in wasip1 wasip2; do
# test LTO too
for args in "" "-O -flto=full -defaultlib=druntime-ldc-lto"; do
for args in "" "-O -flto=full -defaultlib=druntime-ldc-lto,phobos2-ldc-lto"; do
bin/ldc2 -mtriple=${{ matrix.arch }}-unknown-$os $args hello.d
ls -l hello.wasm
../wasmtime/wasmtime -W exceptions ./hello.wasm
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
- `-foptimize-nothrow` is the default setting when targeting Windows or WebAssembly, to make hitting https://github.com/ldc-developers/ldc/issues/3504 much less likely.
- Support for [LLVM 22](https://releases.llvm.org/22.1.0/docs/ReleaseNotes.html). The prebuilt packages use v22.1.8. (#5097, #5102, #5172)
- Minimum LLVM version raised to 18. (#5094)
- 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)
- 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)
- Windows: `x86_64-windows-msvc`, `i686-windows-msvc`; no SDK required.
- 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.
- 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)
- 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)
- 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)
- 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)
- **dcompute**: Added support for Native device code Embedding (PTX and SPIR-V) into the host executable's `.rodata` section. (#5140)
- WebAssembly:
- 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)
- 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)
- 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)
- 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)
- 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)
- 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)

Expand Down
12 changes: 3 additions & 9 deletions runtime/druntime/src/core/sys/posix/unistd.d
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,9 @@ else

version (CRuntime_WASI)
{
version (WASI_EMULATED_GETPID)
pid_t getpid() @trusted;
else
deprecated("WASI lacks process identifiers; to enable emulation of"~
" the `getpid` function using a placeholder value, which"~
" doesn't reflect the host PID of the program, compile"~
" with --d-version=WASI_EMULATED_GETPID and link with"~
" -lwasi-emulated-getpid")
pid_t getpid() @trusted;
// WASI has no processes, and wasi-libc requires you to jump through hoops
// to link this in. We just let D code use it silently.
extern(D) pid_t getpid()() @trusted => 42;
} else
pid_t getpid() @trusted;

Expand Down
Loading