From f5fe750a576177b99e0a4b1b24f923ba645c785d Mon Sep 17 00:00:00 2001 From: Jonathan Flat Date: Wed, 30 Sep 2026 09:06:03 -0600 Subject: [PATCH 1/2] Improve CSystem import handling --- Sources/CSystem/CMakeLists.txt | 2 - Sources/CSystem/include/CSystemDarwin.h | 20 -------- Sources/CSystem/include/CSystemLinux.h | 32 ++++++++----- Sources/CSystem/include/CSystemWindows.h | 17 ------- Sources/CSystem/include/io_uring.h | 46 ++----------------- Sources/CSystem/include/module.modulemap | 13 +++++- Sources/CSystem/shims.c | 43 +++++++++++++++-- .../System/FilePath/FilePathTempPosix.swift | 4 +- Sources/System/FileSystem/Stat.swift | 3 -- Sources/System/IORing/IOCompletion.swift | 2 +- Sources/System/IORing/IORequest.swift | 2 +- Sources/System/IORing/IORing+Util.swift | 15 +++--- Sources/System/IORing/IORing.swift | 5 +- Sources/System/IORing/RawIORequest.swift | 2 +- Sources/System/Internals/CInterop.swift | 8 +--- Sources/System/Internals/Constants.swift | 11 ++++- Sources/System/Internals/Exports.swift | 7 +-- Sources/System/Internals/Syscalls.swift | 2 +- Tests/MemberImportVisibility/Probe.swift | 7 ++- Tests/SystemTests/FileOperationsTest.swift | 16 +++++++ Tests/SystemTests/IORingTests.swift | 7 +-- Tests/SystemTests/StatTests.swift | 2 - 22 files changed, 126 insertions(+), 140 deletions(-) delete mode 100644 Sources/CSystem/include/CSystemDarwin.h delete mode 100644 Sources/CSystem/include/CSystemWindows.h diff --git a/Sources/CSystem/CMakeLists.txt b/Sources/CSystem/CMakeLists.txt index 70e08e4..49fbd6a 100644 --- a/Sources/CSystem/CMakeLists.txt +++ b/Sources/CSystem/CMakeLists.txt @@ -13,11 +13,9 @@ target_include_directories(CSystem PUBLIC $) install(FILES - include/CSystemDarwin.h include/CSystemLinux.h include/CSystemShared.h include/CSystemWASI.h - include/CSystemWindows.h include/CSystemFreeBSD.h include/io_uring.h include/module.modulemap diff --git a/Sources/CSystem/include/CSystemDarwin.h b/Sources/CSystem/include/CSystemDarwin.h deleted file mode 100644 index bcef0a6..0000000 --- a/Sources/CSystem/include/CSystemDarwin.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - This source file is part of the Swift System open source project - - Copyright (c) 2026 Apple Inc. and the Swift System project authors - Licensed under Apache License v2.0 with Runtime Library Exception - - See https://swift.org/LICENSE.txt for license information -*/ - -#if defined(__APPLE__) - -#include - -#ifdef O_CLOFORK -#define COMPATIBILITY_O_CLOFORK O_CLOFORK -#else -#define COMPATIBILITY_O_CLOFORK 0 -#endif - -#endif // defined(__APPLE__) diff --git a/Sources/CSystem/include/CSystemLinux.h b/Sources/CSystem/include/CSystemLinux.h index 815e142..3c99b69 100644 --- a/Sources/CSystem/include/CSystemLinux.h +++ b/Sources/CSystem/include/CSystemLinux.h @@ -1,7 +1,7 @@ /* This source file is part of the Swift System open source project - Copyright (c) 2020 Apple Inc. and the Swift System project authors + Copyright (c) 2020 - 2026 Apple Inc. and the Swift System project authors Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information @@ -9,16 +9,24 @@ #ifdef __linux__ -#include +// Glibc doesn't export eventfd, which the tests use. #include -#include -#include -#include -#include -#include -#include -#include -#include -#include "io_uring.h" -#endif +#if !defined(__ANDROID__) +#include +#include "io_uring.h" + +// Defined in shims.c, which can include the libc headers they need. +extern int csystem_io_uring_setup(unsigned int entries, + struct io_uring_params *p); +extern int csystem_io_uring_enter(int fd, unsigned int to_submit, + unsigned int min_complete, + unsigned int flags, void *sig); +extern int csystem_io_uring_enter2(int fd, unsigned int to_submit, + unsigned int min_complete, + unsigned int flags, void *args, size_t sz); +extern int csystem_io_uring_register(int fd, unsigned int opcode, void *arg, + unsigned int nr_args); +#endif // !defined(__ANDROID__) + +#endif // __linux__ diff --git a/Sources/CSystem/include/CSystemWindows.h b/Sources/CSystem/include/CSystemWindows.h deleted file mode 100644 index 7719be9..0000000 --- a/Sources/CSystem/include/CSystemWindows.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - This source file is part of the Swift System open source project - - Copyright (c) 2020 Apple Inc. and the Swift System project authors - Licensed under Apache License v2.0 with Runtime Library Exception - - See https://swift.org/LICENSE.txt for license information -*/ - -#if defined(_WIN32) - -#define NOMINMAX -#define WIN32_LEAN_AND_MEAN -#define VC_EXTRA_LEAN -#include - -#endif diff --git a/Sources/CSystem/include/io_uring.h b/Sources/CSystem/include/io_uring.h index defc284..b633283 100644 --- a/Sources/CSystem/include/io_uring.h +++ b/Sources/CSystem/include/io_uring.h @@ -1,7 +1,6 @@ -#include -#include -#include -#include +#pragma once + +// Types only: the syscall wrappers need libc headers, so they're in shims.c. #define __SWIFT_IORING_SQE_FALLBACK_STRUCT { \ __u8 opcode; \ @@ -193,19 +192,6 @@ struct io_uring_params { }; #endif // __has_include() -#ifndef SWIFT_IORING_C_WRAPPER -#define SWIFT_IORING_C_WRAPPER - -# ifndef __NR_io_uring_setup -# define __NR_io_uring_setup 425 -# endif -# ifndef __NR_io_uring_enter -# define __NR_io_uring_enter 426 -# endif -# ifndef __NR_io_uring_register -# define __NR_io_uring_register 427 -# endif - /* struct io_uring_getevents_arg { __u64 sigmask; @@ -220,29 +206,3 @@ struct swift_io_uring_getevents_arg { __u32 min_wait_usec; __u64 ts; }; - -static inline int io_uring_register(int fd, unsigned int opcode, void *arg, - unsigned int nr_args) -{ - return syscall(__NR_io_uring_register, fd, opcode, arg, nr_args); -} - -static inline int io_uring_setup(unsigned int entries, struct io_uring_params *p) -{ - return syscall(__NR_io_uring_setup, entries, p); -} - -static inline int io_uring_enter2(int fd, unsigned int to_submit, unsigned int min_complete, - unsigned int flags, void *args, size_t sz) -{ - return syscall(__NR_io_uring_enter, fd, to_submit, min_complete, - flags, args, sz); -} - -static inline int io_uring_enter(int fd, unsigned int to_submit, unsigned int min_complete, - unsigned int flags, sigset_t *sig) -{ - return io_uring_enter2(fd, to_submit, min_complete, flags, sig, _NSIG / 8); -} - -#endif diff --git a/Sources/CSystem/include/module.modulemap b/Sources/CSystem/include/module.modulemap index 31e1371..07a52bf 100644 --- a/Sources/CSystem/include/module.modulemap +++ b/Sources/CSystem/include/module.modulemap @@ -1,9 +1,18 @@ +// System imports CSystem with `internal import`. Don't include a header that +// the platform's C module also includes: CSystem would then co-own its +// declarations, so Swift would limit them to CSystem's import access level and +// could credit their members to CSystem under MemberImportVisibility. +// (CSystemWASI.h and CSystemFreeBSD.h still do; see Constants.swift.) module CSystem { header "CSystemShared.h" - header "CSystemDarwin.h" header "CSystemLinux.h" header "CSystemWASI.h" - header "CSystemWindows.h" header "CSystemFreeBSD.h" export * } + +// IORing's inlinable code stores these types, so System imports this module +// with `public import`. Keep libc headers out of it too. +module CSystemIOUring { + header "io_uring.h" +} diff --git a/Sources/CSystem/shims.c b/Sources/CSystem/shims.c index b32bd84..9ba0eb2 100644 --- a/Sources/CSystem/shims.c +++ b/Sources/CSystem/shims.c @@ -20,13 +20,12 @@ #ifdef __linux__ #define _GNU_SOURCE +#include +#include +#include #include #endif -#if defined(_WIN32) -#include -#endif - #include #if !defined(_WIN32) && !defined(__wasi__) && !defined(__APPLE__) @@ -70,3 +69,39 @@ extern int csystem_posix_dup3(int fildes, int fildes2, int flag) { return -1; #endif } + +#if defined(__linux__) && !defined(__ANDROID__) +# ifndef __NR_io_uring_setup +# define __NR_io_uring_setup 425 +# endif +# ifndef __NR_io_uring_enter +# define __NR_io_uring_enter 426 +# endif +# ifndef __NR_io_uring_register +# define __NR_io_uring_register 427 +# endif + +extern int csystem_io_uring_setup(unsigned int entries, + struct io_uring_params *p) { + return syscall(__NR_io_uring_setup, entries, p); +} + +extern int csystem_io_uring_enter2(int fd, unsigned int to_submit, + unsigned int min_complete, + unsigned int flags, void *args, size_t sz) { + return syscall(__NR_io_uring_enter, fd, to_submit, min_complete, flags, + args, sz); +} + +extern int csystem_io_uring_enter(int fd, unsigned int to_submit, + unsigned int min_complete, + unsigned int flags, void *sig) { + return csystem_io_uring_enter2(fd, to_submit, min_complete, flags, sig, + _NSIG / 8); +} + +extern int csystem_io_uring_register(int fd, unsigned int opcode, void *arg, + unsigned int nr_args) { + return syscall(__NR_io_uring_register, fd, opcode, arg, nr_args); +} +#endif // defined(__linux__) && !defined(__ANDROID__) diff --git a/Sources/System/FilePath/FilePathTempPosix.swift b/Sources/System/FilePath/FilePathTempPosix.swift index 2ac7098..8b548a8 100644 --- a/Sources/System/FilePath/FilePathTempPosix.swift +++ b/Sources/System/FilePath/FilePathTempPosix.swift @@ -12,15 +12,13 @@ #if SYSTEM_PACKAGE_DARWIN import Darwin #elseif canImport(Glibc) -import CSystem import Glibc #elseif canImport(Musl) -import CSystem import Musl #elseif canImport(WASILibc) +internal import CSystem // For the members of system_dirent import WASILibc #elseif canImport(Android) -import CSystem import Android #else #error("Unsupported Platform") diff --git a/Sources/System/FileSystem/Stat.swift b/Sources/System/FileSystem/Stat.swift index ce4b6b5..e4a7f9d 100644 --- a/Sources/System/FileSystem/Stat.swift +++ b/Sources/System/FileSystem/Stat.swift @@ -15,15 +15,12 @@ #if SYSTEM_PACKAGE_DARWIN import Darwin #elseif canImport(Glibc) -import CSystem import Glibc #elseif canImport(Musl) -import CSystem import Musl #elseif canImport(WASILibc) import WASILibc #elseif canImport(Android) -import CSystem import Android #else #error("Unsupported Platform") diff --git a/Sources/System/IORing/IOCompletion.swift b/Sources/System/IORing/IOCompletion.swift index d9e6905..53588b0 100644 --- a/Sources/System/IORing/IOCompletion.swift +++ b/Sources/System/IORing/IOCompletion.swift @@ -1,7 +1,7 @@ #if compiler(>=6.2) && $Lifetimes #if os(Linux) -import CSystem +public import CSystemIOUring public extension IORing { struct Completion: ~Copyable { diff --git a/Sources/System/IORing/IORequest.swift b/Sources/System/IORing/IORequest.swift index 4a388c4..b23a843 100644 --- a/Sources/System/IORing/IORequest.swift +++ b/Sources/System/IORing/IORequest.swift @@ -1,7 +1,7 @@ #if compiler(>=6.2) && $Lifetimes #if os(Linux) -import CSystem +public import CSystemIOUring @usableFromInline internal enum IORequestCore { diff --git a/Sources/System/IORing/IORing+Util.swift b/Sources/System/IORing/IORing+Util.swift index be25886..2ff757c 100644 --- a/Sources/System/IORing/IORing+Util.swift +++ b/Sources/System/IORing/IORing+Util.swift @@ -10,14 +10,15 @@ #if compiler(>=6.2) && $Lifetimes #if os(Linux) -import CSystem +internal import CSystem +public import CSystemIOUring #if canImport(Glibc) import Glibc #elseif canImport(Musl) import Musl #endif -/// Throwing wrapper around the `io_uring_enter2` shim. +/// Throwing wrapper around the `csystem_io_uring_enter2` shim. /// /// On success returns the syscall's non-negative result (the number of SQEs /// consumed by the kernel). On failure, reads `errno` and throws the matching @@ -32,14 +33,14 @@ internal func _ioUringEnter2( argsSize: Int ) throws(Errno) -> Int32 { let result = valueOrErrno(retryOnInterrupt: true) { - io_uring_enter2( + csystem_io_uring_enter2( ringDescriptor, toSubmit, minComplete, flags, args, argsSize ) } return try result.get() } -/// Throwing wrapper around the `io_uring_enter` shim. +/// Throwing wrapper around the `csystem_io_uring_enter` shim. /// /// On success returns the syscall's non-negative result (the number of SQEs /// consumed by the kernel). On failure, reads `errno` and throws the matching @@ -53,12 +54,12 @@ internal func _ioUringEnter( sig: UnsafeMutablePointer? ) throws(Errno) -> Int32 { let result = valueOrErrno(retryOnInterrupt: true) { - io_uring_enter(ringDescriptor, toSubmit, minComplete, flags, sig) + csystem_io_uring_enter(ringDescriptor, toSubmit, minComplete, flags, sig) } return try result.get() } -/// Throwing wrapper around the `io_uring_register` shim. +/// Throwing wrapper around the `csystem_io_uring_register` shim. /// /// On success returns the syscall's non-negative result. On failure, reads /// `errno` and throws the matching `Errno`. `EINTR` is retried automatically. @@ -70,7 +71,7 @@ internal func _ioUringRegister( nrArgs: UInt32 ) throws(Errno) -> Int32 { let result = valueOrErrno(retryOnInterrupt: true) { - io_uring_register(ringDescriptor, opcode, arg, nrArgs) + csystem_io_uring_register(ringDescriptor, opcode, arg, nrArgs) } return try result.get() } diff --git a/Sources/System/IORing/IORing.swift b/Sources/System/IORing/IORing.swift index 27d27a0..bce65f5 100644 --- a/Sources/System/IORing/IORing.swift +++ b/Sources/System/IORing/IORing.swift @@ -1,7 +1,8 @@ #if compiler(>=6.2) && $Lifetimes #if os(Linux) -import CSystem +internal import CSystem +public import CSystemIOUring // needed for mmap #if canImport(Glibc) import Glibc @@ -223,7 +224,7 @@ private func setUpRing( var err: Errno? = nil let ringDescriptor = withUnsafeMutablePointer(to: ¶ms) { - let result = io_uring_setup(queueDepth, $0) + let result = csystem_io_uring_setup(queueDepth, $0) if result < 0 { err = Errno.current } diff --git a/Sources/System/IORing/RawIORequest.swift b/Sources/System/IORing/RawIORequest.swift index 40156dd..357bc98 100644 --- a/Sources/System/IORing/RawIORequest.swift +++ b/Sources/System/IORing/RawIORequest.swift @@ -1,7 +1,7 @@ #if compiler(>=6.2) && $Lifetimes #if os(Linux) -import CSystem +public import CSystemIOUring #if canImport(Glibc) import Glibc #elseif canImport(Musl) diff --git a/Sources/System/Internals/CInterop.swift b/Sources/System/Internals/CInterop.swift index 5570d1e..6d98f12 100644 --- a/Sources/System/Internals/CInterop.swift +++ b/Sources/System/Internals/CInterop.swift @@ -10,19 +10,15 @@ #if SYSTEM_PACKAGE_DARWIN import Darwin #elseif os(Windows) -import CSystem import ucrt #elseif canImport(Glibc) -import CSystem import Glibc #elseif canImport(Musl) -import CSystem import Musl #elseif canImport(WASILibc) import WASILibc -#elseif canImport(Bionic) -import CSystem -import Bionic +#elseif canImport(Android) +import Android #else #error("Unsupported Platform") #endif diff --git a/Sources/System/Internals/Constants.swift b/Sources/System/Internals/Constants.swift index 656e2c3..2a3989f 100644 --- a/Sources/System/Internals/Constants.swift +++ b/Sources/System/Internals/Constants.swift @@ -15,6 +15,7 @@ import Darwin #elseif os(Windows) import ucrt +import WinSDK #elseif canImport(Glibc) import Glibc #elseif canImport(Musl) @@ -27,7 +28,11 @@ import Android #error("Unsupported Platform") #endif -import CSystem +// Some WASI and FreeBSD constants come from CSystem and are inlined into +// clients. +#if os(WASI) || os(FreeBSD) +public import CSystem +#endif // MARK: errno #if SYSTEM_PACKAGE_DARWIN @@ -629,7 +634,9 @@ internal var _O_CLOEXEC: CInt { #if !os(Windows) @_alwaysEmitIntoClient internal var _O_CLOFORK: CInt { - #if SYSTEM_PACKAGE_DARWIN || os(FreeBSD) + #if SYSTEM_PACKAGE_DARWIN + 0x0800_0000 // O_CLOFORK, which SDKs before macOS 27 lack + #elseif os(FreeBSD) COMPATIBILITY_O_CLOFORK #elseif !os(WASI) && !os(Linux) && !os(Android) O_CLOFORK diff --git a/Sources/System/Internals/Exports.swift b/Sources/System/Internals/Exports.swift index 6ce7d4d..7dd9d4e 100644 --- a/Sources/System/Internals/Exports.swift +++ b/Sources/System/Internals/Exports.swift @@ -10,23 +10,18 @@ // Internal wrappers and typedefs which help reduce #if littering in System's // code base. -// TODO: Should CSystem just include all the header files we need? - #if SYSTEM_PACKAGE_DARWIN import Darwin #elseif os(Windows) -import CSystem import ucrt +import WinSDK #elseif canImport(Glibc) -import CSystem import Glibc #elseif canImport(Musl) -import CSystem import Musl #elseif canImport(WASILibc) import WASILibc #elseif canImport(Android) -import CSystem import Android #else #error("Unsupported Platform") diff --git a/Sources/System/Internals/Syscalls.swift b/Sources/System/Internals/Syscalls.swift index b0d9dae..0909029 100644 --- a/Sources/System/Internals/Syscalls.swift +++ b/Sources/System/Internals/Syscalls.swift @@ -7,7 +7,7 @@ See https://swift.org/LICENSE.txt for license information */ -import CSystem +internal import CSystem #if SYSTEM_PACKAGE_DARWIN import Darwin #elseif canImport(Glibc) diff --git a/Tests/MemberImportVisibility/Probe.swift b/Tests/MemberImportVisibility/Probe.swift index a27c836..9359931 100644 --- a/Tests/MemberImportVisibility/Probe.swift +++ b/Tests/MemberImportVisibility/Probe.swift @@ -16,8 +16,9 @@ // - Access raw C members of vended types (e.g. CInterop.Stat) as a downstream // consumer would. Don't go through the Swift (e.g. Stat) wrapper since its // accesses happen inside System, where importing CSystem is fine. -// - Touch every direct member the public API exposes. One field is not always -// a safe proxy for the rest. +// - Touch every direct member the public API exposes, and the members of C +// types it exposes through them (e.g. timespec). One field is not always a +// safe proxy for the rest. #if canImport(Glibc) || canImport(Musl) || canImport(Android) #if canImport(Glibc) @@ -43,5 +44,7 @@ func _mivProbe(_ s: CInterop.Stat) { _ = s.st_atim _ = s.st_mtim _ = s.st_ctim + _ = s.st_atim.tv_sec + _ = s.st_atim.tv_nsec } #endif diff --git a/Tests/SystemTests/FileOperationsTest.swift b/Tests/SystemTests/FileOperationsTest.swift index f62dc48..2434bb5 100644 --- a/Tests/SystemTests/FileOperationsTest.swift +++ b/Tests/SystemTests/FileOperationsTest.swift @@ -201,6 +201,22 @@ final class FileOperationsTest: XCTestCase { } } } + + #if canImport(Darwin, _version: 428) // The macOS 27 SDK defines O_CLOFORK. + func testAdHocPipeCloseOnFork() throws { + guard #available(macOS 27.0, iOS 27.0, watchOS 27.0, tvOS 27.0, visionOS 27.0, *) else { + throw XCTSkip("pipe2 and PipeOptions require anyAppleOS 27 or newer") + } + // System spells O_CLOFORK as a literal on Darwin. + XCTAssertEqual(FileDescriptor.PipeOptions.closeOnFork.rawValue, O_CLOFORK) + let pipe = try FileDescriptor.pipe(options: .closeOnFork) + try pipe.readEnd.closeAfter { + try pipe.writeEnd.closeAfter { + XCTAssertEqual(fcntl(pipe.readEnd.rawValue, F_GETFD) & FD_CLOFORK, FD_CLOFORK) + } + } + } + #endif #endif // !os(WASI) #if !os(Windows) diff --git a/Tests/SystemTests/IORingTests.swift b/Tests/SystemTests/IORingTests.swift index 97bf86c..4cd2ea9 100644 --- a/Tests/SystemTests/IORingTests.swift +++ b/Tests/SystemTests/IORingTests.swift @@ -2,7 +2,8 @@ #if os(Linux) import XCTest -import CSystem //for eventfd +import CSystem // for eventfd and csystem_io_uring_setup +import CSystemIOUring #if canImport(Glibc) import Glibc // for errno #elseif canImport(Musl) @@ -28,7 +29,7 @@ let uringEnabled: Bool = { func isUringEnabled() throws -> Bool { // Even if the kernel supports io_uring, the SystemPackage build may have // been compiled against older kernel headers that lack features it needs - // (gated on IORING_TIMEOUT_BOOTTIME in CSystem); in that configuration + // (gated on IORING_TIMEOUT_BOOTTIME in io_uring.h); in that configuration // IORing.init throws ENOTSUP. Treat that as disabled so tests skip cleanly // instead of failing. do throws(Errno) { @@ -59,7 +60,7 @@ func isUringEnabled() throws -> Bool { // - EPERM or EACCES -> treat as disabled // - propagate any other error. var params = io_uring_params() - let raw = io_uring_setup(1, ¶ms) + let raw = csystem_io_uring_setup(1, ¶ms) if raw < 0 { let err = Errno(rawValue: errno) switch err { diff --git a/Tests/SystemTests/StatTests.swift b/Tests/SystemTests/StatTests.swift index 11876b8..37e2aa2 100644 --- a/Tests/SystemTests/StatTests.swift +++ b/Tests/SystemTests/StatTests.swift @@ -16,10 +16,8 @@ import Testing #if SYSTEM_PACKAGE_DARWIN import Darwin #elseif canImport(Glibc) -import CSystem import Glibc #elseif canImport(Musl) -import CSystem import Musl #elseif canImport(WASILibc) import CSystem From 4179b2cce50ec130857543bab03ded8952ef34b4 Mon Sep 17 00:00:00 2001 From: Jonathan Flat Date: Mon, 12 Oct 2026 19:33:46 -0600 Subject: [PATCH 2/2] Remove CSystemFreeBSD.h, too --- Sources/CSystem/CMakeLists.txt | 1 - Sources/CSystem/include/CSystemFreeBSD.h | 20 -------------------- Sources/CSystem/include/module.modulemap | 3 +-- Sources/CSystem/shims.c | 4 ---- Sources/System/Internals/Constants.swift | 11 ++++------- 5 files changed, 5 insertions(+), 34 deletions(-) delete mode 100644 Sources/CSystem/include/CSystemFreeBSD.h diff --git a/Sources/CSystem/CMakeLists.txt b/Sources/CSystem/CMakeLists.txt index 49fbd6a..7f0a79f 100644 --- a/Sources/CSystem/CMakeLists.txt +++ b/Sources/CSystem/CMakeLists.txt @@ -16,7 +16,6 @@ install(FILES include/CSystemLinux.h include/CSystemShared.h include/CSystemWASI.h - include/CSystemFreeBSD.h include/io_uring.h include/module.modulemap DESTINATION include/CSystem) diff --git a/Sources/CSystem/include/CSystemFreeBSD.h b/Sources/CSystem/include/CSystemFreeBSD.h deleted file mode 100644 index d90c343..0000000 --- a/Sources/CSystem/include/CSystemFreeBSD.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - This source file is part of the Swift System open source project - - Copyright (c) 2026 Apple Inc. and the Swift System project authors - Licensed under Apache License v2.0 with Runtime Library Exception - - See https://swift.org/LICENSE.txt for license information -*/ - -#if defined(__FreeBSD__) - -#include - -#ifdef O_CLOFORK -#define COMPATIBILITY_O_CLOFORK O_CLOFORK -#else -#define COMPATIBILITY_O_CLOFORK 0 -#endif - -#endif // defined(__FreeBSD__) diff --git a/Sources/CSystem/include/module.modulemap b/Sources/CSystem/include/module.modulemap index 07a52bf..64a5c41 100644 --- a/Sources/CSystem/include/module.modulemap +++ b/Sources/CSystem/include/module.modulemap @@ -2,12 +2,11 @@ // the platform's C module also includes: CSystem would then co-own its // declarations, so Swift would limit them to CSystem's import access level and // could credit their members to CSystem under MemberImportVisibility. -// (CSystemWASI.h and CSystemFreeBSD.h still do; see Constants.swift.) +// (CSystemWASI.h still does; see Constants.swift.) module CSystem { header "CSystemShared.h" header "CSystemLinux.h" header "CSystemWASI.h" - header "CSystemFreeBSD.h" export * } diff --git a/Sources/CSystem/shims.c b/Sources/CSystem/shims.c index 9ba0eb2..b0425ad 100644 --- a/Sources/CSystem/shims.c +++ b/Sources/CSystem/shims.c @@ -14,10 +14,6 @@ #include #endif -#if defined(__FreeBSD__) -#include -#endif - #ifdef __linux__ #define _GNU_SOURCE #include diff --git a/Sources/System/Internals/Constants.swift b/Sources/System/Internals/Constants.swift index 2a3989f..f74d784 100644 --- a/Sources/System/Internals/Constants.swift +++ b/Sources/System/Internals/Constants.swift @@ -28,9 +28,8 @@ import Android #error("Unsupported Platform") #endif -// Some WASI and FreeBSD constants come from CSystem and are inlined into -// clients. -#if os(WASI) || os(FreeBSD) +// Some WASI constants come from CSystem and are inlined into clients. +#if os(WASI) public import CSystem #endif @@ -634,10 +633,8 @@ internal var _O_CLOEXEC: CInt { #if !os(Windows) @_alwaysEmitIntoClient internal var _O_CLOFORK: CInt { - #if SYSTEM_PACKAGE_DARWIN - 0x0800_0000 // O_CLOFORK, which SDKs before macOS 27 lack - #elseif os(FreeBSD) - COMPATIBILITY_O_CLOFORK + #if SYSTEM_PACKAGE_DARWIN || os(FreeBSD) + 0x0800_0000 // O_CLOFORK, which SDKs before macOS 27 and older FreeBSD lack #elseif !os(WASI) && !os(Linux) && !os(Android) O_CLOFORK #else