diff --git a/CMakeLists.txt b/CMakeLists.txt index 62b22af84d..cf84098e19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) +option(BUILD_SHARED_LIBS "build shared libraries" ON) + # Optionally build tools (on by default) but only when building shared libraries if(BUILD_SHARED_LIBS) option(FOUNDATION_BUILD_TOOLS "build tools" ON) @@ -106,13 +108,24 @@ list(APPEND _Foundation_common_build_flags "-Wno-unused-function" "-Wno-microsoft-enum-forward-reference" "-Wno-int-conversion" - "-fconstant-cfstrings" - "-fexceptions" # TODO: not on OpenBSD - "-fdollars-in-identifiers" - "-fno-common" "-fcf-runtime-abi=swift" "-fblocks") +if(NOT "${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") + list(APPEND _Foundation_common_build_flags + "-fconstant-cfstrings" + "-fdollars-in-identifiers" + "-fno-common") + + if(NOT CMAKE_SYSTEM_NAME STREQUAL OpenBSD) + list(APPEND _Foundation_common_build_flags + "-fexceptions") + endif() +else() + list(APPEND _Foundation_common_build_flags + "/EHsc") +endif() + if(CMAKE_BUILD_TYPE STREQUAL Debug) list(APPEND _Foundation_common_build_flags "-DDEBUG") diff --git a/Sources/CoreFoundation/include/CFRunLoop.h b/Sources/CoreFoundation/include/CFRunLoop.h index e3cf929e8b..86447f20c4 100644 --- a/Sources/CoreFoundation/include/CFRunLoop.h +++ b/Sources/CoreFoundation/include/CFRunLoop.h @@ -16,6 +16,8 @@ #include "CFString.h" #if TARGET_OS_OSX || TARGET_OS_IPHONE #include +#elif TARGET_OS_WIN32 +#include #endif CF_IMPLICIT_BRIDGING_ENABLED diff --git a/Sources/CoreFoundation/include/CFString.h b/Sources/CoreFoundation/include/CFString.h index 03b56abb64..56fc02b694 100644 --- a/Sources/CoreFoundation/include/CFString.h +++ b/Sources/CoreFoundation/include/CFString.h @@ -160,7 +160,7 @@ since it is the default choice with Mac OS X developer tools. CF_EXPORT void *_CF_CONSTANT_STRING_SWIFT_CLASS[]; #endif -#if DEPLOYMENT_RUNTIME_SWIFT && TARGET_OS_MAC +#if DEPLOYMENT_RUNTIME_SWIFT struct __CFConstStr { struct { diff --git a/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h b/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h index f60cb44f4a..2a847e6c1f 100644 --- a/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h +++ b/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h @@ -517,7 +517,11 @@ static inline bool _withStackOrHeapBuffer(size_t amount, void (__attribute__((no buffer.capacity = amount; #endif buffer.onStack = (_CFIsMainThread() != 0 ? buffer.capacity < 2048 : buffer.capacity < 512); +#if TARGET_OS_WIN32 + buffer.memory = buffer.onStack ? _alloca(buffer.capacity) : malloc(buffer.capacity); +#else buffer.memory = buffer.onStack ? alloca(buffer.capacity) : malloc(buffer.capacity); +#endif if (buffer.memory == NULL) { return false; } applier(&buffer); if (!buffer.onStack) { @@ -540,6 +544,7 @@ CF_CROSS_PLATFORM_EXPORT CFIndex __CFCharDigitValue(UniChar ch); #pragma mark - File Functions #if TARGET_OS_WIN32 +typedef int mode_t; CF_CROSS_PLATFORM_EXPORT int _CFOpenFileWithMode(const unsigned short *path, int opts, mode_t mode); #else CF_CROSS_PLATFORM_EXPORT int _CFOpenFileWithMode(const char *path, int opts, mode_t mode); diff --git a/Sources/CoreFoundation/include/module.modulemap b/Sources/CoreFoundation/include/module.modulemap index fab2d38e13..b8cddc7779 100644 --- a/Sources/CoreFoundation/include/module.modulemap +++ b/Sources/CoreFoundation/include/module.modulemap @@ -1,6 +1,5 @@ module CoreFoundation { umbrella header "CoreFoundation.h" - explicit module CFPlugInCOM { header "CFPlugInCOM.h" } export * module * { diff --git a/Sources/CoreFoundation/internalInclude/CFInternal.h b/Sources/CoreFoundation/internalInclude/CFInternal.h index 5b9f109060..79dc4e6001 100644 --- a/Sources/CoreFoundation/internalInclude/CFInternal.h +++ b/Sources/CoreFoundation/internalInclude/CFInternal.h @@ -485,7 +485,7 @@ CF_PRIVATE Boolean __CFProcessIsRestricted(void); CF_EXPORT void * __CFConstantStringClassReferencePtr; -#if DEPLOYMENT_RUNTIME_SWIFT && TARGET_OS_MAC +#if DEPLOYMENT_RUNTIME_SWIFT #if TARGET_OS_LINUX #define CONST_STRING_SECTION __attribute__((section(".cfstr.data"))) diff --git a/Sources/Foundation/FileManager+Win32.swift b/Sources/Foundation/FileManager+Win32.swift index 1e8379600c..2bf47e7370 100644 --- a/Sources/Foundation/FileManager+Win32.swift +++ b/Sources/Foundation/FileManager+Win32.swift @@ -162,7 +162,7 @@ extension FileManager { internal func _recursiveDestinationOfSymbolicLink(atPath path: String) throws -> String { // Throw error if path is not a symbolic link: - var previousIterationDestination = try _destinationOfSymbolicLink(atPath: path) + var previousIterationDestination = try destinationOfSymbolicLink(atPath: path) // Same recursion limit as in Darwin: let symbolicLinkRecursionLimit = 32 diff --git a/Sources/Foundation/FileManager.swift b/Sources/Foundation/FileManager.swift index 6f1c7286d2..6e973c35b9 100644 --- a/Sources/Foundation/FileManager.swift +++ b/Sources/Foundation/FileManager.swift @@ -283,8 +283,10 @@ extension FileManager { let hiddenAttrs = isHidden ? attrs | FILE_ATTRIBUTE_HIDDEN : attrs & ~FILE_ATTRIBUTE_HIDDEN - guard SetFileAttributesW(fsRep, hiddenAttrs) else { - throw _NSErrorWithWindowsError(GetLastError(), reading: false, paths: [path]) + try _fileSystemRepresentation(withPath: path) { fsRep in + guard SetFileAttributesW(fsRep, hiddenAttrs) else { + throw _NSErrorWithWindowsError(GetLastError(), reading: false, paths: [path]) + } } #else if isHidden { @@ -308,7 +310,7 @@ extension FileManager { // Setting these attributes is unsupported on these platforms. throw NSError(domain: NSCocoaErrorDomain, code: CocoaError.fileWriteUnknown.rawValue) #else - let stat = try _lstatFile(atPath: path, withFileSystemRepresentation: fsRep) + let stat = try _lstatFile(atPath: path, withFileSystemRepresentation: nil) var flags = stat.st_flags flags |= flagsToSet flags &= ~flagsToUnset diff --git a/Sources/Foundation/NSUUID.swift b/Sources/Foundation/NSUUID.swift index 00acd6890f..4bc4dd98ad 100644 --- a/Sources/Foundation/NSUUID.swift +++ b/Sources/Foundation/NSUUID.swift @@ -90,7 +90,7 @@ open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding { open override func isEqual(_ value: Any?) -> Bool { switch value { - case let other as UUID: + case let other as FoundationEssentials.UUID: return other.uuid.0 == buffer[0] && other.uuid.1 == buffer[1] && other.uuid.2 == buffer[2] && @@ -124,9 +124,9 @@ open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding { } extension NSUUID : _StructTypeBridgeable { - public typealias _StructType = UUID + public typealias _StructType = FoundationEssentials.UUID - public func _bridgeToSwift() -> UUID { - return UUID._unconditionallyBridgeFromObjectiveC(self) + public func _bridgeToSwift() -> FoundationEssentials.UUID { + return FoundationEssentials.UUID._unconditionallyBridgeFromObjectiveC(self) } }