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: 25 additions & 0 deletions .github/actions/5a-wasi/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,28 @@ runs:
export WASMTIME_BACKTRACE_DETAILS=1
../wasmtime/wasmtime -W exceptions ./druntime-test-runner-debug
../wasmtime/wasmtime -W exceptions ./druntime-test-runner

- name: Run `importc_compare`
shell: bash
run: |
set -eux
cd ..

os='${{ inputs.os }}'
arch='${{ inputs.arch }}'
triple="$arch-unknown-$os"

# wasm-enable-sjlj only used so `setjmp.h` doesn't error out
bootstrap-ldc/bin/ldc2 \
-defaultlib=druntime-ldc -L-Linstall/lib-$os-$arch \
-gcc=wasi-sdk/bin/$arch-$os-clang \
--mtriple=$triple \
-P=-mllvm -P=-wasm-enable-sjlj \
-P=-D_WASI_EMULATED_SIGNAL --d-version=WASI_EMULATED_SIGNAL \
-P=-D_WASI_EMULATED_PROCESS_CLOCKS --d-version=WASI_EMULATED_PROCESS_CLOCKS \
-P=-D_WASI_EMULATED_MMAN --d-version=WASI_EMULATED_MMAN \
-I$PWD/ldc/runtime/druntime/test/importc_compare/src \
$PWD/ldc/runtime/druntime/test/importc_compare/src/importc_compare.d

