Skip to content

Commit 59f0767

Browse files
committed
WIP/Foundation: port to Windows
Unformalised changes to port Foundation to Windows
1 parent b8888e5 commit 59f0767

Some content is hidden

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

44 files changed

+1215
-243
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ExternalProject_Add(CoreFoundation
3838
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
3939
# NOTE(compnerd) ensure that we build it as a DLL as we
4040
# wish to re-export the symbols from Foundation
41-
-DCMAKE_C_FLAGS=-D_USRDLL
41+
-DCMAKE_C_FLAGS=-D_USRDLL -DCURL_STATICLIB
4242
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
4343
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
4444
-DCMAKE_INSTALL_LIBDIR=usr/lib
@@ -110,6 +110,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
110110
set(Foundation_rpath_flags -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN")
111111
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
112112
set(deployment_target -DDEPLOYMENT_TARGET_WINDOWS)
113+
set(CoreFoundation_INTERFACE_LIBRARIES -lWS2_32 -lUser32 -lmsvcrt -ladvapi32 -lshell32 -lrpcrt4 -lsecur32 -lPathcch -lOle32 -lCrypt32 -lwldap32 -lNormaliz)
113114
endif()
114115

115116
add_swift_library(Foundation

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)