diff --git a/Sources/Foundation/Data.swift b/Sources/Foundation/Data.swift index a808240b33..706b857bf2 100644 --- a/Sources/Foundation/Data.swift +++ b/Sources/Foundation/Data.swift @@ -26,6 +26,13 @@ @usableFromInline let memset = WASILibc.memset @usableFromInline let memcpy = WASILibc.memcpy @usableFromInline let memcmp = WASILibc.memcmp +#elseif canImport(CRT) +@usableFromInline let calloc = ucrt.calloc +@usableFromInline let malloc = ucrt.malloc +@usableFromInline let free = ucrt.free +@usableFromInline let memset = ucrt.memset +@usableFromInline let memcpy = ucrt.memcpy +@usableFromInline let memcmp = ucrt.memcmp #endif #if !canImport(Darwin) diff --git a/Sources/Foundation/FileHandle.swift b/Sources/Foundation/FileHandle.swift index e282628602..097b18ca1b 100644 --- a/Sources/Foundation/FileHandle.swift +++ b/Sources/Foundation/FileHandle.swift @@ -25,10 +25,11 @@ fileprivate let _close = Glibc.close(_:) #endif #if canImport(WinSDK) -// We used to get the copy that was re-exported by CoreFoundation +import WinSDK.core +// We used to get the alias that was re-exported by CoreFoundation // but we want to explicitly depend on its types in this file, // so we need to make sure Swift doesn't think it's @_implementationOnly. -import WinSDK +import struct WinSDK.HANDLE #endif extension NSError { diff --git a/Sources/Foundation/FileManager+Win32.swift b/Sources/Foundation/FileManager+Win32.swift index a3a75f6ae4..0629ab7029 100644 --- a/Sources/Foundation/FileManager+Win32.swift +++ b/Sources/Foundation/FileManager+Win32.swift @@ -10,6 +10,9 @@ @_implementationOnly import CoreFoundation #if os(Windows) +import WinSDK.core +import struct WinSDK.FILETIME + internal func joinPath(prefix: String, suffix: String) -> String { var pszPath: PWSTR? @@ -1035,4 +1038,8 @@ extension FileManager.NSPathDirectoryEnumerator { } +// FIXME: This is a workaround for CoreFoundation/WinSDK overload +// of the same constants with different types. We should prevent +// CoreFoundation from re-exporting them. +fileprivate let INVALID_FILE_ATTRIBUTES = DWORD(bitPattern: -1) #endif diff --git a/Sources/Foundation/FileManager.swift b/Sources/Foundation/FileManager.swift index ec0f255817..be3549265d 100644 --- a/Sources/Foundation/FileManager.swift +++ b/Sources/Foundation/FileManager.swift @@ -18,6 +18,7 @@ fileprivate let UF_HIDDEN: Int32 = 1 @_implementationOnly import CoreFoundation #if os(Windows) import CRT +import WinSDK.core #endif #if os(Windows) diff --git a/Sources/Foundation/Host.swift b/Sources/Foundation/Host.swift index d21f9b702a..da2e57afb6 100644 --- a/Sources/Foundation/Host.swift +++ b/Sources/Foundation/Host.swift @@ -9,6 +9,10 @@ @_implementationOnly import CoreFoundation +#if os(Windows) +import WinSDK.core +#endif + #if os(Android) // Android Glibc differs a little with respect to the Linux Glibc. diff --git a/Sources/Foundation/NSError.swift b/Sources/Foundation/NSError.swift index d5a8f67a07..73a4761d76 100644 --- a/Sources/Foundation/NSError.swift +++ b/Sources/Foundation/NSError.swift @@ -16,6 +16,7 @@ import Darwin import Glibc #elseif canImport(CRT) import CRT +import WinSDK #endif @_implementationOnly import CoreFoundation diff --git a/Sources/Foundation/NSPathUtilities.swift b/Sources/Foundation/NSPathUtilities.swift index b4c6a2889e..eb7b112415 100644 --- a/Sources/Foundation/NSPathUtilities.swift +++ b/Sources/Foundation/NSPathUtilities.swift @@ -9,6 +9,11 @@ @_implementationOnly import CoreFoundation +#if os(Windows) +import WinSDK.core +#endif + + #if os(Windows) let validPathSeps: [Character] = ["\\", "/"] #else diff --git a/Sources/Foundation/NSSwiftRuntime.swift b/Sources/Foundation/NSSwiftRuntime.swift index 04958446d7..4879ae62bc 100644 --- a/Sources/Foundation/NSSwiftRuntime.swift +++ b/Sources/Foundation/NSSwiftRuntime.swift @@ -14,7 +14,7 @@ // This mimics the behavior of the swift sdk overlay on Darwin #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) @_exported import Darwin -#elseif os(Linux) || os(Android) || CYGWIN || os(OpenBSD) +#elseif os(Linux) || os(Android) || os(Cygwin) || os(OpenBSD) @_exported import Glibc #elseif os(WASI) @_exported import WASILibc diff --git a/Sources/Foundation/NSURL.swift b/Sources/Foundation/NSURL.swift index 38c260d17d..c73864dfc9 100644 --- a/Sources/Foundation/NSURL.swift +++ b/Sources/Foundation/NSURL.swift @@ -17,6 +17,8 @@ internal let kCFURLWindowsPathStyle = CFURLPathStyle.cfurlWindowsPathStyle import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(CRT) +import CRT #endif // NOTE: this represents PLATFORM_PATH_STYLE diff --git a/Sources/Foundation/Process.swift b/Sources/Foundation/Process.swift index 8d4834320e..7ad81ce3fb 100644 --- a/Sources/Foundation/Process.swift +++ b/Sources/Foundation/Process.swift @@ -11,13 +11,15 @@ #if canImport(Darwin) import Darwin +#elseif canImport(WinSDK) +import WinSDK #endif #if canImport(WinSDK) -// We used to get the copy that was re-exported by CoreFoundation +// We used to get the alias that was re-exported by CoreFoundation // but we want to explicitly depend on its types in this file, // so we need to make sure Swift doesn't think it's @_implementationOnly. -import WinSDK +import struct WinSDK.HANDLE #endif extension Process { @@ -1162,6 +1164,13 @@ open class Process: NSObject { } extension Process { - public static let didTerminateNotification = NSNotification.Name(rawValue: "NSTaskDidTerminateNotification") } + +#if os(Windows) +// FIXME: This is a workaround for CoreFoundation/WinSDK overload +// of the same constants with different types. We should prevent +// CoreFoundation from re-exporting them. +fileprivate let HANDLE_FLAG_INHERIT = DWORD(0x00000001) +fileprivate let STARTF_USESTDHANDLES = DWORD(0x00000100) +#endif diff --git a/Sources/Foundation/ProcessInfo.swift b/Sources/Foundation/ProcessInfo.swift index 92ad64ef19..d34dfbd244 100644 --- a/Sources/Foundation/ProcessInfo.swift +++ b/Sources/Foundation/ProcessInfo.swift @@ -9,6 +9,10 @@ @_implementationOnly import CoreFoundation +#if os(Windows) +import WinSDK +#endif + public struct OperatingSystemVersion { public var majorVersion: Int public var minorVersion: Int diff --git a/Sources/Foundation/Thread.swift b/Sources/Foundation/Thread.swift index 7fc74fb160..8ad287cfd7 100644 --- a/Sources/Foundation/Thread.swift +++ b/Sources/Foundation/Thread.swift @@ -11,6 +11,8 @@ #if canImport(Glibc) import Glibc +#elseif canImport(WinSDK) +import WinSDK.core #endif // WORKAROUND_SR9811