Skip to content

Commit e7b56e9

Browse files
zhuoweikateinoigakukun
authored andcommitted
WebAssembly: add more ifdefs for WebAssembly
1 parent b1210ac commit e7b56e9

File tree

7 files changed

+29
-7
lines changed

7 files changed

+29
-7
lines changed

include/swift/SwiftRemoteMirror/Platform.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern "C" {
1818
#endif
1919

2020
#if defined(swiftRemoteMirror_EXPORTS)
21-
# if defined(__ELF__)
21+
# if defined(__ELF__) || defined(__wasm__)
2222
# define SWIFT_REMOTE_MIRROR_LINKAGE __attribute__((__visibility__("protected")))
2323
# elif defined(__MACH__)
2424
# define SWIFT_REMOTE_MIRROR_LINKAGE __attribute__((__visibility__("default")))
@@ -30,7 +30,7 @@ extern "C" {
3030
# endif
3131
# endif
3232
#else
33-
# if defined(__ELF__)
33+
# if defined(__ELF__) || defined(__wasm__)
3434
# define SWIFT_REMOTE_MIRROR_LINKAGE __attribute__((__visibility__("default")))
3535
# elif defined(__MACH__)
3636
# define SWIFT_REMOTE_MIRROR_LINKAGE __attribute__((__visibility__("default")))

stdlib/private/StdlibUnittest/InterceptTraps.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
#include "swift/Runtime/Config.h"
2828

29+
// WebAssembly: no signals on WASI yet
30+
#ifndef __wasi__
31+
2932
static void CrashCatcher(int Sig) {
3033
const char *Msg;
3134
switch (Sig) {
@@ -65,11 +68,16 @@ VectoredCrashHandler(PEXCEPTION_POINTERS ExceptionInfo) {
6568
}
6669
#endif
6770

71+
#endif // __wasi__
72+
6873
SWIFT_CC(swift) SWIFT_RUNTIME_LIBRARY_VISIBILITY extern "C"
6974
void installTrapInterceptor() {
7075
// Disable buffering on stdout so that everything is printed before crashing.
7176
setbuf(stdout, 0);
7277

78+
// WebAssembly: no signals on WASI
79+
#ifndef __wasi__
80+
7381
#if defined(_WIN32)
7482
_set_abort_behavior(0, _WRITE_ABORT_MSG);
7583
#endif
@@ -85,5 +93,6 @@ void installTrapInterceptor() {
8593
signal(SIGBUS, CrashCatcher);
8694
signal(SIGSYS, CrashCatcher);
8795
#endif
88-
}
8996

97+
#endif // __wasi__
98+
}

stdlib/private/StdlibUnittest/RaceTest.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import SwiftPrivateLibcExtras
4141
import SwiftPrivateThreadExtras
4242
#if os(macOS) || os(iOS)
4343
import Darwin
44-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
44+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(Wasm)
4545
import Glibc
4646
#elseif os(Windows)
4747
import MSVCRT
@@ -562,7 +562,12 @@ class _InterruptibleSleep {
562562
return
563563
}
564564

565+
#if os(Wasm)
566+
// WebAssembly/WASI on wasm32 is the only 32-bit platform with Int64 time_t
567+
var timeout = timeval(tv_sec: time_t(duration), tv_usec: 0)
568+
#else
565569
var timeout = timeval(tv_sec: duration, tv_usec: 0)
570+
#endif
566571

567572
var readFDs = _stdlib_fd_set()
568573
var writeFDs = _stdlib_fd_set()

stdlib/private/StdlibUnittest/StdlibCoreExtras.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import SwiftPrivate
1414
import SwiftPrivateLibcExtras
1515
#if os(macOS) || os(iOS)
1616
import Darwin
17-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
17+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(Wasm)
1818
import Glibc
1919
#elseif os(Windows)
2020
import MSVCRT

stdlib/private/StdlibUnittest/StdlibUnittest.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import SwiftPrivateLibcExtras
1818
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1919
import Foundation
2020
import Darwin
21-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
21+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(Wasm)
2222
import Glibc
2323
#elseif os(Windows)
2424
import MSVCRT
@@ -748,6 +748,8 @@ extension ProcessTerminationStatus {
748748
case .signal(let signal):
749749
#if os(Windows)
750750
return CInt(signal) == SIGILL
751+
#elseif os(Wasm)
752+
return false
751753
#else
752754
return CInt(signal) == SIGILL || CInt(signal) == SIGTRAP
753755
#endif
@@ -1746,6 +1748,7 @@ public enum OSVersion : CustomStringConvertible {
17461748
case windowsCygnus
17471749
case windows
17481750
case haiku
1751+
case wasm
17491752

17501753
public var description: String {
17511754
switch self {
@@ -1777,6 +1780,8 @@ public enum OSVersion : CustomStringConvertible {
17771780
return "Windows"
17781781
case .haiku:
17791782
return "Haiku"
1783+
case .wasm:
1784+
return "Wasm"
17801785
}
17811786
}
17821787
}
@@ -1821,6 +1826,8 @@ func _getOSVersion() -> OSVersion {
18211826
return .windows
18221827
#elseif os(Haiku)
18231828
return .haiku
1829+
#elseif os(Wasm)
1830+
return .wasm
18241831
#else
18251832
let productVersion = _getSystemVersionPlistProperty("ProductVersion")!
18261833
let (major, minor, bugFix) = _parseDottedVersionTriple(productVersion)

stdlib/public/Platform/Glibc.swift.gyb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@ public let ${prefix}_TRUE_MIN = ${type}.leastNonzeroMagnitude
7272

7373
#if os(Wasm)
7474
// WebAssembly's error.h uses a macro that Swift can't import.
75+
public let EINTR:Int32 = 27
7576
public let EINVAL:Int32 = 28
7677
#endif

stdlib/tools/swift-reflection-test/swift-reflection-test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <stdio.h>
2828
#include <stdlib.h>
2929
#include <string.h>
30-
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
30+
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__wasi__)
3131
#include <unistd.h>
3232
#elif defined(_WIN32)
3333
#include <io.h>

0 commit comments

Comments
 (0)