Skip to content

Commit 4750898

Browse files
authored
Merge branch 'swiftlang:main' into SHGetKnownFolderPath-Continued
2 parents c8aa817 + 265274a commit 4750898

30 files changed

+457
-171
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Create PR to merge release branch into the main branch
2+
# At the end of a release cycle, we may want to automatically include all changes to release branches on the main branch to avoid the need for cherry-picking changes back to release branches
3+
# This workflow can be disabled earlier in the release cycle in the GitHub UI as described in https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/disabling-and-enabling-a-workflow
4+
permissions:
5+
contents: read
6+
on:
7+
schedule:
8+
- cron: '0 9 * * *'
9+
workflow_dispatch:
10+
jobs:
11+
create_merge_pr:
12+
name: Create PR to merge release branch into main branch
13+
uses: swiftlang/github-workflows/.github/workflows/create_automerge_pr.yml@main
14+
with:
15+
base_branch: main
16+
head_branch: release/6.2
17+
permissions:
18+
contents: write
19+
pull-requests: write
20+
if: (github.event_name == 'schedule' && github.repository == 'swiftlang/swift-corelibs-foundation') || (github.event_name != 'schedule') # Ensure that we don't run this on a schedule in a fork
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Create PR to merge main into release branch
2+
# In the first period after branching the release branch, we typically want to include many changes from `main` in the release branch. This workflow automatically creates a PR every Monday to merge main into the release branch.
3+
# Later in the release cycle we should stop this practice to avoid landing risky changes by disabling this workflow. To do so, disable the workflow as described in https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/disabling-and-enabling-a-workflow
4+
permissions:
5+
contents: read
6+
on:
7+
schedule:
8+
- cron: '0 9 * * MON'
9+
workflow_dispatch:
10+
jobs:
11+
create_merge_pr:
12+
name: Create PR to merge main into release branch
13+
uses: swiftlang/github-workflows/.github/workflows/create_automerge_pr.yml@main
14+
with:
15+
base_branch: release/6.2
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
if: (github.event_name == 'schedule' && github.repository == 'swiftlang/swift-corelibs-foundation') || (github.event_name != 'schedule') # Ensure that we don't run this on a schedule in a fork

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ endif()
4040
project(Foundation
4141
LANGUAGES C Swift)
4242

43+
option(FOUNDATION_SWIFTPM_DEPS "build Windows SwiftPM dependencies via CMake" NO)
44+
if(FOUNDATION_SWIFTPM_DEPS)
45+
include(WindowsSwiftPMDependencies)
46+
_foundation_setup_windows_swiftpm_dependencies_target()
47+
return()
48+
endif()
49+
4350
if(NOT SWIFT_SYSTEM_NAME)
4451
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
4552
set(SWIFT_SYSTEM_NAME macosx)
@@ -212,6 +219,12 @@ else()
212219
"/clang:-fcf-runtime-abi=swift")
213220
endif()
214221

222+
set(CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH ON)
223+
set(CMAKE_INSTALL_RPATH "$ORIGIN")
224+
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD|DragonFlyBSD")
225+
add_link_options("LINKER:-z,origin")
226+
endif()
227+
215228
if(CMAKE_BUILD_TYPE STREQUAL Debug)
216229
list(APPEND _Foundation_common_build_flags
217230
"-DDEBUG")

