Skip to content

[CMake] Fix Windows Build #4991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions Sources/CoreFoundation/include/CFRunLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "CFString.h"
#if TARGET_OS_OSX || TARGET_OS_IPHONE
#include <mach/port.h>
#elif TARGET_OS_WIN32
#include <Windows.h>
#endif

CF_IMPLICIT_BRIDGING_ENABLED
Expand Down
2 changes: 1 addition & 1 deletion Sources/CoreFoundation/include/CFString.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions Sources/CoreFoundation/include/ForSwiftFoundationOnly.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion Sources/CoreFoundation/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module CoreFoundation {
umbrella header "CoreFoundation.h"
explicit module CFPlugInCOM { header "CFPlugInCOM.h" }

export *
module * {
Expand Down
2 changes: 1 addition & 1 deletion Sources/CoreFoundation/internalInclude/CFInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down
2 changes: 1 addition & 1 deletion Sources/Foundation/FileManager+Win32.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions Sources/Foundation/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Sources/Foundation/NSUUID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] &&
Expand Down Expand Up @@ -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)
}
}