Skip to content

Commit c46dd83

Browse files
committed
Put back SwiftFoundation name, make progress on getting tests to run on Darwin
1 parent f53a305 commit c46dd83

Some content is hidden

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

68 files changed

+377
-121
lines changed

Package.swift

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ let coreFoundationBuildSettings: [CSetting] = [
88
.define("DEBUG", .when(configuration: .debug)),
99
.define("CF_BUILDING_CF"),
1010
.define("DEPLOYMENT_ENABLE_LIBDISPATCH"),
11+
.define("DEPLOYMENT_RUNTIME_SWIFT"),
1112
.define("HAVE_STRUCT_TIMESPEC"),
1213
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS"),
1314
.define("_GNU_SOURCE", .when(platforms: [.linux, .android])),
@@ -35,7 +36,7 @@ let coreFoundationBuildSettings: [CSetting] = [
3536
]
3637

3738
let coreFoundationLinkerSettings: [LinkerSetting] = [
38-
.unsafeFlags(["-Xlinker", "-alias_list", "-Xlinker", "\(Context.packageDirectory)/Sources/CoreFoundation/DarwinSymbolAliases",], .when(platforms: [.macOS]))
39+
.unsafeFlags(["-Xlinker", "-init", "-Xlinker", "___CFInitialize", "-Xlinker", "-twolevel_namespace", "-Xlinker", "-alias_list", "-Xlinker", "\(Context.packageDirectory)/Sources/CoreFoundation/DarwinSymbolAliases",], .when(platforms: [.macOS]))
3940
]
4041

4142
// For _CFURLSessionInterface, _CFXMLInterface
@@ -75,27 +76,57 @@ let swiftBuildSettings: [SwiftSetting] = [
7576
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS"),
7677
]
7778

79+
#if os(macOS)
80+
let products : [PackageDescription.Product] = [
81+
.library(name: "SwiftFoundation", targets: ["Foundation"]),
82+
.library(name: "SwiftFoundationXML", targets: ["FoundationXML"]),
83+
.library(name: "SwiftFoundationNetworking", targets: ["FoundationNetworking"]),
84+
.executable(name: "plutil", targets: ["plutil"]),
85+
]
86+
87+
let foundationName = "SwiftFoundation"
88+
let foundationXMLName = "SwiftFoundationXML"
89+
let foundationNetworkingName = "SwiftFoundationNetworking"
90+
91+
#else
92+
let products : [PackageDescription.Product] = [
93+
.library(name: "Foundation", targets: ["Foundation"]),
94+
.library(name: "FoundationXML", targets: ["FoundationXML"]),
95+
.library(name: "FoundationNetworking", targets: ["FoundationNetworking"]),
96+
.executable(name: "plutil", targets: ["plutil"]),
97+
]
98+
99+
let foundationName = "Foundation"
100+
let foundationXMLName = "FoundationXML"
101+
let foundationNetworkingName = "FoundationNetworking"
102+
103+
#endif
104+
105+
78106
let package = Package(
79107
name: "swift-corelibs-foundation",
80108
platforms: [.macOS("13.3"), .iOS("16.4"), .tvOS("16.4"), .watchOS("9.4")],
81109
products: [
82-
.library(name: "Foundation", targets: ["Foundation"]),
83-
.library(name: "FoundationXML", targets: ["FoundationXML"]),
84-
.library(name: "FoundationNetworking", targets: ["FoundationNetworking"]),
110+
.library(name: foundationName, targets: [foundationName]),
111+
.library(name: foundationXMLName, targets: [foundationXMLName]),
112+
.library(name: foundationNetworkingName, targets: [foundationNetworkingName]),
85113
.executable(name: "plutil", targets: ["plutil"]),
86114
],
87115
dependencies: [
88116
.package(
89-
url: "https://github.com/apple/swift-foundation-icu",
90-
from: "0.0.5"),
117+
path: "../swift-foundation-icu"
118+
// url: "https://github.com/apple/swift-foundation-icu",
119+
// from: "0.0.5"
120+
),
91121
.package(
92-
url: "https://github.com/apple/swift-foundation",
93-
revision: "7eb8b598ad8f77ac743b2decc97d56bf350aedee"
122+
path: "../swift-foundation"
123+
//url: "https://github.com/apple/swift-foundation",
124+
//revision: "7eb8b598ad8f77ac743b2decc97d56bf350aedee"
94125
),
95126
],
96127
targets: [
97128
.target(
98-
name: "Foundation",
129+
name: foundationName,
99130
dependencies: [
100131
.product(name: "FoundationEssentials", package: "swift-foundation"),
101132
.product(name: "FoundationInternationalization", package: "swift-foundation"),
@@ -105,21 +136,21 @@ let package = Package(
105136
swiftSettings: swiftBuildSettings
106137
),
107138
.target(
108-
name: "FoundationXML",
139+
name: foundationXMLName,
109140
dependencies: [
110141
.product(name: "FoundationEssentials", package: "swift-foundation"),
111-
"Foundation",
142+
.targetItem(name: foundationName, condition: nil),
112143
"_CoreFoundation",
113144
"_CFXMLInterface"
114145
],
115146
path: "Sources/FoundationXML",
116147
swiftSettings: swiftBuildSettings
117148
),
118149
.target(
119-
name: "FoundationNetworking",
150+
name: foundationNetworkingName,
120151
dependencies: [
121152
.product(name: "FoundationEssentials", package: "swift-foundation"),
122-
"Foundation",
153+
.targetItem(name: foundationName, condition: nil),
123154
"_CoreFoundation",
124155
"_CFURLSessionInterface"
125156
],
@@ -173,40 +204,44 @@ let package = Package(
173204
),
174205
.executableTarget(
175206
name: "plutil",
176-
dependencies: ["Foundation"]
207+
dependencies: [
208+
.targetItem(name: foundationName, condition: nil)
209+
]
177210
),
178211
.executableTarget(
179212
name: "xdgTestHelper",
180213
dependencies: [
181-
"Foundation",
182-
"FoundationNetworking"
214+
.targetItem(name: foundationName, condition: nil),
215+
.targetItem(name: foundationXMLName, condition: nil),
216+
.targetItem(name: foundationNetworkingName, condition: nil)
183217
]
184218
),
185219
.target(
186220
// swift-corelibs-foundation has a copy of XCTest's sources so:
187221
// (1) we do not depend on the toolchain's XCTest, which depends on toolchain's Foundation, which we cannot pull in at the same time as a Foundation package
188222
// (2) we do not depend on a swift-corelibs-xctest Swift package, which depends on Foundation, which causes a circular dependency in swiftpm
189223
// We believe Foundation is the only project that needs to take this rather drastic measure.
190-
name: "XCTest",
224+
name: "XCTest",
191225
dependencies: [
192-
"Foundation"
193-
],
226+
.targetItem(name: foundationName, condition: nil)
227+
],
194228
path: "Sources/XCTest"
195229
),
196230
.testTarget(
197231
name: "TestFoundation",
198232
dependencies: [
199-
"Foundation",
200-
"FoundationXML",
201-
"FoundationNetworking",
202-
"XCTest",
233+
.targetItem(name: foundationName, condition: nil),
234+
.targetItem(name: foundationXMLName, condition: nil),
235+
.targetItem(name: foundationNetworkingName, condition: nil),
236+
.targetItem(name: "XCTest", condition: .when(platforms: [.linux])),
203237
"xdgTestHelper"
204238
],
205239
resources: [
206240
.copy("Foundation/Resources")
207241
],
208242
swiftSettings: [
209-
.define("NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT")
243+
.define("NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT"),
244+
.unsafeFlags(["-module-alias", "Foundation=SwiftFoundation", "-module-alias", "FoundationXML=SwiftFoundationXML", "-module-alias", "FoundationNetworking=SwiftFoundationNetworking"], .when(platforms: [.macOS]))
210245
]
211246
),
212247
]

Sources/CoreFoundation/CFTimeZone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ Boolean _CFTimeZoneInit(CFTimeZoneRef timeZone, CFStringRef name, CFDataRef data
13441344
#if !TARGET_OS_ANDROID && !TARGET_OS_WASI
13451345

13461346
if (!__tzZoneInfo) __InitTZStrings();
1347-
if (!__tzZoneInfo) return NULL;
1347+
if (!__tzZoneInfo) return false;
13481348
baseURL = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, __tzZoneInfo, kCFURLPOSIXPathStyle, true);
13491349
#endif
13501350

Sources/CoreFoundation/DarwinSymbolAliases

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22

33
# This is specific to Swift open source; Foundation's NSCFConstantString is used as our constant string class reference
4-
_$s10Foundation19_NSCFConstantStringCN ___CFConstantStringClassReference
4+
_$s15SwiftFoundation19_NSCFConstantStringCN ___CFConstantStringClassReference
55

66
_kCFCalendarIdentifierBuddhist _kCFBuddhistCalendar
77
_kCFCalendarIdentifierChinese _kCFChineseCalendar

Sources/CoreFoundation/include/CFBase.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
#include <libkern/OSTypes.h>
7070
#endif
7171

72+
#if TARGET_OS_MAC
73+
#include <MacTypes.h>
74+
#endif
75+
7276
#if !defined(__MACTYPES__)
7377
#if !defined(_OS_OSTYPES_H)
7478
typedef bool Boolean;

Sources/CoreFoundation/include/CFString.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ since it is the default choice with Mac OS X developer tools.
151151
*/
152152

153153
#if DEPLOYMENT_RUNTIME_SWIFT
154+
#if TARGET_OS_MAC
155+
#define _CF_CONSTANT_STRING_SWIFT_CLASS $s15SwiftFoundation19_NSCFConstantStringCN
156+
#else
154157
#define _CF_CONSTANT_STRING_SWIFT_CLASS $s10Foundation19_NSCFConstantStringCN
158+
#endif
155159

156160
CF_EXPORT void *_CF_CONSTANT_STRING_SWIFT_CLASS[];
157161
#endif

Sources/CoreFoundation/include/ForFoundationOnly.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,11 @@ CF_EXPORT void *_CFCreateArrayStorage(size_t numPointers, Boolean zeroed, size_t
746746
#if DEPLOYMENT_RUNTIME_SWIFT
747747
// --- Static class references for Swift use; implements {DECLARE_,}STATIC_CLASS_REF.
748748

749+
#if TARGET_OS_MAC
750+
#define STATIC_CLASS_PREFIX $s15SwiftFoundation
751+
#else
749752
#define STATIC_CLASS_PREFIX $s10Foundation
753+
#endif
750754

751755
#define STATIC_CLASS_NAME_LENGTH_LOOKUP___NSCFType 10
752756
#define STATIC_CLASS_NAME_LOOKUP___NSCFType __NSCFTypeCN

Sources/Foundation/NSError.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,25 @@ extension CocoaError : _BridgedStoredNSError {
606606
}
607607

608608
extension CocoaError {
609+
#if os(macOS)
610+
// Temporary extension to take Foundation.URL, until FoundationEssentials.URL is fully ported
611+
public static func error(_ code: CocoaError.Code, userInfo: [String : AnyHashable]? = nil, url: SwiftFoundation.URL? = nil) -> Error {
612+
var info: [String : AnyHashable] = userInfo ?? [:]
613+
if let url = url {
614+
info[NSURLErrorKey] = url
615+
}
616+
return CocoaError(code, userInfo: info)
617+
}
618+
#else
609619
// Temporary extension to take Foundation.URL, until FoundationEssentials.URL is fully ported
610620
public static func error(_ code: CocoaError.Code, userInfo: [String : AnyHashable]? = nil, url: Foundation.URL? = nil) -> Error {
611621
var info: [String : AnyHashable] = userInfo ?? [:]
612622
if let url = url {
613623
info[NSURLErrorKey] = url
614624
}
615625
return CocoaError(code, userInfo: info)
616-
}
626+
}
627+
#endif
617628
}
618629

619630
extension CocoaError.Code : _ErrorCodeProtocol {

Sources/Foundation/NSObjCRuntime.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,11 @@ fileprivate var mapFromSwiftClassNameToObjCName: [String: String] = {
359359
return map
360360
}()
361361

362+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
363+
private let _SwiftFoundationModuleName = "SwiftFoundation"
364+
#else
362365
private let _SwiftFoundationModuleName = "Foundation"
366+
#endif
363367

364368
internal let _SwiftFoundationNetworkingModuleName = _SwiftFoundationModuleName + "Networking"
365369
internal let _SwiftFoundationXMLModuleName = _SwiftFoundationModuleName + "XML"

Sources/FoundationNetworking/Boxing.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212

1313
// This file is for internal use of FoundationNetworking
1414

15+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
16+
import SwiftFoundation
17+
#else
1518
import Foundation
19+
#endif
20+
1621
/// A class type which acts as a handle (pointer-to-pointer) to a Foundation reference type which has only a mutable class (e.g., NSURLComponents).
1722
///
1823
/// Note: This assumes that the result of calling copy() is mutable. The documentation says that classes which do not have a mutable/immutable distinction should just adopt NSCopying instead of NSMutableCopying.

Sources/FoundationNetworking/DataURLProtocol.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99

1010
// Protocol implementation of data: URL scheme
1111

12+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
13+
import SwiftFoundation
14+
#else
1215
import Foundation
16+
#endif
17+
1318

1419
// Iterate through a SubString validating that the input is ASCII and converting any %xx
1520
// percent endcoded hex sequences to a UInt8 byte.

Sources/FoundationNetworking/HTTPCookie.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
11+
import SwiftFoundation
12+
#else
1013
import Foundation
14+
#endif
15+
1116
#if os(Windows)
1217
import WinSDK
1318
#endif

Sources/FoundationNetworking/HTTPCookieStorage.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
11+
import SwiftFoundation
12+
#else
1013
import Foundation
14+
#endif
15+
1116
@_implementationOnly import _CoreFoundation
1217

1318
/*!

Sources/FoundationNetworking/NSURLRequest.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
11+
import SwiftFoundation
12+
#else
1013
import Foundation
14+
#endif
15+
1116
// -----------------------------------------------------------------------------
1217
///
1318
/// This header file describes the constructs used to represent URL

Sources/FoundationNetworking/URLAuthenticationChallenge.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
11+
import SwiftFoundation
12+
#else
1013
import Foundation
14+
#endif
15+
1116
public protocol URLAuthenticationChallengeSender : NSObjectProtocol {
1217

1318

Sources/FoundationNetworking/URLCache.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
11+
import SwiftFoundation
12+
#else
1013
import Foundation
14+
#endif
15+
1116
internal extension NSLock {
1217
func performLocked<T>(_ block: () throws -> T) rethrows -> T {
1318
lock(); defer { unlock() }

Sources/FoundationNetworking/URLCredential.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
11+
import SwiftFoundation
12+
#else
1013
import Foundation
14+
#endif
15+
1116
/*!
1217
@enum URLCredential.Persistence
1318
@abstract Constants defining how long a credential will be kept around

Sources/FoundationNetworking/URLCredentialStorage.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
11+
import SwiftFoundation
12+
#else
1013
import Foundation
14+
#endif
15+
1116
/*!
1217
@class URLCredential.Storage
1318
@discussion URLCredential.Storage implements a singleton object (shared instance) which manages the shared credentials cache. Note: Whereas in Mac OS X any application can access any credential with a persistence of URLCredential.Persistence.permanent provided the user gives permission, in iPhone OS an application can access only its own credentials.

Sources/FoundationNetworking/URLProtectionSpace.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
11+
import SwiftFoundation
12+
#else
1013
import Foundation
14+
#endif
15+
1116
/*!
1217
@const NSURLProtectionSpaceHTTP
1318
@abstract The protocol for HTTP

Sources/FoundationNetworking/URLProtocol.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
11+
import SwiftFoundation
12+
#else
1013
import Foundation
14+
#endif
15+
1116
/*!
1217
@header URLProtocol.h
1318

0 commit comments

Comments
 (0)