Skip to content
Open
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
3 changes: 3 additions & 0 deletions dmd/cond.d
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ extern (C++) final class VersionCondition : DVCondition
case "unittest":
case "VisionOS":
case "WASI":
case "WASIp1":
case "WASIp2":
case "WASIp3":
case "WatchOS":
case "WebAssembly":
case "Win32":
Expand Down
17 changes: 17 additions & 0 deletions dmd/mangle/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,23 @@ public:
buf.writestring(fd.ident.toString());
return;
}

version (IN_LLVM)
{
import gen.llvmhelpers : isTargetWasm;
bool isWasm = isTargetWasm();
}
else bool isWasm = false;

if (fd.isCMain() && isWasm)
{
if (fd.parameters)
buf.writestring("__main_argc_argv");
else
buf.writestring("__main_void");
return;
}

visit(cast(Declaration)fd);
}

Expand Down
73 changes: 73 additions & 0 deletions runtime/druntime/src/core/internal/abort.d
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,79 @@ void abort(scope string msg, scope string filename = __FILE__, size_t line = __L
}
}
}
else version (WASIp1) {
import core.sys.wasi.p1 : CIOVec, fdWrite;

static void writeStr(scope const(char)[][] m...) @nogc nothrow @trusted
{
foreach (s; m) {
CIOVec[1] iovecs;
size_t bytesWritten;
iovecs[0].buf = cast(const(ubyte)*)s.ptr;
iovecs[0].bufLen = s.length;
cast(void)fdWrite(2, iovecs[], bytesWritten);
}
}
} 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")
Comment thread
JohanEngelen marked this conversation as resolved.
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
8 changes: 6 additions & 2 deletions runtime/druntime/src/core/internal/gc/impl/conservative/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ module core.internal.gc.impl.conservative.gc;
//debug = VALGRIND; // Valgrind memcheck integration

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

version (Posix)
version = COLLECT_FORK;

Expand Down Expand Up @@ -3339,7 +3341,9 @@ Lmark:
rangesLock.unlock();
rootsLock.unlock();
}
thread_suspendAll();

version (WASI) {} // WASI is single-threaded
else thread_suspendAll();

prepare();

