Skip to content

Add infrastructure for updates to new Swift Build build system. #8338

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 2 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 34 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ if ProcessInfo.processInfo.environment["SWIFTCI_INSTALL_RPATH_OS"] == "android"
automatic linking type with `-auto` suffix appended to product's name.
*/
let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]
let swiftDriverDep: [Target.Dependency]

swiftDriverDep = [.product(name: "SwiftDriver", package: "swift-driver")]

let package = Package(
name: "SwiftPM",
platforms: [
.macOS(.v13),
.iOS(.v16),
.macCatalyst(.v17),
],
products:
autoProducts.flatMap {
Expand Down Expand Up @@ -119,6 +123,12 @@ let package = Package(
type: .dynamic,
targets: ["PackageDescription", "CompilerPluginSupport"]
),
.library(
name: "AppleProductTypes",
type: .dynamic,
targets: ["AppleProductTypes"]
),

.library(
name: "PackagePlugin",
type: .dynamic,
Expand Down Expand Up @@ -153,6 +163,21 @@ let package = Package(
linkerSettings: packageLibraryLinkSettings
),

// The `AppleProductTypes` target provides additional product types
// to `Package.swift` manifests. Here we build a debug version of the
// library; the bootstrap scripts build the deployable version.
.target(
name: "AppleProductTypes",
// Note: We use `-module-link-name` so clients link against the
// AppleProductTypes library when they import it without further
// messing with the manifest loader.
dependencies: ["PackageDescription"],
swiftSettings: [
.unsafeFlags(["-package-description-version", "999.0"]),
.unsafeFlags(["-enable-library-evolution"], .when(platforms: [.macOS])),
.unsafeFlags(["-Xfrontend", "-module-link-name", "-Xfrontend", "AppleProductTypes"])
]),

// The `PackagePlugin` target provides the API that is available to
// plugin scripts. Here we build a debug version of the library; the
// bootstrap scripts build the deployable version.
Expand Down Expand Up @@ -418,10 +443,9 @@ let package = Package(
"PackageGraph",
"SPMBuildCore",
"SPMLLBuild",
.product(name: "SwiftDriver", package: "swift-driver"),
.product(name: "OrderedCollections", package: "swift-collections"),
"DriverSupport",
],
] + swiftDriverDep,
exclude: ["CMakeLists.txt"],
swiftSettings: [
.unsafeFlags(["-static"]),
Expand All @@ -432,8 +456,7 @@ let package = Package(
dependencies: [
"Basics",
"PackageModel",
.product(name: "SwiftDriver", package: "swift-driver"),
],
] + swiftDriverDep,
exclude: ["CMakeLists.txt"],
swiftSettings: [
.unsafeFlags(["-static"]),
Expand Down Expand Up @@ -1022,6 +1045,13 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
]
}

/// 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.
if ProcessInfo.processInfo.environment["ENABLE_APPLE_PRODUCT_TYPES"] == "1" {
for target in package.targets.filter({ $0.type == .regular || $0.type == .test }) {
target.swiftSettings = (target.swiftSettings ?? []) + [ .define("ENABLE_APPLE_PRODUCT_TYPES") ]
}
}

if ProcessInfo.processInfo.environment["SWIFTPM_SWBUILD_FRAMEWORK"] == nil &&
ProcessInfo.processInfo.environment["SWIFTPM_NO_SWBUILD_DEPENDENCY"] == nil {

Expand Down
90 changes: 90 additions & 0 deletions Sources/AppleProductTypes/Product.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

@_spi(PackageProductSettings) import PackageDescription

#if ENABLE_APPLE_PRODUCT_TYPES
extension Product {
/// Creates an iOS application package product.
///
/// - Parameters:
/// - name: The name of the application product.
/// - targets: The targets to include in the application product; one and only one of them should be an executable target.
/// - settings: The settings that define the core properties of the application.
public static func iOSApplication(
name: String,
targets: [String],
bundleIdentifier: String? = nil,
teamIdentifier: String? = nil,
displayVersion: String? = nil,
bundleVersion: String? = nil,
iconAssetName: String? = nil,
accentColorAssetName: String? = nil,
supportedDeviceFamilies: [ProductSetting.IOSAppInfo.DeviceFamily],
supportedInterfaceOrientations: [ProductSetting.IOSAppInfo.InterfaceOrientation],
capabilities: [ProductSetting.IOSAppInfo.Capability] = [],
additionalInfoPlistContentFilePath: String? = nil
) -> Product {
return iOSApplication(
name: name,
targets: targets,
bundleIdentifier: bundleIdentifier,
teamIdentifier: teamIdentifier,
displayVersion: displayVersion,
bundleVersion: bundleVersion,
appIcon: iconAssetName.map({ .asset($0) }),
accentColor: accentColorAssetName.map({ .asset($0) }),
supportedDeviceFamilies: supportedDeviceFamilies,
supportedInterfaceOrientations: supportedInterfaceOrientations,
capabilities: capabilities,
additionalInfoPlistContentFilePath: additionalInfoPlistContentFilePath
)
}

/// Creates an iOS application package product.
///
/// - Parameters:
/// - name: The name of the application product.
/// - targets: The targets to include in the application product; one and only one of them should be an executable target.
/// - settings: The settings that define the core properties of the application.
@available(_PackageDescription, introduced: 5.6)
public static func iOSApplication(
name: String,
targets: [String],
bundleIdentifier: String? = nil,
teamIdentifier: String? = nil,
displayVersion: String? = nil,
bundleVersion: String? = nil,
appIcon: ProductSetting.IOSAppInfo.AppIcon? = nil,
accentColor: ProductSetting.IOSAppInfo.AccentColor? = nil,
supportedDeviceFamilies: [ProductSetting.IOSAppInfo.DeviceFamily],
supportedInterfaceOrientations: [ProductSetting.IOSAppInfo.InterfaceOrientation],
capabilities: [ProductSetting.IOSAppInfo.Capability] = [],
appCategory: ProductSetting.IOSAppInfo.AppCategory? = nil,
additionalInfoPlistContentFilePath: String? = nil
) -> Product {
return .executable(name: name, targets: targets, settings: [
bundleIdentifier.map{ .bundleIdentifier($0) },
teamIdentifier.map{ .teamIdentifier($0) },
displayVersion.map{ .displayVersion($0) },
bundleVersion.map{ .bundleVersion($0) },
.iOSAppInfo(ProductSetting.IOSAppInfo(
appIcon: appIcon,
accentColor: accentColor,
supportedDeviceFamilies: supportedDeviceFamilies,
supportedInterfaceOrientations: supportedInterfaceOrientations,
capabilities: capabilities,
appCategory: appCategory,
additionalInfoPlistContentFilePath: additionalInfoPlistContentFilePath
))
].compactMap{ $0 })
}
}
#endif
126 changes: 126 additions & 0 deletions Sources/PackageDescription/PackageDescriptionSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ enum Serialization {
let name: String
let targets: [String]
let productType: ProductType

#if ENABLE_APPLE_PRODUCT_TYPES
let settings: [ProductSetting]
#endif
}

// MARK: - trait serialization
Expand Down Expand Up @@ -301,3 +305,125 @@ enum Serialization {
let cxxLanguageStandard: CXXLanguageStandard?
}
}

#if ENABLE_APPLE_PRODUCT_TYPES
extension Serialization {
enum ProductSetting: Codable {
case bundleIdentifier(String)
case teamIdentifier(String)
case displayVersion(String)
case bundleVersion(String)
case iOSAppInfo(IOSAppInfo)

struct IOSAppInfo: Codable {
var appIcon: AppIcon?
var accentColor: AccentColor?
var supportedDeviceFamilies: [DeviceFamily]
var supportedInterfaceOrientations: [InterfaceOrientation]
var capabilities: [Capability] = []
var appCategory: AppCategory?
var additionalInfoPlistContentFilePath: String?

enum AccentColor: Codable {
struct PresetColor: Codable {
var rawValue: String
}

case presetColor(PresetColor)
case asset(String)
}

enum AppIcon: Codable {
struct PlaceholderIcon: Codable {
var rawValue: String
}

case placeholder(icon: PlaceholderIcon)
case asset(String)
}

enum DeviceFamily: String, Codable {
case phone
case pad
case mac
}

struct DeviceFamilyCondition: Codable {
var deviceFamilies: [DeviceFamily]
}

enum InterfaceOrientation: Codable {
case portrait(_ condition: DeviceFamilyCondition? = nil)
case portraitUpsideDown(_ condition: DeviceFamilyCondition? = nil)
case landscapeRight(_ condition: DeviceFamilyCondition? = nil)
case landscapeLeft(_ condition: DeviceFamilyCondition? = nil)
}

enum Capability: Codable {
case appTransportSecurity(configuration: AppTransportSecurityConfiguration, _ condition: DeviceFamilyCondition? = nil)
case bluetoothAlways(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case calendars(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case camera(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case contacts(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case faceID(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case fileAccess(_ location: FileAccessLocation, mode: FileAccessMode, _ condition: DeviceFamilyCondition? = nil)
case incomingNetworkConnections(_ condition: DeviceFamilyCondition? = nil)
case localNetwork(purposeString: String, bonjourServiceTypes: [String]? = nil, _ condition: DeviceFamilyCondition? = nil)
case locationAlwaysAndWhenInUse(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case locationWhenInUse(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case mediaLibrary(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case microphone(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case motion(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case nearbyInteractionAllowOnce(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case outgoingNetworkConnections(_ condition: DeviceFamilyCondition? = nil)
case photoLibrary(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case photoLibraryAdd(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case reminders(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case speechRecognition(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
case userTracking(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
}

struct AppTransportSecurityConfiguration: Codable {
var allowsArbitraryLoadsInWebContent: Bool? = nil
var allowsArbitraryLoadsForMedia: Bool? = nil
var allowsLocalNetworking: Bool? = nil
var exceptionDomains: [ExceptionDomain]? = nil
var pinnedDomains: [PinnedDomain]? = nil

struct ExceptionDomain: Codable {
var domainName: String
var includesSubdomains: Bool? = nil
var exceptionAllowsInsecureHTTPLoads: Bool? = nil
var exceptionMinimumTLSVersion: String? = nil
var exceptionRequiresForwardSecrecy: Bool? = nil
var requiresCertificateTransparency: Bool? = nil
}

struct PinnedDomain: Codable {
var domainName: String
var includesSubdomains : Bool? = nil
var pinnedCAIdentities : [[String: String]]? = nil
var pinnedLeafIdentities : [[String: String]]? = nil
}
}

enum FileAccessLocation: String, Codable {
case userSelectedFiles
case downloadsFolder
case pictureFolder
case musicFolder
case moviesFolder
}

enum FileAccessMode: String, Codable {
case readOnly
case readWrite
}

struct AppCategory: Codable {
var rawValue: String
}
}
}
}
#endif
Loading