Skip to content

Merge main into release/6.2 #5220

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 10 commits into from
Jun 4, 2025
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
17 changes: 17 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Create PR to merge main into release branch
# 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.
# 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
on:
schedule:
- cron: '0 9 * * MON'
workflow_dispatch:
jobs:
create_merge_pr:
name: Create PR to merge main into release branch
uses: swiftlang/github-workflows/.github/workflows/create_automerge_pr.yml@main
with:
base_branch: release/6.2
permissions:
contents: write
pull-requests: write
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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ else()
"/clang:-fcf-runtime-abi=swift")
endif()

set(CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH ON)
set(CMAKE_INSTALL_RPATH "$ORIGIN")
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD|DragonFlyBSD")
add_link_options("LINKER:-z,origin")
endif()

if(CMAKE_BUILD_TYPE STREQUAL Debug)
list(APPEND _Foundation_common_build_flags
"-DDEBUG")
Expand Down
41 changes: 38 additions & 3 deletions Sources/CoreFoundation/CFPlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ static inline void _CFSetProgramNameFromPath(const char *path) {
#include <sys/exec.h>
#endif

#if TARGET_OS_BSD && defined(__FreeBSD__)
#include <sys/sysctl.h>
#endif

const char *_CFProcessPath(void) {
if (__CFProcessPath) return __CFProcessPath;

Expand Down Expand Up @@ -230,6 +234,29 @@ const char *_CFProcessPath(void) {
char *res = realpath(ps->ps_argvstr[0], NULL);
argv0 = res? res: strdup(ps->ps_argvstr[0]);
}
#elif defined(__FreeBSD__)
// see sysctl(3), pid == -1 means current process
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
int sysctl_ret = 0;
size_t len = PATH_MAX + 1;
argv0 = calloc(len, 1);

sysctl_ret = sysctl(mib, 4, argv0, &len, NULL, 0);

// in case for whatever reason the path is > PATH_MAX
if (sysctl_ret == -1 && errno == ENOMEM) {
// get size needed
sysctl_ret = sysctl(mib, 4, NULL, &len, NULL, 0);
if (sysctl_ret != -1) {
argv0 = realloc(argv0, len);
sysctl_ret = sysctl(mib, 4, argv0, &len, NULL, 0);
}
}

if (sysctl_ret == -1) {
free(argv0);
argv0 = NULL;
}
#endif

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

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

Expand Down Expand Up @@ -1918,7 +1948,7 @@ CF_CROSS_PLATFORM_EXPORT void *_CFReallocf(void *ptr, size_t size) {
#endif
}

#if TARGET_OS_ANDROID
#if TARGET_OS_ANDROID && __ANDROID_API__ < 28

#include <dlfcn.h>
#include <spawn.h>
Expand Down Expand Up @@ -2247,6 +2277,10 @@ CF_EXPORT int _CFPosixSpawnFileActionsAddClose(_CFPosixSpawnFileActionsRef file_
return _CFPosixSpawnFileActionsAddCloseImpl(file_actions, filedes);
}

CF_EXPORT int _CFPosixSpawnFileActionsChdir(_CFPosixSpawnFileActionsRef file_actions, const char *path) {
return ENOSYS;
}

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]) {
_CFPosixSpawnInitialize();
return _CFPosixSpawnImpl(pid, path, file_actions, attrp, argv, envp);
Expand Down Expand Up @@ -2287,12 +2321,13 @@ CF_EXPORT int _CFPosixSpawnFileActionsChdir(_CFPosixSpawnFileActionsRef file_act
// Glibc versions prior to 2.29 don't support posix_spawn_file_actions_addchdir_np, impacting:
// - Amazon Linux 2 (EoL mid-2025)
return ENOSYS;
#elif defined(__OpenBSD__) || defined(__QNX__)
#elif defined(__OpenBSD__) || defined(__QNX__) || (defined(__ANDROID__) && __ANDROID_API__ < 34)
// Currently missing as of:
// - OpenBSD 7.5 (April 2024)
// - QNX 8 (December 2023)
// - Android 13
return ENOSYS;
#elif defined(__GLIBC__) || TARGET_OS_DARWIN || defined(__FreeBSD__) || (defined(__ANDROID__) && __ANDROID_API__ >= 34) || defined(__musl__)
#elif defined(__GLIBC__) || TARGET_OS_DARWIN || defined(__FreeBSD__) || defined(__ANDROID__) || defined(__musl__)
// Pre-standard posix_spawn_file_actions_addchdir_np version available in:
// - Solaris 11.3 (October 2015)
// - Glibc 2.29 (February 2019)
Expand Down
4 changes: 2 additions & 2 deletions Sources/CoreFoundation/include/CFBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ CF_IMPLICIT_BRIDGING_DISABLED
CF_EXPORT
CFTypeRef CFMakeCollectable(CFTypeRef cf) CF_AUTOMATED_REFCOUNT_UNAVAILABLE;

CF_EXTERN_C_END

#if DEPLOYMENT_RUNTIME_SWIFT

#if TARGET_RT_64_BIT
Expand Down Expand Up @@ -696,7 +698,5 @@ CFTypeRef CFMakeCollectable(CFTypeRef cf) CF_AUTOMATED_REFCOUNT_UNAVAILABLE;
#define __ptrauth_cf_objc_isa_pointer
#endif

CF_EXTERN_C_END

#endif /* ! __COREFOUNDATION_CFBASE__ */

4 changes: 0 additions & 4 deletions Sources/Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ if(NOT BUILD_SHARED_LIBS)
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend swiftSynchronization>")
endif()

set_target_properties(Foundation PROPERTIES
INSTALL_RPATH "$ORIGIN"
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)

if(dispatch_FOUND)
set_target_properties(Foundation PROPERTIES
BUILD_RPATH "$<TARGET_FILE_DIR:swiftDispatch>")
Expand Down
21 changes: 20 additions & 1 deletion Sources/Foundation/NSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,13 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
#if os(WASI)
// WASI does not have permission concept
let permissions: Int? = nil
// ReadingOptions.atomic won't be specified on WASI as it's marked unavailable
var atomicWrite: Bool { false }
#else
let permissions = try? fm.attributesOfItem(atPath: path)[.posixPermissions] as? Int
let atomicWrite = writeOptionsMask.contains(.atomic)
#endif
if writeOptionsMask.contains(.atomic) {
if atomicWrite {
let (newFD, auxFilePath) = try _NSCreateTemporaryFile(path)
let fh = FileHandle(fileDescriptor: newFD, closeOnDealloc: true)
do {
Expand Down Expand Up @@ -487,22 +490,38 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {

/// Writes the data object's bytes to the file specified by a given path.
/// NOTE: the 'atomically' flag is ignored if the url is not of a type the supports atomic writes
#if os(WASI)
@available(*, unavailable, message: "WASI does not support atomic file-writing as it does not have temporary directories")
#endif
open func write(toFile path: String, atomically useAuxiliaryFile: Bool) -> Bool {
#if os(WASI)
// WASI does not support atomic file-writing as it does not have temporary directories
return false
#else
do {
try write(toFile: path, options: useAuxiliaryFile ? .atomic : [])
} catch {
return false
}
return true
#endif
}

/// Writes the data object's bytes to the location specified by a given URL.
/// NOTE: the 'atomically' flag is ignored if the url is not of a type the supports atomic writes
#if os(WASI)
@available(*, unavailable, message: "WASI does not support atomic file-writing as it does not have temporary directories")
#endif
open func write(to url: URL, atomically: Bool) -> Bool {
#if os(WASI)
// WASI does not support atomic file-writing as it does not have temporary directories
return false
#else
if url.isFileURL {
return write(toFile: url.path, atomically: atomically)
}
return false
#endif
}

/// Writes the data object's bytes to the location specified by a given URL.
Expand Down
12 changes: 12 additions & 0 deletions Sources/Foundation/NSNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,18 @@ open class NSNumber : NSValue, @unchecked Sendable {
}

open override var classForCoder: AnyClass { return NSNumber.self }

/// 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.
@_spi(BooleanCheckingForPLUtil)
public var _exactBoolValue: Bool? {
if self === kCFBooleanTrue {
return true
} else if self === kCFBooleanFalse {
return false
} else {
return nil
}
}
}

extension CFNumber : _NSBridgeable {
Expand Down
13 changes: 13 additions & 0 deletions Sources/Foundation/NSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1266,16 +1266,29 @@ extension NSString {
data = mData
}

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

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

#if os(WASI)
@available(*, unavailable, message: "WASI does not support atomic file-writing as it does not have temporary directories")
#endif
public func write(toFile path: String, atomically useAuxiliaryFile: Bool, encoding enc: UInt) throws {
try _writeTo(URL(fileURLWithPath: path), useAuxiliaryFile, enc)
}
Expand Down
4 changes: 0 additions & 4 deletions Sources/FoundationNetworking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ if(NOT BUILD_SHARED_LIBS)

endif()

set_target_properties(FoundationNetworking PROPERTIES
INSTALL_RPATH "$ORIGIN"
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)

if(LINKER_SUPPORTS_BUILD_ID)
target_link_options(FoundationNetworking PRIVATE "LINKER:--build-id=sha1")
endif()
Expand Down
4 changes: 0 additions & 4 deletions Sources/FoundationXML/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ if(NOT BUILD_SHARED_LIBS)

endif()

set_target_properties(FoundationXML PROPERTIES
INSTALL_RPATH "$ORIGIN"
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)

if(LINKER_SUPPORTS_BUILD_ID)
target_link_options(FoundationXML PRIVATE "LINKER:--build-id=sha1")
endif()
Expand Down
9 changes: 6 additions & 3 deletions Sources/plutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
##===----------------------------------------------------------------------===##

add_executable(plutil
main.swift)
main.swift
PLUContext_Arguments.swift
PLUContext_KeyPaths.swift
PLUContext.swift
PLULiteralOutput.swift)

target_link_libraries(plutil PRIVATE
Foundation)

set_target_properties(plutil PROPERTIES
INSTALL_RPATH "$ORIGIN/../lib/swift/${SWIFT_SYSTEM_NAME}"
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)
INSTALL_RPATH "$ORIGIN/../lib/swift/${SWIFT_SYSTEM_NAME}")

set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS plutil)
install(TARGETS plutil
Expand Down
Loading