Skip to content

Commit b7f0e55

Browse files
authored
Merge branch 'apple:main' into main
2 parents cfed8d0 + ac4445d commit b7f0e55

File tree

78 files changed

+9045
-278
lines changed

Some content is hidden

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

78 files changed

+9045
-278
lines changed

CMakeLists.txt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,16 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
3838
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
3939

4040
option(BUILD_SHARED_LIBS "build shared libraries" ON)
41+
option(HAS_LIBDISPATCH_API "has libdispatch API" ON)
42+
option(BUILD_NETWORKING "build FoundationNetworking module" ON)
43+
option(BUILD_TOOLS "build tools" ON)
4144
option(NS_CURL_ASSUME_FEATURES_MISSING "Assume that optional libcurl features are missing rather than test the library's version, for build debugging" NO)
4245

43-
find_package(dispatch CONFIG REQUIRED)
46+
if(HAS_LIBDISPATCH_API)
47+
find_package(dispatch CONFIG REQUIRED)
48+
endif()
49+
50+
find_package(ICU COMPONENTS uc i18n REQUIRED)
4451

4552
include(SwiftSupport)
4653
include(GNUInstallDirs)
@@ -53,6 +60,12 @@ set(BUILD_SHARED_LIBS NO)
5360
add_subdirectory(CoreFoundation EXCLUDE_FROM_ALL)
5461
set(BUILD_SHARED_LIBS ${SAVED_BUILD_SHARED_LIBS})
5562

63+
# BlocksRuntime is already in libdispatch so it is only needed if libdispatch is
64+
# NOT being used
65+
if(NOT HAS_LIBDISPATCH_API)
66+
add_subdirectory(Sources/BlocksRuntime)
67+
endif()
68+
5669
# Setup include paths for uuid/uuid.h
5770
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/uuid-headers/uuid/uuid.h
5871
COMMAND
@@ -74,9 +87,22 @@ endif()
7487

7588
if(NOT BUILD_SHARED_LIBS)
7689
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS
77-
CoreFoundation CFXMLInterface CFURLSessionInterface)
78-
install(TARGETS CoreFoundation CFXMLInterface CFURLSessionInterface
90+
CoreFoundation CFXMLInterface)
91+
92+
if(NOT HAS_LIBDISPATCH_API)
93+
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS
94+
BlocksRuntime)
95+
endif()
96+
97+
install(TARGETS CoreFoundation CFXMLInterface
7998
DESTINATION lib/swift_static/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>)
99+
100+
if(BUILD_NETWORKING)
101+
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS
102+
CFURLSessionInterface)
103+
install(TARGETS CFURLSessionInterface
104+
DESTINATION lib/swift_static/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>)
105+
endif()
80106
endif()
81107

82108
set(swift_lib_dir "lib/swift")

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Please remember to include platform information with your report. If the bug is
1515

1616
## Pull Requests
1717

