Skip to content

Commit 8268261

Browse files
authored
Add infrastructure for updates to new Swift Build build system. (#8338)
A previous PR #8271 created an alternate SwiftPM build system called Swift Build. This change adds necessary infrastructure for updates to the PIF Builder using this build system.
1 parent bafe38b commit 8268261

28 files changed

+2694
-42
lines changed

Package.swift

+29
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ let package = Package(
9292
platforms: [
9393
.macOS(.v13),
9494
.iOS(.v16),
95+
.macCatalyst(.v17),
9596
],
9697
products:
9798
autoProducts.flatMap {
@@ -119,6 +120,12 @@ let package = Package(
119120
type: .dynamic,
120121
targets: ["PackageDescription", "CompilerPluginSupport"]
121122
),
123+
.library(
124+
name: "AppleProductTypes",
125+
type: .dynamic,
126+
targets: ["AppleProductTypes"]
127+
),
128+
122129
.library(
123130
name: "PackagePlugin",
124131
type: .dynamic,
@@ -153,6 +160,21 @@ let package = Package(
153160
linkerSettings: packageLibraryLinkSettings
154161
),
155162

163+
// The `AppleProductTypes` target provides additional product types
164+
// to `Package.swift` manifests. Here we build a debug version of the
165+
// library; the bootstrap scripts build the deployable version.
166+
.target(
167+
name: "AppleProductTypes",
168+
// Note: We use `-module-link-name` so clients link against the
169+
// AppleProductTypes library when they import it without further
170+
// messing with the manifest loader.
171+
dependencies: ["PackageDescription"],
172+
swiftSettings: [
173+
.unsafeFlags(["-package-description-version", "999.0"]),
174+
.unsafeFlags(["-enable-library-evolution"], .when(platforms: [.macOS])),
175+
.unsafeFlags(["-Xfrontend", "-module-link-name", "-Xfrontend", "AppleProductTypes"])
176+
]),
177+
156178
// The `PackagePlugin` target provides the API that is available to
157179
// plugin scripts. Here we build a debug version of the library; the
158180
// bootstrap scripts build the deployable version.
@@ -1022,6 +1044,13 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
10221044
]
10231045
}
10241046

1047+
/// If ENABLE_APPLE_PRODUCT_TYPES is set in the environment, then also define ENABLE_APPLE_PRODUCT_TYPES in each of the regular targets and test targets.
1048+
if ProcessInfo.processInfo.environment["ENABLE_APPLE_PRODUCT_TYPES"] == "1" {
1049+
for target in package.targets.filter({ $0.type == .regular || $0.type == .test }) {
1050+
target.swiftSettings = (target.swiftSettings ?? []) + [ .define("ENABLE_APPLE_PRODUCT_TYPES") ]
1051+
}
1052+
}
1053+
10251054
if ProcessInfo.processInfo.environment["SWIFTPM_SWBUILD_FRAMEWORK"] == nil &&
10261055
ProcessInfo.processInfo.environment["SWIFTPM_NO_SWBUILD_DEPENDENCY"] == nil {
10271056

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2021 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
@_spi(PackageProductSettings) import PackageDescription
12+
13+
#if ENABLE_APPLE_PRODUCT_TYPES
14+
extension Product {
15+
/// Creates an iOS application package product.
16+
///
17+
/// - Parameters:
18+
/// - name: The name of the application product.
19+
/// - targets: The targets to include in the application product; one and only one of them should be an executable target.
20+
/// - settings: The settings that define the core properties of the application.
21+
public static func iOSApplication(
22+
name: String,
23+
targets: [String],
24+
bundleIdentifier: String? = nil,
25+
teamIdentifier: String? = nil,
26+
displayVersion: String? = nil,
27+
bundleVersion: String? = nil,
28+
iconAssetName: String? = nil,
29+
accentColorAssetName: String? = nil,
30+
supportedDeviceFamilies: [ProductSetting.IOSAppInfo.DeviceFamily],
31+
supportedInterfaceOrientations: [ProductSetting.IOSAppInfo.InterfaceOrientation],
32+
capabilities: [ProductSetting.IOSAppInfo.Capability] = [],
33+
additionalInfoPlistContentFilePath: String? = nil
34+
) -> Product {
35+
return iOSApplication(
36+
name: name,
37+
targets: targets,
38+
bundleIdentifier: bundleIdentifier,
39+
teamIdentifier: teamIdentifier,
40+
displayVersion: displayVersion,
41+
bundleVersion: bundleVersion,
42+
appIcon: iconAssetName.map({ .asset($0) }),
43+
accentColor: accentColorAssetName.map({ .asset($0) }),
44+
supportedDeviceFamilies: supportedDeviceFamilies,
45+
supportedInterfaceOrientations: supportedInterfaceOrientations,
46+
capabilities: capabilities,
47+
additionalInfoPlistContentFilePath: additionalInfoPlistContentFilePath
48+
)
49+
}
50+
51+
/// Creates an iOS application package product.
52+
///
53+
/// - Parameters:
54+
/// - name: The name of the application product.
55+
/// - targets: The targets to include in the application product; one and only one of them should be an executable target.
56+
/// - settings: The settings that define the core properties of the application.
57+
@available(_PackageDescription, introduced: 5.6)
58+
public static func iOSApplication(
59+
name: String,
60+
targets: [String],
61+
bundleIdentifier: String? = nil,
62+
teamIdentifier: String? = nil,
63+
displayVersion: String? = nil,
64+
bundleVersion: String? = nil,
65+
appIcon: ProductSetting.IOSAppInfo.AppIcon? = nil,
66+
accentColor: ProductSetting.IOSAppInfo.AccentColor? = nil,
67+
supportedDeviceFamilies: [ProductSetting.IOSAppInfo.DeviceFamily],
68+
supportedInterfaceOrientations: [ProductSetting.IOSAppInfo.InterfaceOrientation],
69+
capabilities: [ProductSetting.IOSAppInfo.Capability] = [],
70+
appCategory: ProductSetting.IOSAppInfo.AppCategory? = nil,
71+
additionalInfoPlistContentFilePath: String? = nil
72+
) -> Product {
73+
return .executable(name: name, targets: targets, settings: [
74+
bundleIdentifier.map{ .bundleIdentifier($0) },
75+
teamIdentifier.map{ .teamIdentifier($0) },
76+
displayVersion.map{ .displayVersion($0) },
77+
bundleVersion.map{ .bundleVersion($0) },
78+
.iOSAppInfo(ProductSetting.IOSAppInfo(
79+
appIcon: appIcon,
80+
accentColor: accentColor,
81+
supportedDeviceFamilies: supportedDeviceFamilies,
82+
supportedInterfaceOrientations: supportedInterfaceOrientations,
83+
capabilities: capabilities,
84+
appCategory: appCategory,
85+
additionalInfoPlistContentFilePath: additionalInfoPlistContentFilePath
86+
))
87+
].compactMap{ $0 })
88+
}
89+
}
90+
#endif

Sources/PackageDescription/PackageDescriptionSerialization.swift

+126
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ enum Serialization {
263263
let name: String
264264
let targets: [String]
265265
let productType: ProductType
266+
267+
#if ENABLE_APPLE_PRODUCT_TYPES
268+
let settings: [ProductSetting]
269+
#endif
266270
}
267271

268272
// MARK: - trait serialization
@@ -301,3 +305,125 @@ enum Serialization {
301305
let cxxLanguageStandard: CXXLanguageStandard?
302306
}
303307
}
308+
309+
#if ENABLE_APPLE_PRODUCT_TYPES
310+
extension Serialization {
311+
enum ProductSetting: Codable {
312+
case bundleIdentifier(String)
313+
case teamIdentifier(String)
314+
case displayVersion(String)
315+
case bundleVersion(String)
316+
case iOSAppInfo(IOSAppInfo)
317+
318+
struct IOSAppInfo: Codable {
319+
var appIcon: AppIcon?
320+
var accentColor: AccentColor?
321+
var supportedDeviceFamilies: [DeviceFamily]
322+
var supportedInterfaceOrientations: [InterfaceOrientation]
323+
var capabilities: [Capability] = []
324+
var appCategory: AppCategory?
325+
var additionalInfoPlistContentFilePath: String?
326+
327+
enum AccentColor: Codable {
328+
struct PresetColor: Codable {
329+
var rawValue: String
330+
}
331+
332+
case presetColor(PresetColor)
333+
case asset(String)
334+
}
335+
336+
enum AppIcon: Codable {
337+
struct PlaceholderIcon: Codable {
338+
var rawValue: String
339+
}
340+
341+
case placeholder(icon: PlaceholderIcon)
342+
case asset(String)
343+
}
344+
345+
enum DeviceFamily: String, Codable {
346+
case phone
347+
case pad
348+
case mac
349+
}
350+
351+
struct DeviceFamilyCondition: Codable {
352+
var deviceFamilies: [DeviceFamily]
353+
}
354+
355+
enum InterfaceOrientation: Codable {
356+
case portrait(_ condition: DeviceFamilyCondition? = nil)
357+
case portraitUpsideDown(_ condition: DeviceFamilyCondition? = nil)
358+
case landscapeRight(_ condition: DeviceFamilyCondition? = nil)
359+
case landscapeLeft(_ condition: DeviceFamilyCondition? = nil)
360+
}
361+
362+
enum Capability: Codable {
363+
case appTransportSecurity(configuration: AppTransportSecurityConfiguration, _ condition: DeviceFamilyCondition? = nil)
364+
case bluetoothAlways(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
365+
case calendars(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
366+
case camera(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
367+
case contacts(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
368+
case faceID(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
369+
case fileAccess(_ location: FileAccessLocation, mode: FileAccessMode, _ condition: DeviceFamilyCondition? = nil)
370+
case incomingNetworkConnections(_ condition: DeviceFamilyCondition? = nil)
371+
case localNetwork(purposeString: String, bonjourServiceTypes: [String]? = nil, _ condition: DeviceFamilyCondition? = nil)
372+
case locationAlwaysAndWhenInUse(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
373+
case locationWhenInUse(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
374+
case mediaLibrary(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
375+
case microphone(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
376+
case motion(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
377+
case nearbyInteractionAllowOnce(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
378+
case outgoingNetworkConnections(_ condition: DeviceFamilyCondition? = nil)
379+
case photoLibrary(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
380+
case photoLibraryAdd(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
381+
case reminders(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
382+
case speechRecognition(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
383+
case userTracking(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
384+
}
385+
386+
struct AppTransportSecurityConfiguration: Codable {
387+
var allowsArbitraryLoadsInWebContent: Bool? = nil
388+
var allowsArbitraryLoadsForMedia: Bool? = nil
389+
var allowsLocalNetworking: Bool? = nil
390+
var exceptionDomains: [ExceptionDomain]? = nil
391+
var pinnedDomains: [PinnedDomain]? = nil
392+
393+
struct ExceptionDomain: Codable {
394+
var domainName: String
395+
var includesSubdomains: Bool? = nil
396+
var exceptionAllowsInsecureHTTPLoads: Bool? = nil
397+
var exceptionMinimumTLSVersion: String? = nil
398+
var exceptionRequiresForwardSecrecy: Bool? = nil
399+
var requiresCertificateTransparency: Bool? = nil
400+
}
401+
402+
struct PinnedDomain: Codable {
403+
var domainName: String
404+
var includesSubdomains : Bool? = nil
405+
var pinnedCAIdentities : [[String: String]]? = nil
406+
var pinnedLeafIdentities : [[String: String]]? = nil
407+
}
408+
}
409+
410+
enum FileAccessLocation: String, Codable {
411+
case userSelectedFiles
412+
case downloadsFolder
413+
case pictureFolder
414+
case musicFolder
415+
case moviesFolder
416+
}
417+
418+
enum FileAccessMode: String, Codable {
419+
case readOnly
420+
case readWrite
421+
}
422+
423+
struct AppCategory: Codable {
424+
var rawValue: String
425+
}
426+
}
427+
}
428+
}
429+
#endif

0 commit comments

Comments
 (0)