Skip to content

Commit 72a8dab

Browse files
authored
Merge pull request swiftlang#1828 from compnerd/dependencies
CoreFoundation cleanup for Windows
2 parents 29d6b92 + a497812 commit 72a8dab

File tree

12 files changed

+40
-26
lines changed

12 files changed

+40
-26
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ ExternalProject_Add(CoreFoundation
3434
${CMAKE_COMMAND}
3535
CMAKE_ARGS
3636
-DBUILD_SHARED_LIBS=NO
37-
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
3837
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
38+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
39+
# NOTE(compnerd) ensure that we build it as a DLL as we
40+
# wish to re-export the symbols from Foundation
41+
-DCMAKE_C_FLAGS=-D_USRDLL
3942
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
4043
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
4144
-DCMAKE_INSTALL_LIBDIR=usr/lib

CoreFoundation/Base.subproj/CFBase.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,20 @@
127127
#endif
128128

129129
#if TARGET_OS_WIN32
130-
#if !defined(CF_EXPORT)
131-
#if defined(CF_BUILDING_CF) && defined(__cplusplus)
132-
#define CF_EXPORT extern "C" __declspec(dllexport)
133-
#elif defined(CF_BUILDING_CF) && !defined(__cplusplus)
134-
#define CF_EXPORT extern __declspec(dllexport)
135-
#elif defined(__cplusplus)
136-
#define CF_EXPORT extern "C" __declspec(dllimport)
130+
#if defined(__cplusplus)
131+
#define _CF_EXTERN extern "C"
132+
#else
133+
#define _CF_EXTERN extern
134+
#endif
135+
136+
#if defined(_USRDLL)
137+
#if defined(CoreFoundation_EXPORTS)
138+
#define CF_EXPORT _CF_EXTERN __declspec(dllexport)
137139
#else
138-
#define CF_EXPORT extern __declspec(dllimport)
140+
#define CF_EXPORT _CF_EXTERN __declspec(dllimport)
139141
#endif
142+
#else
143+
#define CF_EXPORT _CF_EXTERN
140144
#endif
141145
#else
142146
#define CF_EXPORT extern

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,13 @@ const char *_CFProcessPath(void) {
126126
}
127127
#endif
128128

129-
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
129+
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_WINDOWS
130130
CF_CROSS_PLATFORM_EXPORT Boolean _CFIsMainThread(void) {
131131
return pthread_main_np() == 1;
132132
}
133+
#endif
133134

135+
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
134136
const char *_CFProcessPath(void) {
135137
if (__CFProcessPath) return __CFProcessPath;
136138
#if DEPLOYMENT_TARGET_MACOSX

CoreFoundation/Base.subproj/CFPriv.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +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);
63-
65+
#endif
6466

6567
#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_LINUX))
6668
CF_EXPORT void _CFRunLoopSetCurrent(CFRunLoopRef rl);
@@ -220,8 +222,10 @@ typedef CF_OPTIONS(CFOptionFlags, CFSearchPathDomainMask) {
220222
kCFAllDomainsMask = 0x0ffff /* all domains: all of the above and more, future items */
221223
};
222224

225+
#if TARGET_OS_MAC || TARGET_OS_EMBEDDED
223226
CF_EXPORT
224227
CFArrayRef CFCopySearchPathForDirectoriesInDomains(CFSearchPathDirectory directory, CFSearchPathDomainMask domainMask, Boolean expandTilde);
228+
#endif
225229

226230

227231
/* Obsolete keys */
@@ -609,7 +613,6 @@ CF_EXPORT CFPropertyListRef _CFBundleCreateFilteredLocalizedInfoPlist(CFBundleRe
609613

610614
CF_EXPORT CFStringRef _CFGetWindowsAppleAppDataDirectory(void);
611615
CF_EXPORT CFArrayRef _CFGetWindowsBinaryDirectories(void);
612-
CF_EXPORT CFStringRef _CFGetWindowsAppleSystemLibraryDirectory(void);
613616

614617
// If your Windows application does not use a CFRunLoop on the main thread (perhaps because it is reserved for handling UI events via Windows API), then call this function to make distributed notifications arrive using a different run loop.
615618
CF_EXPORT void _CFNotificationCenterSetRunLoop(CFNotificationCenterRef nc, CFRunLoopRef rl);

CoreFoundation/Base.subproj/CFRuntime.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,11 +1193,6 @@ void __CFInitialize(void) {
11931193
CFNumberGetTypeID(); // NB: This does other work
11941194

11951195
__CFCharacterSetInitialize();
1196-
1197-
#if DEPLOYMENT_TARGET_WINDOWS
1198-
__CFWindowsNamedPipeInitialize();
1199-
#endif
1200-
12011196
__CFDateInitialize();
12021197

12031198
#if DEPLOYMENT_RUNTIME_SWIFT

CoreFoundation/Base.subproj/CFRuntime_Internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ CF_PRIVATE void __CFCharacterSetInitialize(void);
151151

152152
#if TARGET_OS_WIN32
153153
CF_PRIVATE void __CFTSDWindowsInitialize(void);
154-
CF_PRIVATE void __CFWindowsNamedPipeInitialize(void);
155154
#endif
156155

157156
#if TARGET_OS_MAC || TARGET_OS_IPHONE || TARGET_OS_WIN32

CoreFoundation/Base.subproj/CFSystemDirectories.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ CFSearchPathEnumerationState __CFGetNextSearchPathEnumeration(CFSearchPathEnumer
5252
#endif
5353

5454

55-
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS
55+
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
5656

5757
CFArrayRef CFCopySearchPathForDirectoriesInDomains(CFSearchPathDirectory directory, CFSearchPathDomainMask domainMask, Boolean expandTilde) {
5858
CFMutableArrayRef array;

CoreFoundation/Base.subproj/ForFoundationOnly.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ CF_EXPORT const void *_CFArrayCheckAndGetValueAtIndex(CFArrayRef array, CFIndex
465465
CF_EXPORT void _CFArrayReplaceValues(CFMutableArrayRef array, CFRange range, const void *_Nullable * _Nullable newValues, CFIndex newCount);
466466

467467

468+
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
468469
/* Enumeration
469470
Call CFStartSearchPathEnumeration() once, then call
470471
CFGetNextSearchPathEnumeration() one or more times with the returned state.
@@ -475,6 +476,7 @@ CF_EXPORT void _CFArrayReplaceValues(CFMutableArrayRef array, CFRange range, con
475476
typedef CFIndex CFSearchPathEnumerationState;
476477
CF_EXPORT CFSearchPathEnumerationState __CFStartSearchPathEnumeration(CFSearchPathDirectory dir, CFSearchPathDomainMask domainMask);
477478
CF_EXPORT CFSearchPathEnumerationState __CFGetNextSearchPathEnumeration(CFSearchPathEnumerationState state, UInt8 *path, CFIndex pathSize);
479+
#endif
478480

479481
/* For use by NSNumber and CFNumber.
480482
Hashing algorithm for CFNumber:

CoreFoundation/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,19 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
326326
PRIVATE
327327
-DDEPLOYMENT_TARGET_MACOSX)
328328
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
329+
# NOTE(compnerd) we only support building with the dynamic CRT as using the
330+
# static CRT causes problems for users of the library.
331+
target_compile_definitions(CoreFoundation
332+
PRIVATE
333+
-D_DLL)
329334
target_compile_definitions(CoreFoundation
330335
PRIVATE
331336
-DDEPLOYMENT_TARGET_WINDOWS)
337+
if(BUILD_SHARED_LIBS)
338+
target_compile_definitions(CoreFoundation
339+
PRIVATE
340+
-D_USRDLL)
341+
endif()
332342
endif()
333343
target_compile_definitions(CoreFoundation
334344
PRIVATE

CoreFoundation/Error.subproj/CFError.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ static CFTypeRef _CFErrorPOSIXCallBack(CFErrorRef err, CFStringRef key) CF_RETUR
495495
if (!errStr) return NULL;
496496
if (CFEqual(key, kCFErrorDescriptionKey)) return errStr; // If all we wanted was the non-localized description, we're done
497497

498-
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS
498+
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
499499
// We need a kCFErrorLocalizedFailureReasonKey, so look up a possible localization for the error message
500500
// Look for the bundle in /System/Library/CoreServices/CoreTypes.bundle
501501
CFArrayRef paths = CFCopySearchPathForDirectoriesInDomains(kCFLibraryDirectory, kCFSystemDomainMask, false);

CoreFoundation/Locale.subproj/CFLocaleKeys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ CONST_STRING_DECL(kCFCalendarIdentifierEthiopicAmeteMihret, "ethiopic");
133133
CONST_STRING_DECL(kCFCalendarIdentifierEthiopicAmeteAlem, "ethiopic-amete-alem");
134134

135135
// Aliases for Linux
136-
#if DEPLOYMENT_TARGET_LINUX
136+
#if DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_WINDOWS
137137

138138
CF_EXPORT CFStringRef const kCFBuddhistCalendar __attribute__((alias ("kCFCalendarIdentifierBuddhist")));
139139
CF_EXPORT CFStringRef const kCFChineseCalendar __attribute__((alias ("kCFCalendarIdentifierChinese")));

CoreFoundation/NumberDate.subproj/CFTimeZone.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,14 +679,10 @@ CFTimeZoneRef CFTimeZoneCreateWithWindowsName(CFAllocatorRef allocator, CFString
679679
return retval;
680680
}
681681

682-
extern CFStringRef _CFGetWindowsAppleSystemLibraryDirectory(void);
683682
static void __InitTZStrings(void) {
684683
static CFLock_t __CFTZDirLock = CFLockInit;
685684
__CFLock(&__CFTZDirLock);
686-
if (!__tzZoneInfo) {
687-
CFStringRef winDir = _CFGetWindowsAppleSystemLibraryDirectory();
688-
__tzZoneInfo = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@\\etc\\zoneinfo"), winDir);
689-
}
685+
// TODO(compnerd) figure out how to initialize __tzZoneInfo
690686
if (!__tzDir && __tzZoneInfo) {
691687
int length = CFStringGetLength(__tzZoneInfo) + sizeof("\\zone.tab") + 1;
692688
__tzDir = malloc(length); // If we don't use ascii, we'll need to malloc more space

0 commit comments

Comments
 (0)