Package.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ if let environmentPath = Context.environment["CURL_INCLUDE_PATH"] {
5858

5959
var curlLinkFlags: [LinkerSetting] = [
6060
.linkedLibrary("libcurl.lib", .when(platforms: [.windows])),
61-
.linkedLibrary("zlibstatic.lib", .when(platforms: [.windows]))
61+
.linkedLibrary("zlibstatic.lib", .when(platforms: [.windows])),
62+
.linkedLibrary("brotlicommon.lib", .when(platforms: [.windows])),
63+
.linkedLibrary("brotlidec.lib", .when(platforms: [.windows]))
6264
]
6365
if let environmentPath = Context.environment["CURL_LIBRARY_PATH"] {
6466
curlLinkFlags.append(.unsafeFlags([
@@ -70,6 +72,11 @@ if let environmentPath = Context.environment["ZLIB_LIBRARY_PATH"] {
7072
"-L\(environmentPath)"
7173
]))
7274
}
75+
if let environmentPath = Context.environment["BROTLI_LIBRARY_PATH"] {
76+
curlLinkFlags.append(.unsafeFlags([
77+
"-L\(environmentPath)"
78+
]))
79+
}
7380

7481
var libxmlLinkFlags: [LinkerSetting] = [
7582
.linkedLibrary("libxml2s.lib", .when(platforms: [.windows]))
@@ -349,7 +356,7 @@ let package = Package(
349356
"FoundationNetworking",
350357
"XCTest",
351358
"Testing",
352-
.target(name: "xdgTestHelper", condition: .when(platforms: [.linux, .android]))
359+
.target(name: "xdgTestHelper", condition: .when(platforms: [.linux, .android, .windows]))
353360
],
354361
resources: [
355362
.copy("Foundation/Resources")

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ swift-corelibs-foundation builds as a standalone project using Swift Package Man
7272

7373
swift-corelibs-foundation also builds as part of the toolchain for non-Darwin platforms. Instructions on building the toolchain are available in the [Swift project](https://github.com/swiftlang/swift?tab=readme-ov-file#building).
7474

75+
### Building swift-corelibs-foundation on Windows
76+
77+
When building Foundation as a standalone project, it requires you to provide some dependencies that it will link during the build. SwiftPM already fetches most of these dependencies and on Linux the remaining dependencies (dispatch, zlib, curl, libxml) are found in the Swift toolchain or on the host OS. However, Windows does not ship with zlib/curl/libxml on the host OS. In order to build swift-corelibs-foundation as a package on Windows, you must first checkout and build these dependenies before running `swift build` as recommended above. To do this, you can build the provided CMake target which (instead of building Foundation via CMake) will checkout and build these 3 dependencies via CMake and provide environment variables that will connect the SwiftPM build to these dependencies. To build these targets, run the following commands:
78+
79+
```
80+
cmake -G Ninja -B <build folder> -DFOUNDATION_SWIFTPM_DEPS=YES
81+
cmake --build <build folder> --target --target WindowsSwiftPMDependencies
82+
```
83+
84+
After running these commands, the output will include a list of environment variables to set. After setting these environment variables, you can run `swift test`/`swift build` just like on Linux in order to build swift-corelibs-foundation with an existing Swift toolchain.
85+
7586
## Contributions
7687

7788
We welcome contributions to Foundation! Please see the [known issues](Docs/Issues.md) page if you are looking for an area where we need help. We are also standing by on the [mailing lists](https://swift.org/community/#communication) to answer questions about what is most important to do and what we will accept into the project.

Sources/CoreFoundation/CFBundle.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,22 +255,26 @@ CF_PRIVATE CFURLRef _CFURLCreateResolvedDirectoryWithString(CFAllocatorRef alloc
255255
#pragma mark -
256256
#pragma mark Bundle Tables
257257

258+
static void __CFBundleCreateAllBundlesArrayLocked() {
259+
CFArrayCallBacks callbacks = kCFTypeArrayCallBacks;
260+
#if TARGET_OS_OSX
261+
if (_useUnsafeUnretainedTables()) {
262+
callbacks.retain = NULL;
263+
callbacks.release = NULL;
264+
}
265+
#endif
266+
// The _allBundles array holds a strong reference on the bundle.
267+
// It does this to prevent a race on bundle deallocation / creation. See: <rdar://problem/6606482> CFBundle isn't thread-safe in RR mode
268+
// Also, the existence of the CFBundleGetBundleWithIdentifier / CFBundleGetAllBundles API means that any bundle we hand out from there must be permanently retained, or callers will potentially have an object that can be deallocated out from underneath them.
269+
_allBundles = CFArrayCreateMutable(kCFAllocatorSystemDefault, 0, &callbacks);
270+
}
271+
258272
static void _CFBundleAddToTablesLocked(CFBundleRef bundle, CFStringRef bundleID) {
259273
if (bundle->_isUnique) return;
260274

261275
// Add to the _allBundles list
262276
if (!_allBundles) {
263-
CFArrayCallBacks callbacks = kCFTypeArrayCallBacks;
264-
#if TARGET_OS_OSX
265-
if (_useUnsafeUnretainedTables()) {
266-
callbacks.retain = NULL;
267-
callbacks.release = NULL;
268-
}
269-
#endif
270-
// The _allBundles array holds a strong reference on the bundle.
271-
// It does this to prevent a race on bundle deallocation / creation. See: <rdar://problem/6606482> CFBundle isn't thread-safe in RR mode
272-
// Also, the existence of the CFBundleGetBundleWithIdentifier / CFBundleGetAllBundles API means that any bundle we hand out from there must be permanently retained, or callers will potentially have an object that can be deallocated out from underneath them.
273-
_allBundles = CFArrayCreateMutable(kCFAllocatorSystemDefault, 0, &callbacks);
277+
__CFBundleCreateAllBundlesArrayLocked();
274278
}
275279
CFArrayAppendValue(_allBundles, bundle);
276280

@@ -1795,6 +1799,11 @@ CF_EXPORT CFArrayRef _CFBundleCopyAllBundles(void) {
17951799
_CFBundleEnsureAllBundlesUpToDate();
17961800
CFBundleRef main = CFBundleGetMainBundle();
17971801
_CFMutexLock(&CFBundleGlobalDataLock);
1802+
// There is a chance that `_allBundles` haven't been initiated
1803+
// if no one called `CFBundleCreate()` yet
1804+
if (!_allBundles) {
1805+
__CFBundleCreateAllBundlesArrayLocked();
1806+
}
17981807
// _allBundles does not include the main bundle, so insert it here.
17991808
CFMutableArrayRef bundles = CFArrayCreateMutableCopy(kCFAllocatorSystemDefault, CFArrayGetCount(_allBundles) + 1, _allBundles);
18001809
_CFMutexUnlock(&CFBundleGlobalDataLock);

Sources/CoreFoundation/CFCalendar.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ enum {
3333

3434
#define ICU_LOG(FMT, ...) do { } while (0)
3535

36-
#define MIN_CALENDAR_TIME -211845067200.0 // Julian day 0 (-4713-01-01 12:00:00 +0000) in CFAbsoluteTime.
37-
#define MAX_CALENDAR_TIME 15927175497600.0 // 50000-01-01 00:00:00 +0000, smaller than the max time ICU supported.
36+
#define MIN_CALENDAR_TIME -211845067200.0 // Julian day 0 (-4712-01-01 12:00:00 +0000) in CFAbsoluteTime.
37+
#define MAX_CALENDAR_TIME 15927175497600.0 // 506713-02-07 00:00:00 +0000, smaller than the max time ICU supported.
3838
#define __CFCalendarValidateAndCapTimeRange(at) do { \
3939
if (at < MIN_CALENDAR_TIME || at > MAX_CALENDAR_TIME) { \
4040
os_log_error(_CFOSLog(), "CFAbsoluteTime %lf exceeds calendar calculation range.", at); \

Sources/CoreFoundation/CFPlatform.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,9 @@ static void __CFTSDFinalize(void *arg) {
961961

962962
// FreeBSD libthr emits debug message to stderr if there are leftover nonnull TSD after PTHREAD_DESTRUCTOR_ITERATIONS
963963
// On this platform, the destructor will never be called again, therefore it is unneccessary to set the TSD to CF_TSD_BAD_PTR
964-
#if !defined(__FreeBSD__)
964+
#if defined(__FreeBSD__)
965+
__CFTSDSetSpecific(NULL);
966+
#else
965967
// Now if the destructor is called again we will take the shortcut at the beginning of this function.
966968
__CFTSDSetSpecific(CF_TSD_BAD_PTR);
967969
#endif
@@ -1948,7 +1950,7 @@ CF_CROSS_PLATFORM_EXPORT void *_CFReallocf(void *ptr, size_t size) {
19481950
#endif
19491951
}
19501952

1951-
#if TARGET_OS_ANDROID
1953+
#if TARGET_OS_ANDROID && __ANDROID_API__ < 28
19521954

19531955
#include <dlfcn.h>
19541956
#include <spawn.h>
@@ -2277,6 +2279,10 @@ CF_EXPORT int _CFPosixSpawnFileActionsAddClose(_CFPosixSpawnFileActionsRef file_
22772279
return _CFPosixSpawnFileActionsAddCloseImpl(file_actions, filedes);
22782280
}
22792281

2282+
CF_EXPORT int _CFPosixSpawnFileActionsChdir(_CFPosixSpawnFileActionsRef file_actions, const char *path) {
2283+
return ENOSYS;
2284+
}
2285+
22802286
CF_EXPORT int _CFPosixSpawn(pid_t *_CF_RESTRICT pid, const char *_CF_RESTRICT path, _CFPosixSpawnFileActionsRef file_actions, _CFPosixSpawnAttrRef _Nullable _CF_RESTRICT attrp, char *_Nullable const argv[_Nullable _CF_RESTRICT], char *_Nullable const envp[_Nullable _CF_RESTRICT]) {
22812287
_CFPosixSpawnInitialize();
22822288
return _CFPosixSpawnImpl(pid, path, file_actions, attrp, argv, envp);
@@ -2317,12 +2323,15 @@ CF_EXPORT int _CFPosixSpawnFileActionsChdir(_CFPosixSpawnFileActionsRef file_act
23172323
// Glibc versions prior to 2.29 don't support posix_spawn_file_actions_addchdir_np, impacting:
23182324
// - Amazon Linux 2 (EoL mid-2025)
23192325
return ENOSYS;
2326+
#elif defined(__ANDROID__) && __ANDROID_API__ < 34
2327+
// Android versions prior to 14 (API level 34) don't support posix_spawn_file_actions_addchdir_np
2328+
return ENOSYS;
23202329
#elif defined(__OpenBSD__) || defined(__QNX__)
23212330
// Currently missing as of:
23222331
// - OpenBSD 7.5 (April 2024)
23232332
// - QNX 8 (December 2023)
23242333
return ENOSYS;
2325-
#elif defined(__GLIBC__) || TARGET_OS_DARWIN || defined(__FreeBSD__) || (defined(__ANDROID__) && __ANDROID_API__ >= 34) || defined(__musl__)
2334+
#elif defined(__GLIBC__) || TARGET_OS_DARWIN || defined(__FreeBSD__) || defined(__ANDROID__) || defined(__musl__)
23262335
// Pre-standard posix_spawn_file_actions_addchdir_np version available in:
23272336
// - Solaris 11.3 (October 2015)
23282337
// - Glibc 2.29 (February 2019)

Sources/CoreFoundation/CFRunLoop.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ extern bool _dispatch_runloop_root_queue_perform_4CF(dispatch_queue_t queue);
7272

7373
#if TARGET_OS_MAC
7474
typedef mach_port_t dispatch_runloop_handle_t;
75-
#elif defined(__linux__) || defined(__FreeBSD__)
75+
#elif TARGET_OS_LINUX
7676
typedef int dispatch_runloop_handle_t;
77+
#elif TARGET_OS_BSD
78+
typedef uint64_t dispatch_runloop_handle_t;
7779
#elif TARGET_OS_WIN32
7880
typedef HANDLE dispatch_runloop_handle_t;
7981
#else
80-
typedef uint64_t dispatch_runloop_handle_t;
82+
#error "runloop support not implemented on this platform"
8183
#endif
8284

8385
#if TARGET_OS_MAC

Sources/CoreFoundation/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ add_library(CoreFoundation STATIC
9999
CFWindowsUtilities.c
100100
CFXMLPreferencesDomain.c
101101
uuid.c)
102-
102+
target_compile_definitions(CoreFoundation PRIVATE
103+
$<$<AND:$<PLATFORM_ID:Windows>,$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>>:CF_WINDOWS_EXECUTABLE_INITIALIZER>)
103104
target_include_directories(CoreFoundation
104105
PUBLIC
105106
include

0 commit comments

Comments
 (0)