Skip to content

Commit 395e867

Browse files
committed
Foundation: homogenise importing C, add MSVCRT
This is preliminary setup for enabling the Windows port. Ensure that we import MSVCRT in all the locations where we are importing the C library. Take the opportunity to homogenise the import for linux/android/cygwin as well.
1 parent 4a25565 commit 395e867

23 files changed

+72
-25
lines changed

Foundation/AffineTransform.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
#if os(macOS) || os(iOS)
1111
import Darwin
12-
#elseif os(Linux) || CYGWIN
12+
#elseif os(Linux) || os(Android) || CYGWIN
1313
import Glibc
14+
#elseif os(Windows)
15+
import MSVCRT
1416
#endif
1517

1618
private let ε: CGFloat = CGFloat(2.22045e-16)

Foundation/Data.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414

1515
#if os(macOS) || os(iOS)
1616
import Darwin
17-
#elseif os(Linux)
17+
#elseif os(Linux) || os(Android) || CYGWIN
1818
import Glibc
19+
#elseif os(Windows)
20+
import MSVCRT
21+
#endif
1922

23+
#if os(Linux)
2024
@inlinable // This is @inlinable as trivially computable.
2125
internal func malloc_good_size(_ size: Int) -> Int {
2226
return size
2327
}
24-
2528
#endif
2629

2730
import CoreFoundation

Foundation/DataProtocol.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
#if os(macOS) || os(iOS)
1414
import Darwin
15-
#elseif os(Linux)
15+
#elseif os(Linux) || os(Android) || CYGWIN
1616
import Glibc
17+
#elseif os(Windows)
18+
import MSVCRT
1719
#endif
1820

1921
//===--- DataProtocol -----------------------------------------------------===//

Foundation/FileHandle.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import CoreFoundation
1111

1212
#if os(macOS) || os(iOS)
1313
import Darwin
14-
#elseif os(Linux) || CYGWIN
14+
#elseif os(Linux) || os(Android) || CYGWIN
1515
import Glibc
16+
#elseif os(Windows)
17+
import MSVCRT
1618
#endif
1719