export WASMTIME_BACKTRACE_DETAILS=1
wasmtime/wasmtime -W exceptions ./importc_compare.wasm
4 changes: 4 additions & 0 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,22 +935,26 @@ void registerPredefinedTargetVersions() {
case llvm::Triple::WASI:
VersionCondition::addPredefinedGlobalIdent("WASI");
VersionCondition::addPredefinedGlobalIdent("WASIp1");
VersionCondition::addPredefinedGlobalIdent("Posix");
VersionCondition::addPredefinedGlobalIdent("CRuntime_WASI");
break;
#if LLVM_VERSION_MAJOR >= 22
case llvm::Triple::WASIp1:
VersionCondition::addPredefinedGlobalIdent("WASI");
VersionCondition::addPredefinedGlobalIdent("WASIp1");
VersionCondition::addPredefinedGlobalIdent("Posix");
VersionCondition::addPredefinedGlobalIdent("CRuntime_WASI");
break;
case llvm::Triple::WASIp2:
VersionCondition::addPredefinedGlobalIdent("WASI");
VersionCondition::addPredefinedGlobalIdent("WASIp2");
VersionCondition::addPredefinedGlobalIdent("Posix");
VersionCondition::addPredefinedGlobalIdent("CRuntime_WASI");
break;
case llvm::Triple::WASIp3:
VersionCondition::addPredefinedGlobalIdent("WASI");
VersionCondition::addPredefinedGlobalIdent("WASIp3");
VersionCondition::addPredefinedGlobalIdent("Posix");
VersionCondition::addPredefinedGlobalIdent("CRuntime_WASI");
break;
#endif
Expand Down
5 changes: 1 addition & 4 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,11 @@ file(GLOB_RECURSE DRUNTIME_D_OPENBSD ${RUNTIME_DIR}/src/core/sys/openbsd/*.d)
file(GLOB_RECURSE DRUNTIME_D_POSIX ${RUNTIME_DIR}/src/core/sys/posix/*.d)
file(GLOB_RECURSE DRUNTIME_D_SOLARIS ${RUNTIME_DIR}/src/core/sys/solaris/*.d)
file(GLOB_RECURSE DRUNTIME_D_WINDOWS ${RUNTIME_DIR}/src/core/sys/windows/*.d)
file(GLOB_RECURSE DRUNTIME_D_WASI ${RUNTIME_DIR}/src/core/sys/wasi/*.d)
list(REMOVE_ITEM DRUNTIME_D
${DRUNTIME_D_BIONIC} ${DRUNTIME_D_DARWIN} ${DRUNTIME_D_DRAGONFLYBSD}
${DRUNTIME_D_FREEBSD} ${DRUNTIME_D_LINUX} ${DRUNTIME_D_NETBSD}
${DRUNTIME_D_OPENBSD} ${DRUNTIME_D_POSIX} ${DRUNTIME_D_SOLARIS}
${DRUNTIME_D_WINDOWS} ${DRUNTIME_D_WASI}
${DRUNTIME_D_WINDOWS}
)
if("${TARGET_SYSTEM}" MATCHES "Windows")
list(APPEND DRUNTIME_D ${DRUNTIME_D_WINDOWS})
Expand All @@ -235,8 +234,6 @@ elseif("${TARGET_SYSTEM}" MATCHES "UNIX")
elseif("${TARGET_SYSTEM}" MATCHES "SunOS")
list(APPEND DRUNTIME_D ${DRUNTIME_D_SOLARIS})
endif()
elseif("${TARGET_SYSTEM}" MATCHES "WASI")
list(APPEND DRUNTIME_D ${DRUNTIME_D_WASI})
endif()

# druntime C parts
Expand Down
1 change: 1 addition & 0 deletions runtime/druntime/src/core/demangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -3003,6 +3003,7 @@ CXX_DEMANGLER getCXXDemangler() nothrow @trusted
version (OpenBSD) import core.sys.openbsd.dlfcn : RTLD_DEFAULT;
version (Darwin) import core.sys.darwin.dlfcn : RTLD_DEFAULT;
version (Solaris) import core.sys.solaris.dlfcn : RTLD_DEFAULT;
version (CRuntime_WASI) import core.sys.posix.dlfcn : RTLD_DEFAULT;

if (auto found = cast(CXX_DEMANGLER) dlsym(RTLD_DEFAULT, "__cxa_demangle"))
atomicStore(__cxa_demangle, found);
Expand Down
88 changes: 0 additions & 88 deletions runtime/druntime/src/core/internal/abort.d
Original file line number Diff line number Diff line change
Expand Up @@ -41,94 +41,6 @@ void abort(scope string msg, scope string filename = __FILE__, size_t line = __L
}
}
}
else version (WASIp1) {
// currently depends on wasi-libc being linked in to provide these "syscalls"
// TODO: detach this from wasi-libc
alias ushort __wasi_errno_t;
alias int __wasi_fd_t;
alias size_t __wasi_size_t;

extern(C) struct __wasi_ciovec_t {
const(ubyte)* buf;
__wasi_size_t buf_len;
}

pragma(mangle, "__wasi_fd_write")
extern(C) static __wasi_errno_t
__wasi_fd_write(__wasi_fd_t fd,
const __wasi_ciovec_t *iovs,
size_t iovs_len, __wasi_size_t *retptr0) @nogc nothrow;

static void writeStr(scope const(char)[][] m...) @nogc nothrow @trusted
{
foreach (s; m) {
__wasi_ciovec_t iovec;
__wasi_size_t ret;
iovec.buf = cast(const(ubyte)*)s.ptr;
iovec.buf_len = s.length;
cast(void)__wasi_fd_write(2, &iovec, 1, &ret);
}
}
} else version (WASIp2) {
// currently depends on wasi-libc being linked in to provide these "syscalls"
// TODO: detach this from wasi-libc
extern(C) struct wasip2_list_u8_t {
ubyte* ptr;
size_t len;
}
extern(C) struct streams_own_output_stream_t {
int __handle;
}
extern(C) struct streams_borrow_output_stream_t {
int __handle;
}
alias streams_own_output_stream_t stderr_own_output_stream_t;
extern(C) struct io_error_own_error_t {
int __handle;
}
alias io_error_own_error_t streams_own_error_t;

extern(C) struct streams_stream_error_t {
ubyte tag;

union Val {
streams_own_error_t last_operation_failed;
}
Val val;
}

pragma(mangle, "streams_output_stream_drop_own")
extern(C) static void streams_output_stream_drop_own(streams_own_output_stream_t handle) @nogc nothrow;
pragma(mangle, "streams_borrow_output_stream")
extern(C) static streams_borrow_output_stream_t streams_borrow_output_stream(streams_own_output_stream_t handle) @nogc nothrow;
pragma(mangle, "stderr_get_stderr")
extern(C) static stderr_own_output_stream_t stderr_get_stderr() @nogc nothrow;
pragma(mangle, "io_error_error_drop_own")
extern(C) static void io_error_error_drop_own(io_error_own_error_t handle) @nogc nothrow;
pragma(mangle, "streams_stream_error_free")
extern(C) static void streams_stream_error_free(streams_stream_error_t *ptr) @nogc nothrow;
pragma(mangle, "streams_method_output_stream_blocking_write_and_flush")
extern(C) static bool streams_method_output_stream_blocking_write_and_flush(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err) @nogc nothrow;

static void writeStr(scope const(char)[][] m...) @nogc nothrow @trusted
{
auto stderr_own = stderr_get_stderr();
scope(exit) streams_output_stream_drop_own(stderr_own);

auto stderr = streams_borrow_output_stream(stderr_own);

foreach (s; m) {
wasip2_list_u8_t contents;
contents.ptr = cast(ubyte*)s.ptr;
contents.len = s.length;
streams_stream_error_t err;
bool success = streams_method_output_stream_blocking_write_and_flush(stderr, &contents, &err);
if (!success) {
streams_stream_error_free(&err);
}
}
}
}
else
static assert(0, "Unsupported OS");

Expand Down
3 changes: 3 additions & 0 deletions runtime/druntime/src/core/internal/backtrace/dwarf.d
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@

module core.internal.backtrace.dwarf;

version (WASI) {}
else:

version (Posix):

import core.internal.string;
Expand Down
3 changes: 3 additions & 0 deletions runtime/druntime/src/core/internal/elf/io.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module core.internal.elf.io;

version (Posix):

version (WASI) {}
else:

import core.lifetime : move;
import core.memory : pageSize;
import core.stdc.stdlib : free, malloc;
Expand Down
12 changes: 8 additions & 4 deletions runtime/druntime/src/core/internal/gc/impl/conservative/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ module core.internal.gc.impl.conservative.gc;

/***************************************************/
version (WASI) {} // WASI is single-threaded
else version = COLLECT_PARALLEL; // parallel scanning
else
{
version = COLLECT_PARALLEL; // parallel scanning

version (Posix)
version = COLLECT_FORK;
version (Posix)
version = COLLECT_FORK;
}

import core.internal.gc.bits;
import core.internal.gc.os;
Expand Down Expand Up @@ -1787,7 +1790,8 @@ struct Gcx
usedSmallPages = usedLargePages = 0;
mappedPages = 0;
//printf("gcx = %p, self = %x\n", &this, self);
version (Posix)
version(WASI) {}
else version (Posix)
{
import core.sys.posix.pthread : pthread_atfork;
instance = &this;
Expand Down
4 changes: 4 additions & 0 deletions runtime/druntime/src/core/internal/gc/os.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ version (Windows)

//version = GC_Use_Alloc_Win32;
}
else version (WASI)
{
import core.stdc.stdlib : free, malloc;
}
else version (Posix)
{
version (OSX)
Expand Down
3 changes: 2 additions & 1 deletion runtime/druntime/src/core/runtime.d
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,8 @@ void defaultTraceDeallocator(Throwable.TraceInfo info) nothrow
}

/// Default implementation for most POSIX systems
version (Posix) private class DefaultTraceInfo : Throwable.TraceInfo
version (WASI) {}
else version (Posix) private class DefaultTraceInfo : Throwable.TraceInfo
{
import core.demangle;
import core.stdc.stdlib : free;
Expand Down
31 changes: 0 additions & 31 deletions runtime/druntime/src/core/stdc/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -182,37 +182,6 @@ else version (Posix)
alias cpp_ulonglong = ulong;
}
}
else version (WASI)
{
static if ( (void*).sizeof > int.sizeof )
{
enum __c_longlong : long;
enum __c_ulonglong : ulong;

alias c_long = long;
alias c_ulong = ulong;

alias cpp_long = long;
alias cpp_ulong = ulong;

alias cpp_longlong = __c_longlong;
alias cpp_ulonglong = __c_ulonglong;
}
else
{
enum __c_long : int;
enum __c_ulong : uint;

alias c_long = int;
alias c_ulong = uint;

alias cpp_long = __c_long;
alias cpp_ulong = __c_ulong;

alias cpp_longlong = long;
alias cpp_ulonglong = ulong;
}
}

version (GNU)
alias c_long_double = real;
Expand Down
2 changes: 1 addition & 1 deletion runtime/druntime/src/core/stdc/limits.d
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ else version (CRuntime_WASI)
///
enum PATH_MAX = 256;
///
enum PIPE_BUF = 512;
enum PIPE_BUF = 4096;
}
else
static assert(0, "unsupported OS");
32 changes: 17 additions & 15 deletions runtime/druntime/src/core/stdc/signal.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ nothrow:

// this should be volatile
///
version (CRuntime_WASI) {
version (CRuntime_WASI)
{
import core.stdc.config : c_long;
alias c_long sig_atomic_t;
} else {
Expand All @@ -29,14 +30,18 @@ version (CRuntime_WASI) {

private alias sigfn_t = void function(int);

version (Posix)

version (CRuntime_WASI)
{
extern(C) void __SIG_ERR(int);
extern(C) void __SIG_IGN(int);

///
enum SIG_ERR = cast(sigfn_t) -1;
enum SIG_ERR = cast(sigfn_t)&__SIG_ERR;
///
enum SIG_DFL = cast(sigfn_t) 0;
enum SIG_DFL = cast(sigfn_t)0;
///
enum SIG_IGN = cast(sigfn_t) 1;
enum SIG_IGN = cast(sigfn_t)&__SIG_IGN;

// standard C signals
///
Expand All @@ -52,7 +57,7 @@ version (Posix)
///
enum SIGTERM = 15; // Termination
}
else version (Windows)
else version (Posix)
{
///
enum SIG_ERR = cast(sigfn_t) -1;
Expand All @@ -63,7 +68,7 @@ else version (Windows)

// standard C signals
///
enum SIGABRT = 22; // Abnormal termination
enum SIGABRT = 6; // Abnormal termination
///
enum SIGFPE = 8; // Floating-point error
///
Expand All @@ -75,21 +80,18 @@ else version (Windows)
///
enum SIGTERM = 15; // Termination
}
else version (CRuntime_WASI)
else version (Windows)
{
extern(C) void __SIG_ERR(int);
extern(C) void __SIG_IGN(int);

///
enum SIG_ERR = cast(sigfn_t)&__SIG_ERR;
enum SIG_ERR = cast(sigfn_t) -1;
///
enum SIG_DFL = cast(sigfn_t)0;
enum SIG_DFL = cast(sigfn_t) 0;
///
enum SIG_IGN = cast(sigfn_t)&__SIG_IGN;
enum SIG_IGN = cast(sigfn_t) 1;

// standard C signals
///
enum SIGABRT = 6; // Abnormal termination
enum SIGABRT = 22; // Abnormal termination
///
enum SIGFPE = 8; // Floating-point error
///
Expand Down
5 changes: 0 additions & 5 deletions runtime/druntime/src/core/stdc/stddef.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,3 @@ else version (Posix)
///
alias wchar_t = dchar;
}
else version (WASI)
{
///
alias wchar_t = dchar;
}
Loading
Loading