Skip to content

Commit de2f754

Browse files
authored
Merge pull request #5220 from swiftlang/automerge/merge-main-2025-06-02_09-39
Merge `main` into `release/6.2`
2 parents af2ecd8 + cac38ff commit de2f754

File tree

17 files changed

+1880
-411
lines changed

17 files changed

+1880
-411
lines changed

.github/workflows/automerge.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
on:
5+
schedule:
6+
- cron: '0 9 * * MON'
7+
workflow_dispatch:
8+
jobs:
9+
create_merge_pr:
10+
name: Create PR to merge main into release branch
11+
uses: swiftlang/github-workflows/.github/workflows/create_automerge_pr.yml@main
12+
with:
13+
base_branch: release/6.2
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ else()
212212
"/clang:-fcf-runtime-abi=swift")
213213
endif()
214214

215+
set(CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH ON)
216+
set(CMAKE_INSTALL_RPATH "$ORIGIN")
217+
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD|DragonFlyBSD")
218+
add_link_options("LINKER:-z,origin")
219+
endif()
220+
215221
if(CMAKE_BUILD_TYPE STREQUAL Debug)
216222
list(APPEND _Foundation_common_build_flags
217223
"-DDEBUG")

Sources/CoreFoundation/CFPlatform.c

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ static inline void _CFSetProgramNameFromPath(const char *path) {
136136
#include <sys/exec.h>
137137
#endif
138138

139+
#if TARGET_OS_BSD && defined(__FreeBSD__)
140+
#include <sys/sysctl.h>
141+
#endif
142+
139143
const char *_CFProcessPath(void) {
140144
if (__CFProcessPath) return __CFProcessPath;
141145

@@ -230,6 +234,29 @@ const char *_CFProcessPath(void) {
230234
char *res = realpath(ps->ps_argvstr[0], NULL);
231235
argv0 = res? res: strdup(ps->ps_argvstr[0]);
232236
}
237+
#elif defined(__FreeBSD__)
238+
// see sysctl(3), pid == -1 means current process
239+
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
240+
int sysctl_ret = 0;
241+
size_t len = PATH_MAX + 1;
242+
argv0 = calloc(len, 1);
243+
244+
sysctl_ret = sysctl(mib, 4, argv0, &len, NULL, 0);
245+
246+
// in case for whatever reason the path is > PATH_MAX
247+
if (sysctl_ret == -1 && errno == ENOMEM) {
248+
// get size needed
249+
sysctl_ret = sysctl(mib, 4, NULL, &len, NULL, 0);
250+
if (sysctl_ret != -1) {
251+
argv0 = realloc(argv0, len);
252+
sysctl_ret = sysctl(mib, 4, argv0, &len, NULL, 0);
253+
}
254+
}
255+
256+
if (sysctl_ret == -1) {
257+
free(argv0);
258+
argv0 = NULL;
259+
}
233260
#endif
234261

235262
if (!__CFProcessIsRestricted() && argv0 && argv0[0] == '/') {
@@ -908,6 +935,9 @@ static void __CFTSDFinalize(void *arg) {
908935

909936
if (!arg || arg == CF_TSD_BAD_PTR) {
910937
// We've already been destroyed. The call above set the bad pointer again. Now we just return.
938+
#if defined(__FreeBSD__)
939+
__CFTSDSetSpecific(NULL);
940+
#endif
911941
return;
912942
}
913943

@@ -1918,7 +1948,7 @@ CF_CROSS_PLATFORM_EXPORT void *_CFReallocf(void *ptr, size_t size) {
19181948
#endif
19191949
}
19201950

1921-
#if TARGET_OS_ANDROID
1951+
#if TARGET_OS_ANDROID && __ANDROID_API__ < 28
19221952

19231953
#include <dlfcn.h>
19241954
#include <spawn.h>
@@ -2247,6 +2277,10 @@ CF_EXPORT int _CFPosixSpawnFileActionsAddClose(_CFPosixSpawnFileActionsRef file_
22472277
return _CFPosixSpawnFileActionsAddCloseImpl(file_actions, filedes);
22482278
}
22492279

2280+
CF_EXPORT int _CFPosixSpawnFileActionsChdir(_CFPosixSpawnFileActionsRef file_actions, const char *path) {
2281+
return ENOSYS;
2282+
}
2283+
22502284
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]) {
22512285
_CFPosixSpawnInitialize();
22522286
return _CFPosixSpawnImpl(pid, path, file_actions, attrp, argv, envp);
@@ -2287,12 +2321,13 @@ CF_EXPORT int _CFPosixSpawnFileActionsChdir(_CFPosixSpawnFileActionsRef file_act
22872321
// Glibc versions prior to 2.29 don't support posix_spawn_file_actions_addchdir_np, impacting:
22882322
// - Amazon Linux 2 (EoL mid-2025)
22892323
return ENOSYS;
2290-
#elif defined(__OpenBSD__) || defined(__QNX__)
2324+
#elif defined(__OpenBSD__) || defined(__QNX__) || (defined(__ANDROID__) && __ANDROID_API__ < 34)
22912325
// Currently missing as of:
22922326
// - OpenBSD 7.5 (April 2024)
22932327
// - QNX 8 (December 2023)
2328+
// - Android 13
22942329
return ENOSYS;
2295-
#elif defined(__GLIBC__) || TARGET_OS_DARWIN || defined(__FreeBSD__) || (defined(__ANDROID__) && __ANDROID_API__ >= 34) || defined(__musl__)
2330+
#elif defined(__GLIBC__) || TARGET_OS_DARWIN || defined(__FreeBSD__) || defined(__ANDROID__) || defined(__musl__)
22962331
// Pre-standard posix_spawn_file_actions_addchdir_np version available in:
22972332
// - Solaris 11.3 (October 2015)
22982333
// - Glibc 2.29 (February 2019)

Sources/CoreFoundation/include/CFBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ CF_IMPLICIT_BRIDGING_DISABLED
669669
CF_EXPORT
670670
CFTypeRef CFMakeCollectable(CFTypeRef cf) CF_AUTOMATED_REFCOUNT_UNAVAILABLE;
671671

672+
CF_EXTERN_C_END
673+
672674
#if DEPLOYMENT_RUNTIME_SWIFT
673675

674676
#if TARGET_RT_64_BIT
@@ -696,7 +698,5 @@ CFTypeRef CFMakeCollectable(CFTypeRef cf) CF_AUTOMATED_REFCOUNT_UNAVAILABLE;
696698
#define __ptrauth_cf_objc_isa_pointer
697699
#endif
698700

699-
CF_EXTERN_C_END
700-
701701
#endif /* ! __COREFOUNDATION_CFBASE__ */
702702

Sources/Foundation/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ if(NOT BUILD_SHARED_LIBS)
164164
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend swiftSynchronization>")
165165
endif()
166166

167-
set_target_properties(Foundation PROPERTIES
168-
INSTALL_RPATH "$ORIGIN"
169-
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)
170-
171167
if(dispatch_FOUND)
172168
set_target_properties(Foundation PROPERTIES
173169
BUILD_RPATH "$<TARGET_FILE_DIR:swiftDispatch>")

Sources/Foundation/NSData.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,13 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
433433
#if os(WASI)
434434
// WASI does not have permission concept
435435
let permissions: Int? = nil
436+
// ReadingOptions.atomic won't be specified on WASI as it's marked unavailable
437+
var atomicWrite: Bool { false }
436438
#else
437439
let permissions = try? fm.attributesOfItem(atPath: path)[.posixPermissions] as? Int
440+
let atomicWrite = writeOptionsMask.contains(.atomic)
438441
#endif
439-
if writeOptionsMask.contains(.atomic) {
442+
if atomicWrite {
440443
let (newFD, auxFilePath) = try _NSCreateTemporaryFile(path)
441444
let fh = FileHandle(fileDescriptor: newFD, closeOnDealloc: true)
442445
do {
@@ -487,22 +490,38 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
487490

488491
/// Writes the data object's bytes to the file specified by a given path.
489492
/// NOTE: the 'atomically' flag is ignored if the url is not of a type the supports atomic writes
493+
#if os(WASI)
494+
@available(*, unavailable, message: "WASI does not support atomic file-writing as it does not have temporary directories")
495+
#endif
490496
open func write(toFile path: String, atomically useAuxiliaryFile: Bool) -> Bool {
497+
#if os(WASI)
498+
// WASI does not support atomic file-writing as it does not have temporary directories
499+
return false
500+
#else
491501
do {
492502
try write(toFile: path, options: useAuxiliaryFile ? .atomic : [])
493503
} catch {
494504
return false
495505
}
496506
return true
507+
#endif
497508
}
498509

499510
/// Writes the data object's bytes to the location specified by a given URL.
500511
/// NOTE: the 'atomically' flag is ignored if the url is not of a type the supports atomic writes
512+
#if os(WASI)
513+
@available(*, unavailable, message: "WASI does not support atomic file-writing as it does not have temporary directories")
514+
#endif
501515
open func write(to url: URL, atomically: Bool) -> Bool {
516+
#if os(WASI)
517+
// WASI does not support atomic file-writing as it does not have temporary directories
518+
return false
519+
#else
502520
if url.isFileURL {
503521
return write(toFile: url.path, atomically: atomically)
504522
}
505523
return false
524+
#endif
506525
}
507526

508527
/// Writes the data object's bytes to the location specified by a given URL.

Sources/Foundation/NSNumber.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,18 @@ open class NSNumber : NSValue, @unchecked Sendable {
11501150
}
11511151

11521152
open override var classForCoder: AnyClass { return NSNumber.self }
1153+
1154+
/// Provides a way for `plutil` to know if `CFPropertyList` has returned a literal `true`/`false` value, as opposed to a number which happens to have a value of 1 or 0.
1155+
@_spi(BooleanCheckingForPLUtil)
1156+
public var _exactBoolValue: Bool? {
1157+
if self === kCFBooleanTrue {
1158+
return true
1159+
} else if self === kCFBooleanFalse {
1160+
return false
1161+
} else {
1162+
return nil
1163+
}
1164+
}
11531165
}
11541166

11551167
extension CFNumber : _NSBridgeable {

Sources/Foundation/NSString.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,16 +1266,29 @@ extension NSString {
12661266
data = mData
12671267
}
12681268

1269+
#if os(WASI)
1270+
@available(*, unavailable, message: "WASI does not support atomic file-writing as it does not have temporary directories")
1271+
#endif
12691272
internal func _writeTo(_ url: URL, _ useAuxiliaryFile: Bool, _ enc: UInt) throws {
1273+
#if os(WASI)
1274+
throw CocoaError(.featureUnsupported)
1275+
#else
12701276
var data = Data()
12711277
try _getExternalRepresentation(&data, url, enc)
12721278
try data.write(to: url, options: useAuxiliaryFile ? .atomic : [])
1279+
#endif
12731280
}
12741281

1282+
#if os(WASI)
1283+
@available(*, unavailable, message: "WASI does not support atomic file-writing as it does not have temporary directories")
1284+
#endif
12751285
public func write(to url: URL, atomically useAuxiliaryFile: Bool, encoding enc: UInt) throws {
12761286
try _writeTo(url, useAuxiliaryFile, enc)
12771287
}
12781288

1289+
#if os(WASI)
1290+
@available(*, unavailable, message: "WASI does not support atomic file-writing as it does not have temporary directories")
1291+
#endif
12791292
public func write(toFile path: String, atomically useAuxiliaryFile: Bool, encoding enc: UInt) throws {
12801293
try _writeTo(URL(fileURLWithPath: path), useAuxiliaryFile, enc)
12811294
}

Sources/FoundationNetworking/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ if(NOT BUILD_SHARED_LIBS)
7373

7474
endif()
7575

76-
set_target_properties(FoundationNetworking PROPERTIES
77-
INSTALL_RPATH "$ORIGIN"
78-
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)
79-
8076
if(LINKER_SUPPORTS_BUILD_ID)
8177
target_link_options(FoundationNetworking PRIVATE "LINKER:--build-id=sha1")
8278
endif()

Sources/FoundationXML/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ if(NOT BUILD_SHARED_LIBS)
4646

4747
endif()
4848

49-
set_target_properties(FoundationXML PROPERTIES
50-
INSTALL_RPATH "$ORIGIN"
51-
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)
52-
5349
if(LINKER_SUPPORTS_BUILD_ID)
5450
target_link_options(FoundationXML PRIVATE "LINKER:--build-id=sha1")
5551
endif()

Sources/plutil/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
##===----------------------------------------------------------------------===##
1414

1515
add_executable(plutil
16-
main.swift)
16+
main.swift
17+
PLUContext_Arguments.swift
18+
PLUContext_KeyPaths.swift
19+
PLUContext.swift
20+
PLULiteralOutput.swift)
1721

1822
target_link_libraries(plutil PRIVATE
1923
Foundation)
2024

2125
set_target_properties(plutil PROPERTIES
22-
INSTALL_RPATH "$ORIGIN/../lib/swift/${SWIFT_SYSTEM_NAME}"
23-
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)
26+
INSTALL_RPATH "$ORIGIN/../lib/swift/${SWIFT_SYSTEM_NAME}")
2427

2528
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS plutil)
2629
install(TARGETS plutil

0 commit comments

Comments
 (0)