Expand Down
4 changes: 4 additions & 0 deletions runtime/druntime/src/core/memory.d
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ private extern (C) void _initialize() @system
GetSystemInfo(&si);
(cast() pageSize) = cast(size_t) si.dwPageSize;
}
else version (WebAssembly)
{
(cast() pageSize) = cast(size_t) 65536;
}
else
static assert(false, __FUNCTION__ ~ " is not implemented on this platform");
}
Expand Down
7 changes: 7 additions & 0 deletions runtime/druntime/src/core/stdc/assert_.d
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ else version (CRuntime_Musl)
*/
noreturn __assert_fail(const(char)* exp, const(char)* file, uint line, const(char)* func);
}
else version (CRuntime_WASI)
{
/***
* Assert failure function in the WASI C library.
*/
noreturn __assert_fail(const(char)* exp, const(char)* file, uint line, const(char)* func);
}
else version (CRuntime_Newlib)
{
/***
Expand Down
221 changes: 87 additions & 134 deletions runtime/druntime/src/core/stdc/errno.d
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ else version (CRuntime_Musl)
alias errno = __errno_location;
}
}
else version (CRuntime_WASI)
{
extern (C)
{
ref int __errno_location();
alias errno = __errno_location;
}
}
else version (CRuntime_Newlib)
{
extern (C)
Expand Down Expand Up @@ -2320,142 +2328,87 @@ else version (Haiku)
enum B_NO_TRANSLATOR = (B_TRANSLATION_ERROR_BASE + 1);
enum B_ILLEGAL_DATA = (B_TRANSLATION_ERROR_BASE + 2);
}
else version (WASI)
else version (CRuntime_WASI)
{
enum EPERM = 1;
enum ENOENT = 2;
enum ESRCH = 3;
enum EINTR = 4;
enum EIO = 5;
enum ENXIO = 6;
enum E2BIG = 7;
enum ENOEXEC = 8;
enum EBADF = 9;
enum ECHILD = 10;
enum EAGAIN = 11;
enum ENOMEM = 12;
enum EACCES = 13;
enum EFAULT = 14;
enum ENOTBLK = 15;
enum EBUSY = 16;
enum EEXIST = 17;
enum EXDEV = 18;
enum ENODEV = 19;
enum ENOTDIR = 20;
enum EISDIR = 21;
enum EINVAL = 22;
enum ENFILE = 23;
enum EMFILE = 24;
enum ENOTTY = 25;
enum ETXTBSY = 26;
enum EFBIG = 27;
enum ENOSPC = 28;
enum ESPIPE = 29;
enum EROFS = 30;
enum EMLINK = 31;
enum EPIPE = 32;
enum EDOM = 33;
enum ERANGE = 34;
enum EDEADLK = 35;
enum ENAMETOOLONG = 36;
enum ENOLCK = 37;
enum ENOSYS = 38;
enum ENOTEMPTY = 39;
enum ELOOP = 40;
enum E2BIG = 1;
enum EACCES = 2;
enum EADDRINUSE = 3;
enum EADDRNOTAVAIL = 4;
enum EAFNOSUPPORT = 5;
enum EAGAIN = 6;
enum EALREADY = 7;
enum EBADF = 8;
enum EBADMSG = 9;
enum EBUSY = 10;
enum ECANCELED = 11;
enum ECHILD = 12;
enum ECONNABORTED = 13;
enum ECONNREFUSED = 14;
enum ECONNRESET = 15;
enum EDEADLK = 16;
enum EDESTADDRREQ = 17;
enum EDOM = 18;
enum EDQUOT = 19;
enum EEXIST = 20;
enum EFAULT = 21;
enum EFBIG = 22;
enum EHOSTUNREACH = 23;
enum EIDRM = 24;
enum EILSEQ = 25;
enum EINPROGRESS = 26;
enum EINTR = 27;
enum EINVAL = 28;
enum EIO = 29;
enum EISCONN = 30;
enum EISDIR = 31;
enum ELOOP = 32;
enum EMFILE = 33;
enum EMLINK = 34;
enum EMSGSIZE = 35;
enum EMULTIHOP = 36;
enum ENAMETOOLONG = 37;
enum ENETDOWN = 38;
enum ENETRESET = 39;
enum ENETUNREACH = 40;
enum ENFILE = 41;
enum ENOBUFS = 42;
enum ENODEV = 43;
enum ENOENT = 44;
enum ENOEXEC = 45;
enum ENOLCK = 46;
enum ENOLINK = 47;
enum ENOMEM = 48;
enum ENOMSG = 49;
enum ENOPROTOOPT = 50;
enum ENOSPC = 51;
enum ENOSYS = 52;
enum ENOTCONN = 53;
enum ENOTDIR = 54;
enum ENOTEMPTY = 55;
enum ENOTRECOVERABLE = 56;
enum ENOTSOCK = 57;
enum ENOTSUP = 58;
enum ENOTTY = 59;
enum ENXIO = 60;
enum EOVERFLOW = 61;
enum EOWNERDEAD = 62;
enum EPERM = 63;
enum EPIPE = 64;
enum EPROTO = 65;
enum EPROTONOSUPPORT = 66;
enum EPROTOTYPE = 67;
enum ERANGE = 68;
enum EROFS = 69;
enum ESPIPE = 70;
enum ESRCH = 71;
enum ESTALE = 72;
enum ETIMEDOUT = 73;
enum ETXTBSY = 74;
enum EXDEV = 75;
enum ENOTCAPABLE = 76;

enum EOPNOTSUPP = ENOTSUP;
enum EWOULDBLOCK = EAGAIN;
enum ENOMSG = 42;
enum EIDRM = 43;
enum ECHRNG = 44;
enum EL2NSYNC = 45;
enum EL3HLT = 46;
enum EL3RST = 47;
enum ELNRNG = 48;
enum EUNATCH = 49;
enum ENOCSI = 50;
enum EL2HLT = 51;
enum EBADE = 52;
enum EBADR = 53;
enum EXFULL = 54;
enum ENOANO = 55;
enum EBADRQC = 56;
enum EBADSLT = 57;
enum EDEADLOCK = EDEADLK;
enum EBFONT = 59;
enum ENOSTR = 60;
enum ENODATA = 61;
enum ETIME = 62;
enum ENOSR = 63;
enum ENONET = 64;
enum ENOPKG = 65;
enum EREMOTE = 66;
enum ENOLINK = 67;
enum EADV = 68;
enum ESRMNT = 69;
enum ECOMM = 70;
enum EPROTO = 71;
enum EMULTIHOP = 72;
enum EDOTDOT = 73;
enum EBADMSG = 74;
enum EOVERFLOW = 75;
enum ENOTUNIQ = 76;
enum EBADFD = 77;
enum EREMCHG = 78;
enum ELIBACC = 79;
enum ELIBBAD = 80;
enum ELIBSCN = 81;
enum ELIBMAX = 82;
enum ELIBEXEC = 83;
enum EILSEQ = 84;
enum ERESTART = 85;
enum ESTRPIPE = 86;
enum EUSERS = 87;
enum ENOTSOCK = 88;
enum EDESTADDRREQ = 89;
enum EMSGSIZE = 90;
enum EPROTOTYPE = 91;
enum ENOPROTOOPT = 92;
enum EPROTONOSUPPORT = 93;
enum ESOCKTNOSUPPORT = 94;
enum EOPNOTSUPP = 95;
enum ENOTSUP = EOPNOTSUPP;
enum EPFNOSUPPORT = 96;
enum EAFNOSUPPORT = 97;
enum EADDRINUSE = 98;
enum EADDRNOTAVAIL = 99;
enum ENETDOWN = 100;
enum ENETUNREACH = 101;
enum ENETRESET = 102;
enum ECONNABORTED = 103;
enum ECONNRESET = 104;
enum ENOBUFS = 105;
enum EISCONN = 106;
enum ENOTCONN = 107;
enum ESHUTDOWN = 108;
enum ETOOMANYREFS = 109;
enum ETIMEDOUT = 110;
enum ECONNREFUSED = 111;
enum EHOSTDOWN = 112;
enum EHOSTUNREACH = 113;
enum EALREADY = 114;
enum EINPROGRESS = 115;
enum ESTALE = 116;
enum EUCLEAN = 117;
enum ENOTNAM = 118;
enum ENAVAIL = 119;
enum EISNAM = 120;
enum EREMOTEIO = 121;
enum EDQUOT = 122;
enum ENOMEDIUM = 123;
enum EMEDIUMTYPE = 124;
enum ECANCELED = 125;
enum ENOKEY = 126;
enum EKEYEXPIRED = 127;
enum EKEYREVOKED = 128;
enum EKEYREJECTED = 129;
enum EOWNERDEAD = 130;
enum ENOTRECOVERABLE = 131;
enum ERFKILL = 132;
enum EHWPOISON = 133;
}
else
{
Expand Down
Loading
Loading