Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm] Exclude some completely unavailable APIs from build #4915

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/Foundation/DispatchData+DataProtocol.swift
Expand Up @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//


#if canImport(Dispatch)
import Dispatch

extension DispatchData : DataProtocol {
Expand Down Expand Up @@ -54,3 +54,4 @@ extension DispatchData : DataProtocol {
return regions
}
}
#endif
4 changes: 4 additions & 0 deletions Sources/Foundation/NSNotification.swift
Expand Up @@ -82,6 +82,8 @@ open class NSNotification: NSObject, NSCopying, NSCoding {
}
}

#if canImport(Dispatch)

private class NSNotificationReceiver : NSObject {
fileprivate var name: Notification.Name?
fileprivate var block: ((Notification) -> Void)?
Expand Down Expand Up @@ -191,3 +193,5 @@ open class NotificationCenter: NSObject {
}

}

#endif // canImport(Dispatch)
3 changes: 3 additions & 0 deletions Sources/Foundation/NotificationQueue.swift
Expand Up @@ -7,6 +7,7 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

#if canImport(Dispatch)
@_implementationOnly import CoreFoundation

extension NotificationQueue {
Expand Down Expand Up @@ -176,3 +177,5 @@ open class NotificationQueue: NSObject {
}

}

#endif
2 changes: 2 additions & 0 deletions Sources/Foundation/Operation.swift
Expand Up @@ -7,6 +7,7 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

#if canImport(Dispatch)
import Dispatch

internal let _NSOperationIsFinished = "isFinished"
Expand Down Expand Up @@ -1438,3 +1439,4 @@ extension OperationQueue {
}
}
}
#endif
9 changes: 9 additions & 0 deletions Sources/Foundation/Port.swift
Expand Up @@ -83,6 +83,13 @@ public protocol PortDelegate: AnyObject {
func handle(_ message: PortMessage)
}

#if os(WASI)

@available(*, unavailable, message: "SocketPort is not available on this platform.")
open class SocketPort: Port {}

#else

#if canImport(Glibc) && !os(Android) && !os(OpenBSD)
import Glibc
fileprivate let SOCK_STREAM = Int32(Glibc.SOCK_STREAM.rawValue)
Expand Down Expand Up @@ -1106,3 +1113,5 @@ fileprivate extension Data {
return self[...self.index(self.startIndex, offsetBy: range.upperBound)]
}
}

#endif
3 changes: 3 additions & 0 deletions Sources/Foundation/Process.swift
Expand Up @@ -7,6 +7,7 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

#if canImport(Dispatch)
@_implementationOnly import CoreFoundation
#if os(Windows)
import WinSDK
Expand Down Expand Up @@ -1174,3 +1175,5 @@ extension Process {

public static let didTerminateNotification = NSNotification.Name(rawValue: "NSTaskDidTerminateNotification")
}

#endif
2 changes: 2 additions & 0 deletions Sources/Foundation/Progress.swift
Expand Up @@ -7,6 +7,7 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

#if canImport(Dispatch)
import Dispatch

/**
Expand Down Expand Up @@ -545,3 +546,4 @@ fileprivate class _ProgressTSD : NSObject {
childAttached = false
}
}
#endif
20 changes: 20 additions & 0 deletions Sources/Foundation/RunLoop.swift
Expand Up @@ -51,6 +51,24 @@ extension RunLoop.Mode {
}
}

#if !canImport(Dispatch)

open class RunLoop: NSObject {
@available(*, unavailable, message: "RunLoop is not available on WASI")
open class var current: RunLoop {
fatalError("RunLoop is not available on WASI")
}

@available(*, unavailable, message: "RunLoop is not available on WASI")
open class var main: RunLoop {
fatalError("RunLoop is not available on WASI")
}

internal final var currentCFRunLoop: CFRunLoop { NSUnsupported() }
}

#else

internal func _NSRunLoopNew(_ cf: CFRunLoop) -> Unmanaged<AnyObject> {
let rl = Unmanaged<RunLoop>.passRetained(RunLoop(cfObject: cf))
return unsafeBitCast(rl, to: Unmanaged<AnyObject>.self) // this retain is balanced on the other side of the CF fence
Expand Down Expand Up @@ -421,3 +439,5 @@ extension RunLoop._Source {
unsafeBitCast(_cfSourceStorage, to: CFRunLoopSource.self)
}
}

#endif // canImport(Dispatch)
2 changes: 2 additions & 0 deletions Sources/Foundation/Thread.swift
Expand Up @@ -7,6 +7,7 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

#if canImport(Dispatch)
@_implementationOnly import CoreFoundation
#if os(Windows)
import WinSDK
Expand Down Expand Up @@ -448,3 +449,4 @@ extension NSNotification.Name {
public static let NSDidBecomeSingleThreaded = NSNotification.Name(rawValue: "NSDidBecomeSingleThreadedNotification")
public static let NSThreadWillExit = NSNotification.Name(rawValue: "NSThreadWillExitNotification")
}
#endif
4 changes: 4 additions & 0 deletions Sources/Foundation/UserDefaults.swift
Expand Up @@ -406,7 +406,9 @@ open class UserDefaults: NSObject {

_ = defaults.synchronize()

#if canImport(Dispatch)
NotificationCenter.default.post(name: UserDefaults.didChangeNotification, object: self)
#endif
}
}

Expand All @@ -418,7 +420,9 @@ open class UserDefaults: NSObject {

_ = defaults.synchronize()

#if canImport(Dispatch)
NotificationCenter.default.post(name: UserDefaults.didChangeNotification, object: self)
#endif
}
}

Expand Down