1820
open class FileHandle : NSObject, NSSecureCoding {

Foundation/FileManager.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10-
#if canImport(Darwin)
10+
#if os(macOS) || os(iOS)
1111
import Darwin
12-
#endif
13-
14-
#if canImport(Glibc)
12+
#elseif os(Linux) || os(Android) || CYGWIN
1513
import Glibc
14+
#elseif os(Windows)
15+
import MSVCRT
1616
#endif
1717

1818
#if os(Android) // struct stat.st_mode is UInt32

Foundation/FoundationErrors.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,10 @@ public var NSCoderValueNotFoundError: Int { return CocoaError
166166

167167
#if os(macOS) || os(iOS)
168168
import Darwin
169-
#elseif os(Linux) || CYGWIN
169+
#elseif os(Linux) || os(Android) || CYGWIN
170170
import Glibc
171+
#elseif os(Windows)
172+
import MSVCRT
171173
#endif
172174

173175
internal func _NSErrorWithErrno(_ posixErrno : Int32, reading : Bool, path : String? = nil, url : URL? = nil, extraUserInfo : [String : Any]? = nil) -> NSError {

Foundation/Host.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
#if os(macOS) || os(iOS)
1212
import Darwin
13-
#elseif os(Linux) || CYGWIN
13+
#elseif os(Linux) || os(Android) || CYGWIN
1414
import Glibc
15+
#elseif os(Windows)
16+
import MSVCRT
1517
#endif
1618

1719
import CoreFoundation

Foundation/JSONSerialization.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import CoreFoundation
1111

1212
#if os(macOS) || os(iOS)
1313
import Darwin
14-
#elseif os(Linux) || CYGWIN
14+
#elseif os(Linux) || os(Android) || CYGWIN
1515
import Glibc
16+
#elseif os(Windows)
17+
import MSVCRT
1618
#endif
1719

1820
extension JSONSerialization {

Foundation/NSConcreteValue.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import CoreFoundation
1111

1212
#if os(macOS) || os(iOS)
1313
import Darwin
14-
#elseif os(Linux) || CYGWIN
14+
#elseif os(Linux) || os(Android) || CYGWIN
1515
import Glibc
16+
#elseif os(Windows)
17+
import MSVCRT
1618
#endif
1719

1820
internal class NSConcreteValue : NSValue {

Foundation/NSData.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import CoreFoundation
1111

1212
#if os(macOS) || os(iOS)
1313
import Darwin
14-
#elseif os(Linux) || CYGWIN
14+
#elseif os(Linux) || os(Android) || CYGWIN
1515
import Glibc
16+
#elseif os(Windows)
17+
import MSVCRT
1618
#endif
1719

1820
#if DEPLOYMENT_ENABLE_LIBDISPATCH

Foundation/NSDate.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import CoreFoundation
1111

1212
#if os(macOS) || os(iOS)
1313
import Darwin
14-
#elseif os(Linux) || CYGWIN
14+
#elseif os(Linux) || os(Android) || CYGWIN
1515
import Glibc
16+
#elseif os(Windows)
17+
import MSVCRT
1618
#endif
1719

1820
public typealias TimeInterval = Double

Foundation/NSGeometry.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
#if os(macOS) || os(iOS)
1111
import Darwin
12-
#elseif os(Linux) || CYGWIN
12+
#elseif os(Linux) || os(Android) || CYGWIN
1313
import Glibc
14+
#elseif os(Windows)
15+
import MSVCRT
1416
#endif
1517

1618
public struct CGPoint {

Foundation/NSLock.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
#if os(macOS) || os(iOS)
1212
import Darwin
13-
#elseif os(Linux) || CYGWIN
13+
#elseif os(Linux) || os(Android) || CYGWIN
1414
import Glibc
15+
#elseif os(Windows)
16+
import MSVCRT
1517
#endif
1618

1719
import CoreFoundation

Foundation/NSPathUtilities.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import CoreFoundation
1111

1212
#if os(macOS) || os(iOS)
1313
import Darwin
14-
#elseif os(Linux) || CYGWIN
14+
#elseif os(Linux) || os(Android) || CYGWIN
1515
import Glibc
16+
#elseif os(Windows)
17+
import MSVCRT
1618
#endif
1719

1820
public func NSTemporaryDirectory() -> String {

Foundation/NSPlatform.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
#if os(macOS) || os(iOS)
1111
import Darwin
12-
#elseif os(Linux)
12+
#elseif os(Linux) || os(Android) || CYGWIN
1313
import Glibc
14+
#elseif os(Windows)
15+
import MSVCRT
1416
#endif
1517

1618
#if os(macOS) || os(iOS)

Foundation/NSSwiftRuntime.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import CoreFoundation
1616
@_exported import Darwin
1717
#elseif os(Linux) || os(Android) || CYGWIN
1818
@_exported import Glibc
19+
#elseif os(Windows)
20+
@_exported import MSVCRT
1921
#endif
2022

2123
@_exported import Dispatch

Foundation/NSURL.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import CoreFoundation
1212

1313
#if os(macOS) || os(iOS)
1414
import Darwin
15-
#elseif os(Linux) || CYGWIN
15+
#elseif os(Linux) || os(Android) || CYGWIN
1616
import Glibc
17+
#elseif os(Windows)
18+
import MSVCRT
1719
#endif
1820

1921
#if os(macOS) || os(iOS)

Foundation/NSUUID.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import CoreFoundation
1212

1313
#if os(macOS) || os(iOS)
1414
import Darwin.uuid
15-
#elseif os(Linux) || CYGWIN
15+
#elseif os(Linux) || os(Android) || CYGWIN
1616
import Glibc
17+
#elseif os(Windows)
18+
import MSVCRT
1719
#endif
1820

1921
open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding {

Foundation/Process.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import CoreFoundation
1414
import Darwin
1515
#elseif os(Linux) || CYGWIN
1616
import Glibc
17+
#elseif os(Windows)
18+
import MSVCRT
1719
#endif
1820

1921
extension Process {

Foundation/ProcessInfo.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
#if os(macOS) || os(iOS)
1212
import Darwin
13-
#elseif os(Linux) || CYGWIN
13+
#elseif os(Linux) || os(Android) || CYGWIN
1414
import Glibc
15+
#elseif os(Windows)
16+
import MSVCRT
1517
#endif
1618

1719
import CoreFoundation

Foundation/Progress.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
#if os(macOS) || os(iOS)
1111
import Darwin
12-
#elseif os(Linux)
12+
#elseif os(Linux) || os(Android) || CYGWIN
1313
import Glibc
14+
#elseif os(Windows)
15+
import MSVCRT
1416
#endif
1517

1618
import Dispatch

Foundation/Thread.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
#if os(macOS) || os(iOS)
1212
import Darwin
13-
#elseif os(Linux) || CYGWIN
13+
#elseif os(Linux) || os(Android) || CYGWIN
1414
import Glibc
15+
#elseif os(Windows)
16+
import MSVCRT
1517
#endif
18+
1619
import CoreFoundation
1720

1821
internal class NSThreadSpecific<T: NSObject> {

Foundation/XMLParser.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515

1616
#if os(macOS) || os(iOS)
1717
import Darwin
18-
#elseif os(Linux) || CYGWIN
18+
#elseif os(Linux) || os(Android) || CYGWIN
1919
import Glibc
20+
#elseif os(Windows)
21+
import MSVCRT
2022
#endif
23+
2124
import CoreFoundation
2225

2326
extension XMLParser {

0 commit comments

Comments
 (0)