Skip to content

Fix Windows when C compiler is ignorant of system module #3151

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions Sources/Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions Sources/Foundation/FileHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions Sources/Foundation/FileManager+Win32.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions Sources/Foundation/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions Sources/Foundation/Host.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions Sources/Foundation/NSError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Darwin
import Glibc
#elseif canImport(CRT)
import CRT
import WinSDK
#endif

@_implementationOnly import CoreFoundation
Expand Down
5 changes: 5 additions & 0 deletions Sources/Foundation/NSPathUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

@_implementationOnly import CoreFoundation

#if os(Windows)
import WinSDK.core
#endif


#if os(Windows)
let validPathSeps: [Character] = ["\\", "/"]
#else
Expand Down
2 changes: 1 addition & 1 deletion Sources/Foundation/NSSwiftRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Sources/Foundation/NSURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions Sources/Foundation/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions Sources/Foundation/ProcessInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

@_implementationOnly import CoreFoundation

#if os(Windows)
import WinSDK
#endif

public struct OperatingSystemVersion {
public var majorVersion: Int
public var minorVersion: Int
Expand Down
2 changes: 2 additions & 0 deletions Sources/Foundation/Thread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#if canImport(Glibc)
import Glibc
#elseif canImport(WinSDK)
import WinSDK.core
#endif

// WORKAROUND_SR9811
Expand Down