Skip to content

Commit 78a599e

Browse files
committed
WIP/Foundation: port to Windows
Unformalised changes to port Foundation to Windows
1 parent 60651e2 commit 78a599e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1162
-241
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
8484
elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
8585
set(deployment_target -DDEPLOYMENT_TARGET_FREEBSD)
8686
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
87-
set(deployment_target -DDEPLOYMENT_TARGET_WINDOWS)
87+
set(deployment_target -DDEPLOYMENT_TARGET_WINDOWS -D_AMD64_)
8888
endif()
8989

9090
add_swift_library(Foundation

CoreFoundation/Base.subproj/CFPriv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ CF_EXPORT void _CFRuntimeSetCFMPresent(void *a);
5757
CF_EXPORT const char *_CFProcessPath(void);
5858
CF_EXPORT const char **_CFGetProcessPath(void);
5959
CF_EXPORT const char **_CFGetProgname(void);
60+
61+
#if !TARGET_OS_WIN32
6062
CF_EXPORT void _CFGetUGIDs(uid_t *euid, gid_t *egid);
6163
CF_EXPORT uid_t _CFGetEUID(void);
6264
CF_EXPORT uid_t _CFGetEGID(void);
65+
#endif
6366

6467

6568
#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_LINUX))

Foundation/AffineTransform.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import Darwin
1212
#elseif os(Linux) || CYGWIN
1313
import Glibc
14+
#elseif os(Windows)
15+
import MSVCRT
1416
#endif
1517

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

Foundation/ByteCountFormatter.swift

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

10+
#if os(Windows)
11+
import MSVCRT
12+
#endif
1013

1114
extension ByteCountFormatter {
1215
public struct Units : OptionSet {

Foundation/CGFloat.swift

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

10+
#if os(Windows)
11+
import MSVCRT
12+
#endif
13+
1014
@_fixed_layout
1115
public struct CGFloat {
1216
#if arch(i386) || arch(arm)
@@ -863,11 +867,13 @@ public func scalbn(_ x: CGFloat, _ n: Int) -> CGFloat {
863867
return CGFloat(scalbn(x.native, n))
864868
}
865869

870+
#if !os(Windows)
866871
@_transparent
867872
public func lgamma(_ x: CGFloat) -> (CGFloat, Int) {
868873
let (value, sign) = lgamma(x.native)
869874
return (CGFloat(value), sign)
870875
}
876+
#endif
871877

872878
@_transparent
873879
public func remquo(_ x: CGFloat, _ y: CGFloat) -> (CGFloat, Int) {

Foundation/Data.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@
1616
import Darwin
1717
#elseif os(Linux)
1818
import Glibc
19+
#elseif os(Windows)
20+
import MSVCRT
21+
import WinSDK
1922
#endif
2023

2124
import CoreFoundation
2225

2326
internal func __NSDataInvokeDeallocatorUnmap(_ mem: UnsafeMutableRawPointer, _ length: Int) {
27+
#if os(Windows)
28+
UnmapViewOfFile(mem)
29+
#else
2430
munmap(mem, length)
31+
#endif
2532
}
2633

2734
internal func __NSDataInvokeDeallocatorFree(_ mem: UnsafeMutableRawPointer, _ length: Int) {
@@ -187,7 +194,7 @@ public final class _DataStorage {
187194
var buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: range.count, alignment: MemoryLayout<UInt>.alignment)
188195
defer { buffer.deallocate() }
189196

190-
let sliceRange = NSRange(location: range.lowerBound - _offset, length: range.count)
197+
_ = NSRange(location: range.lowerBound - _offset, length: range.count)
191198
var enumerated = 0
192199
d.enumerateBytes { (ptr, byteRange, stop) in
193200
if byteRange.upperBound - _offset < range.lowerBound {

Foundation/DateFormatter.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@ open class DateFormatter : Formatter {
1414
private var __cfObject: CFType?
1515
private var _cfObject: CFType {
1616
guard let obj = __cfObject else {
17-
#if os(macOS) || os(iOS)
18-
let dateStyle = CFDateFormatterStyle(rawValue: CFIndex(self.dateStyle.rawValue))!
19-
let timeStyle = CFDateFormatterStyle(rawValue: CFIndex(self.timeStyle.rawValue))!
20-
#else
21-
let dateStyle = CFDateFormatterStyle(self.dateStyle.rawValue)
22-
let timeStyle = CFDateFormatterStyle(self.timeStyle.rawValue)
23-
#endif
24-
17+
let dateStyle = CFDateFormatterStyle(rawValue: CFIndex(self.dateStyle.rawValue))!
18+
let timeStyle = CFDateFormatterStyle(rawValue: CFIndex(self.timeStyle.rawValue))!
19+
2520
let obj = CFDateFormatterCreate(kCFAllocatorSystemDefault, locale._cfObject, dateStyle, timeStyle)!
2621
_setFormatterAttributes(obj)
2722
if let dateFormat = _dateFormat {

0 commit comments

Comments
 (0)