diff --git a/Sources/Foundation/Host.swift b/Sources/Foundation/Host.swift index 5a72373c6d..b5205ebb76 100644 --- a/Sources/Foundation/Host.swift +++ b/Sources/Foundation/Host.swift @@ -91,6 +91,8 @@ open class Host: NSObject { return "localhost" } return String(cString: hostname) +#elseif os(WASI) // WASI does not have uname + return "localhost" #else let hname = UnsafeMutablePointer.allocate(capacity: Int(NI_MAXHOST)) defer { @@ -170,6 +172,9 @@ open class Host: NSObject { } _names = [info] _resolved = true +#elseif os(WASI) // WASI does not have getifaddrs + _names = [info] + _resolved = true #else var ifaddr: UnsafeMutablePointer? = nil if getifaddrs(&ifaddr) != 0 { @@ -267,6 +272,11 @@ open class Host: NSObject { _resolved = true } +#elseif os(WASI) // WASI does not have getaddrinfo + if let info = _info { + _names = [info] + _resolved = true + } #else if let info = _info { var flags: Int32 = 0 diff --git a/Sources/Foundation/NSCharacterSet.swift b/Sources/Foundation/NSCharacterSet.swift index 0148771bbe..b1491b340f 100644 --- a/Sources/Foundation/NSCharacterSet.swift +++ b/Sources/Foundation/NSCharacterSet.swift @@ -184,7 +184,6 @@ open class NSCharacterSet : NSObject, NSCopying, NSMutableCopying, NSSecureCodin _CFCharacterSetInitWithBitmapRepresentation(_cfMutableObject, data._cfObject) } -#if !os(WASI) public convenience init?(contentsOfFile fName: String) { do { let data = try Data(contentsOf: URL(fileURLWithPath: fName)) @@ -330,7 +329,6 @@ open class NSCharacterSet : NSObject, NSCopying, NSMutableCopying, NSSecureCodin aCoder.encode(true, forKey: .characterSetIsInvertedKey) } } -#endif open func characterIsMember(_ aCharacter: unichar) -> Bool { return longCharacterIsMember(UInt32(aCharacter)) diff --git a/Sources/Foundation/NSKeyedArchiver.swift b/Sources/Foundation/NSKeyedArchiver.swift index 8433b13869..c09c682222 100644 --- a/Sources/Foundation/NSKeyedArchiver.swift +++ b/Sources/Foundation/NSKeyedArchiver.swift @@ -150,10 +150,6 @@ open class NSKeyedArchiver : NSCoder { /// - Returns: `true` if the operation was successful, otherwise `false`. @available(swift, deprecated: 9999, renamed: "archivedData(withRootObject:requiringSecureCoding:)") open class func archiveRootObject(_ rootObject: Any, toFile path: String) -> Bool { -#if os(WASI) - assertionFailure("\(#function) does not support file access on WASI") - return false -#else var fd : Int32 = -1 var auxFilePath : String var finishedEncoding : Bool = false @@ -187,7 +183,6 @@ open class NSKeyedArchiver : NSCoder { finishedEncoding = keyedArchiver._flags.contains(.finishedEncoding) return finishedEncoding -#endif } public convenience init(requiringSecureCoding: Bool) { @@ -228,13 +223,8 @@ open class NSKeyedArchiver : NSCoder { success = true } } else { -#if !os(WASI) let stream = unsafeBitCast(self._stream, to: CFWriteStream.self) success = CFPropertyListWrite(plist, stream, kCFPropertyListXMLFormat_v1_0, 0, nil) > 0 -#else - assertionFailure("\(#function) only supports data streams on WASI") - return false -#endif } return success diff --git a/Sources/Foundation/NSPathUtilities.swift b/Sources/Foundation/NSPathUtilities.swift index 3253845696..91e7ccba44 100644 --- a/Sources/Foundation/NSPathUtilities.swift +++ b/Sources/Foundation/NSPathUtilities.swift @@ -75,11 +75,9 @@ public func NSTemporaryDirectory() -> String { } } #endif -#if !os(WASI) if let tmpdir = ProcessInfo.processInfo.environment["TMPDIR"] { return normalizedPath(with: tmpdir) } -#endif #if os(Android) // Bionic uses /data/local/tmp/ as temporary directory. TMPDIR is rarely // defined. @@ -433,7 +431,6 @@ extension NSString { return paths.map(appendingPathComponent) } -#if !os(WASI) /// - Experiment: This is a draft API currently under consideration for official import into Foundation /// - Note: Since this API is under consideration it may be either removed or revised in the near future public func completePath(into outputName: inout String?, caseSensitive flag: Bool, matchesInto outputArray: inout [String], filterTypes: [String]?) -> Int { @@ -536,7 +533,6 @@ extension NSString { return { $0.lowercased().hasPrefix(prefix) } } } -#endif internal func _longestCommonPrefix(_ strings: [String], caseSensitive: Bool) -> String? { guard !strings.isEmpty else { @@ -584,11 +580,9 @@ extension NSString { return path + "/" } -#if !os(WASI) public var fileSystemRepresentation: UnsafePointer { return FileManager.default.fileSystemRepresentation(withPath: self._swiftObject) } -#endif public func getFileSystemRepresentation(_ cname: UnsafeMutablePointer, maxLength max: Int) -> Bool { #if os(Windows) diff --git a/Sources/Foundation/NSString.swift b/Sources/Foundation/NSString.swift index d81b20b571..d35c0b02ae 100644 --- a/Sources/Foundation/NSString.swift +++ b/Sources/Foundation/NSString.swift @@ -25,11 +25,7 @@ func NSLocalizedString(_ key: String, bundle: Bundle = Bundle.main, value: String = "", comment: String) -> String { -#if os(WASI) - return key -#else return bundle.localizedString(forKey: key, value: value, table: tableName) -#endif } internal let kCFStringEncodingMacRoman = CFStringBuiltInEncodings.macRoman.rawValue diff --git a/Sources/Foundation/ScannerAPI.swift b/Sources/Foundation/ScannerAPI.swift index d3fe75edfa..500b2f1d92 100644 --- a/Sources/Foundation/ScannerAPI.swift +++ b/Sources/Foundation/ScannerAPI.swift @@ -43,7 +43,7 @@ extension Scanner { if let value = scanInt64(representation: representation) { return Int(value) } - #elseif arch(i386) || arch(arm) + #elseif arch(i386) || arch(arm) || arch(wasm32) if let value = scanInt32(representation: representation) { return Int(value) }