18-
Before embarking on a large amount of work to implement missing functionality, please double-check with the community on the [swift-corelibs-dev](https://lists.swift.org/mailman/listinfo/swift-corelibs-dev) mailing list. Someone may already be working in this area, and we want to avoid duplication of work.
18+
Before embarking on a large amount of work to implement missing functionality, please double-check with the community in the [Swift Forums](https://forums.swift.org/). Someone may already be working in this area, and we want to avoid duplication of work.
1919

2020
If your request includes functionality changes, please be sure to test your code on Linux as well as macOS. Differences in the compiler and runtime on each platform means that code that compiles and runs correctly on Darwin (where the Objective-C runtime is present) may not compile at all on Linux.
2121

CoreFoundation/Base.subproj/CFBase.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,11 @@ CFTypeRef CFMakeCollectable(CFTypeRef cf) CF_AUTOMATED_REFCOUNT_UNAVAILABLE;
686686

687687
#if DEPLOYMENT_RUNTIME_SWIFT
688688

689-
#define _CF_SWIFT_RC_PINNED_FLAG (0x1)
689+
#if TARGET_RT_64_BIT
690+
#define _CF_SWIFT_RC_PINNED_FLAG (0x80000004ffffffff)
691+
#else
692+
#define _CF_SWIFT_RC_PINNED_FLAG (0x800004FF)
693+
#endif
690694
#define _CF_CONSTANT_OBJECT_STRONG_RC ((uintptr_t)_CF_SWIFT_RC_PINNED_FLAG)
691695
#endif
692696

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ int _CFArgc(void) { return *_NSGetArgc(); }
5959
#endif
6060

6161

62+
#if !TARGET_OS_WASI
6263
CF_PRIVATE Boolean _CFGetCurrentDirectory(char *path, int maxlen) {
6364
return getcwd(path, maxlen) != NULL;
6465
}
66+
#endif
6567

6668
#if TARGET_OS_WIN32
6769
// Returns the path to the CF DLL, which we can then use to find resources like char sets
@@ -96,8 +98,9 @@ CF_PRIVATE const wchar_t *_CFDLLPath(void) {
9698
}
9799
return cachedPath;
98100
}
99-
#endif
101+
#endif // TARGET_OS_WIN32
100102

103+
#if !TARGET_OS_WASI
101104
static const char *__CFProcessPath = NULL;
102105
static const char *__CFprogname = NULL;
103106

@@ -242,6 +245,7 @@ const char *_CFProcessPath(void) {
242245
return __CFProcessPath;
243246
#endif
244247
}
248+
#endif // TARGET_OS_WASI
245249

246250
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_BSD
247251
CF_CROSS_PLATFORM_EXPORT Boolean _CFIsMainThread(void) {
@@ -255,13 +259,14 @@ CF_CROSS_PLATFORM_EXPORT Boolean _CFIsMainThread(void) {
255259
#include <syscall.h>
256260
#else
257261
#include <sys/syscall.h>
258-
#endif
262+
#endif // __has_include(<syscall.h>)
259263

260264
Boolean _CFIsMainThread(void) {
261265
return syscall(SYS_gettid) == getpid();
262266
}
263-
#endif
267+
#endif // TARGET_OS_LINUX
264268

269+
#if !TARGET_OS_WASI
265270
CF_PRIVATE CFStringRef _CFProcessNameString(void) {
266271
static CFStringRef __CFProcessNameString = NULL;
267272
if (!__CFProcessNameString) {
@@ -274,7 +279,7 @@ CF_PRIVATE CFStringRef _CFProcessNameString(void) {
274279
}
275280
return __CFProcessNameString;
276281
}
277-
282+
#endif // !TARGET_OS_WASI
278283

279284
#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
280285

@@ -369,7 +374,7 @@ static CFURLRef _CFCopyHomeDirURLForUser(const char *username, bool fallBackToHo
369374

370375
#endif
371376

372-
377+
#if !TARGET_OS_WASI
373378
#define CFMaxHostNameLength 256
374379
#define CFMaxHostNameSize (CFMaxHostNameLength+1)
375380

@@ -582,6 +587,7 @@ CF_EXPORT CFURLRef CFCopyHomeDirectoryURLForUser(CFStringRef uName) {
582587

583588
#undef CFMaxHostNameLength
584589
#undef CFMaxHostNameSize
590+
#endif // !TARGET_OS_WASI
585591

586592
#if TARGET_OS_WIN32
587593
CF_INLINE CFIndex strlen_UniChar(const UniChar* p) {
@@ -720,11 +726,17 @@ CF_PRIVATE void __CFTSDWindowsCleanup() {
720726

721727
static _CFThreadSpecificKey __CFTSDIndexKey;
722728

729+
#if TARGET_OS_WASI
730+
static void *__CFThreadSpecificData;
731+
#endif
732+
723733
CF_PRIVATE void __CFTSDInitialize() {
734+
#if !TARGET_OS_WASI
724735
static dispatch_once_t once;
725736
dispatch_once(&once, ^{
726737
(void)pthread_key_create(&__CFTSDIndexKey, __CFTSDFinalize);
727738
});
739+
#endif
728740
}
729741

730742
#endif
@@ -736,6 +748,8 @@ static void __CFTSDSetSpecific(void *arg) {
736748
pthread_setspecific(__CFTSDIndexKey, arg);
737749
#elif TARGET_OS_WIN32
738750
FlsSetValue(__CFTSDIndexKey, arg);
751+
#elif TARGET_OS_WASI
752+
__CFThreadSpecificData = arg;
739753
#endif
740754
}
741755

@@ -746,16 +760,22 @@ static void *__CFTSDGetSpecific() {
746760
return pthread_getspecific(__CFTSDIndexKey);
747761
#elif TARGET_OS_WIN32
748762
return FlsGetValue(__CFTSDIndexKey);
763+
#elif TARGET_OS_WASI
764+
return __CFThreadSpecificData;
749765
#endif
750766
}
751767

752768
_Atomic(bool) __CFMainThreadHasExited = false;
753769

754770
static void __CFTSDFinalize(void *arg) {
771+
#if TARGET_OS_WASI
772+
__CFMainThreadHasExited = true;
773+
#else
755774
if (pthread_main_np() == 1) {
756775
// Important: we need to be sure that the only time we set this flag to true is when we actually can guarentee we ARE the main thread.
757776
__CFMainThreadHasExited = true;
758777
}
778+
#endif
759779

760780
// Set our TSD so we're called again by pthreads. It will call the destructor PTHREAD_DESTRUCTOR_ITERATIONS times as long as a value is set in the thread specific data. We handle each case below.
761781
__CFTSDSetSpecific(arg);
@@ -779,7 +799,7 @@ static void __CFTSDFinalize(void *arg) {
779799
}
780800
}
781801

782-
#if _POSIX_THREADS
802+
#if _POSIX_THREADS && !TARGET_OS_WASI
783803
if (table->destructorCount == PTHREAD_DESTRUCTOR_ITERATIONS - 1) { // On PTHREAD_DESTRUCTOR_ITERATIONS-1 call, destroy our data
784804
free(table);
785805

@@ -1303,9 +1323,9 @@ CF_PRIVATE int _NS_gettimeofday(struct timeval *tv, struct timezone *tz) {
13031323
#endif // TARGET_OS_WIN32
13041324

13051325
#pragma mark -
1306-
#pragma mark Linux OSAtomic
1326+
#pragma mark Linux, BSD, and WASI OSAtomic
13071327

1308-
#if TARGET_OS_LINUX || TARGET_OS_BSD
1328+
#if TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI
13091329

13101330
bool OSAtomicCompareAndSwapPtr(void *oldp, void *newp, void *volatile *dst)
13111331
{
@@ -1364,7 +1384,7 @@ void OSMemoryBarrier() {
13641384
__sync_synchronize();
13651385
}
13661386

1367-
#endif // TARGET_OS_LINUX
1387+
#endif // TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI
13681388

13691389
#pragma mark -
13701390
#pragma mark Dispatch Replacements
@@ -1378,11 +1398,15 @@ typedef struct _CF_sema_s {
13781398
} * _CF_sema_t;
13791399

13801400
CF_INLINE void _CF_sem_signal(_CF_sema_t s) {
1401+
#if !TARGET_OS_WASI
13811402
sem_post(&s->sema);
1403+
#endif
13821404
}
13831405

13841406
CF_INLINE void _CF_sem_wait(_CF_sema_t s) {
1407+
#if !TARGET_OS_WASI
13851408
sem_wait(&s->sema);
1409+
#endif
13861410
}
13871411

13881412
static void _CF_sem_destroy(_CF_sema_t s) {
@@ -1391,6 +1415,7 @@ static void _CF_sem_destroy(_CF_sema_t s) {
13911415

13921416
CF_INLINE _CFThreadSpecificKey _CF_thread_sem_key() {
13931417
static _CFThreadSpecificKey key = 0;
1418+
#if !TARGET_OS_WASI
13941419
static OSSpinLock lock = OS_SPINLOCK_INIT;
13951420
if (key == 0) {
13961421
OSSpinLockLock(&lock);
@@ -1399,9 +1424,11 @@ CF_INLINE _CFThreadSpecificKey _CF_thread_sem_key() {
13991424
}
14001425
OSSpinLockUnlock(&lock);
14011426
}
1427+
#endif
14021428
return key;
14031429
}
14041430

1431+
#if !TARGET_OS_WASI
14051432
CF_INLINE _CF_sema_t _CF_get_thread_semaphore() {
14061433
_CFThreadSpecificKey key = _CF_thread_sem_key();
14071434
_CF_sema_t s = (_CF_sema_t)pthread_getspecific(key);
@@ -1416,6 +1443,7 @@ CF_INLINE _CF_sema_t _CF_get_thread_semaphore() {
14161443
CF_INLINE void _CF_put_thread_semaphore(_CF_sema_t s) {
14171444
pthread_setspecific(_CF_thread_sem_key(), s);
14181445
}
1446+
#endif
14191447

14201448
#define CF_DISPATCH_ONCE_DONE ((_CF_dispatch_once_waiter_t)~0l)
14211449

@@ -1435,6 +1463,12 @@ defined(__arm64__)
14351463
#endif
14361464

14371465
void _CF_dispatch_once(dispatch_once_t *predicate, void (^block)(void)) {
1466+
#if TARGET_OS_WASI
1467+
if (!*predicate) {
1468+
block();
1469+
*predicate = 1;
1470+
}
1471+
#else
14381472
_CF_dispatch_once_waiter_t volatile *vval = (_CF_dispatch_once_waiter_t*)predicate;
14391473
struct _CF_dispatch_once_waiter_s dow = { NULL };
14401474
_CF_dispatch_once_waiter_t tail = &dow, next, tmp;
@@ -1465,6 +1499,7 @@ void _CF_dispatch_once(dispatch_once_t *predicate, void (^block)(void)) {
14651499
}
14661500
_CF_put_thread_semaphore(dow.dow_sema);
14671501
}
1502+
#endif // TARGET_OS_WASI
14681503
}
14691504

14701505
#endif
@@ -1689,7 +1724,7 @@ CF_EXPORT char **_CFEnviron(void) {
16891724
#elif TARGET_OS_WIN32
16901725
return _environ;
16911726
#else
1692-
#if TARGET_OS_BSD
1727+
#if TARGET_OS_BSD || TARGET_OS_WASI
16931728
extern char **environ;
16941729
#endif
16951730
return environ;
@@ -1711,7 +1746,7 @@ int _CFOpenFile(const char *path, int opts) {
17111746
}
17121747

17131748
CF_CROSS_PLATFORM_EXPORT void *_CFReallocf(void *ptr, size_t size) {
1714-
#if TARGET_OS_WIN32 || TARGET_OS_LINUX || defined(__OpenBSD__)
1749+
#if TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI || defined(__OpenBSD__)
17151750
void *mem = realloc(ptr, size);
17161751
if (mem == NULL && ptr != NULL && size != 0) {
17171752
free(ptr);
@@ -2056,7 +2091,7 @@ CF_EXPORT int _CFPosixSpawn(pid_t *_CF_RESTRICT pid, const char *_CF_RESTRICT pa
20562091
return _CFPosixSpawnImpl(pid, path, file_actions, attrp, argv, envp);
20572092
}
20582093

2059-
#elif !TARGET_OS_WIN32
2094+
#elif !TARGET_OS_WIN32 && !TARGET_OS_WASI
20602095

20612096
#include <spawn.h>
20622097

CoreFoundation/Base.subproj/CFPriv.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,17 @@
4646
#include <CoreFoundation/CFMessagePort.h>
4747
#endif
4848

49+
#if !TARGET_OS_WASI
4950
#include <CoreFoundation/CFRunLoop.h>
5051
#include <CoreFoundation/CFSocket.h>
52+
#endif
5153
#include <CoreFoundation/CFBundlePriv.h>
5254

5355
CF_EXTERN_C_BEGIN
5456

5557
CF_EXPORT void _CFRuntimeSetCFMPresent(void *a);
5658

59+
#if !TARGET_OS_WASI
5760
CF_EXPORT const char *_CFProcessPath(void);
5861
CF_EXPORT const char **_CFGetProcessPath(void);
5962
CF_EXPORT const char **_CFGetProgname(void);
@@ -65,6 +68,7 @@ CF_EXPORT void _CFGetUGIDs(uid_t *euid, gid_t *egid);
6568
CF_EXPORT uid_t _CFGetEUID(void);
6669
CF_EXPORT uid_t _CFGetEGID(void);
6770
#endif
71+
#endif
6872

6973
#if (TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_LINUX))
7074
CF_EXPORT void _CFRunLoopSetCurrent(CFRunLoopRef rl);
@@ -161,6 +165,7 @@ CF_EXPORT Boolean _CFStringGetFileSystemRepresentation(CFStringRef string, UInt8
161165
/* If this is publicized, we might need to create a GetBytesPtr type function as well. */
162166
CF_EXPORT CFStringRef _CFStringCreateWithBytesNoCopy(CFAllocatorRef alloc, const UInt8 *bytes, CFIndex numBytes, CFStringEncoding encoding, Boolean externalFormat, CFAllocatorRef contentsDeallocator);
163167

168+
#if !TARGET_OS_WASI
164169
/* These return NULL on MacOS 8 */
165170
// This one leaks the returned string in order to be thread-safe.
166171
// CF cannot help you in this matter if you continue to use this SPI.
@@ -172,6 +177,7 @@ CFStringRef CFCopyUserName(void);
172177

173178
CF_EXPORT
174179
CFURLRef CFCopyHomeDirectoryURLForUser(CFStringRef uName); /* Pass NULL for the current user's home directory */
180+
#endif
175181

176182

177183
/*
@@ -630,8 +636,10 @@ typedef CF_OPTIONS(CFOptionFlags, _CFBundleFilteredPlistOptions) {
630636
_CFBundleFilteredPlistMemoryMapped = 1
631637
} API_AVAILABLE(macos(10.8), ios(6.0), watchos(2.0), tvos(9.0));
632638

639+
#if !TARGET_OS_WASI
633640
CF_EXPORT CFPropertyListRef _CFBundleCreateFilteredInfoPlist(CFBundleRef bundle, CFSetRef keyPaths, _CFBundleFilteredPlistOptions options) API_AVAILABLE(macos(10.8), ios(6.0), watchos(2.0), tvos(9.0));
634641
CF_EXPORT CFPropertyListRef _CFBundleCreateFilteredLocalizedInfoPlist(CFBundleRef bundle, CFSetRef keyPaths, CFStringRef localizationName, _CFBundleFilteredPlistOptions options) API_AVAILABLE(macos(10.8), ios(6.0), watchos(2.0), tvos(9.0));
642+
#endif
635643

636644
#if TARGET_OS_WIN32
637645
#include <CoreFoundation/CFNotificationCenter.h>

0 commit comments

Comments
 (0)