Skip to content

Commit c24abe5

Browse files
committed
WIP/Foundation: port to Windows
Unformalised changes to port Foundation to Windows
1 parent 933549b commit c24abe5

18 files changed

+799
-52
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -297,13 +298,15 @@ add_swift_library(Foundation
297298
-L${CMAKE_CURRENT_BINARY_DIR}
298299
-luuid
299300
${Foundation_rpath_flags}
301+
${CoreFoundation_INTERFACE_LIBRARIES}
300302
SWIFT_FLAGS
301303
-DDEPLOYMENT_RUNTIME_SWIFT
302304
${deployment_enable_libdispatch}
303305
-I;${ICU_INCLUDE_DIR}
304306
${libdispatch_cflags}
305307
${swift_enable_testing}
306308
${swift_optimization_flags}
309+
-Xcc -D_DLL
307310
DEPENDS
308311
CoreFoundation)
309312

CoreFoundation/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ if(CF_DEPLOYMENT_SWIFT)
353353
target_compile_definitions(CoreFoundation
354354
PRIVATE
355355
-DDEPLOYMENT_RUNTIME_SWIFT)
356+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
357+
target_compile_definitions(CoreFoundation
358+
PRIVATE
359+
-D_DLL
360+
-DCURL_STATICLIB)
361+
endif()
356362
else()
357363
target_compile_definitions(CoreFoundation
358364
PRIVATE

Foundation/CGFloat.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,11 +863,13 @@ public func scalbn(_ x: CGFloat, _ n: Int) -> CGFloat {
863863
return CGFloat(scalbn(x.native, n))
864864
}
865865

866+
#if !os(Windows)
866867
@_transparent
867868
public func lgamma(_ x: CGFloat) -> (CGFloat, Int) {
868869
let (value, sign) = lgamma(x.native)
869870
return (CGFloat(value), sign)
870871
}
872+
#endif
871873

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

Foundation/Data.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#if DEPLOYMENT_RUNTIME_SWIFT
1414

15-
#if os(Linux)
15+
#if os(Linux) || os(Windows)
1616
@inlinable // This is @inlinable as trivially computable.
1717
internal func malloc_good_size(_ size: Int) -> Int {
1818
return size
@@ -22,7 +22,11 @@ internal func malloc_good_size(_ size: Int) -> Int {
2222
import CoreFoundation
2323

2424
internal func __NSDataInvokeDeallocatorUnmap(_ mem: UnsafeMutableRawPointer, _ length: Int) {
25+
#if os(Windows)
26+
UnmapViewOfFile(mem)
27+
#else
2528
munmap(mem, length)
29+
#endif
2630
}
2731

2832
internal func __NSDataInvokeDeallocatorFree(_ mem: UnsafeMutableRawPointer, _ length: Int) {

0 commit comments

Comments
 (0)