I have a Package.swift
manifest as follows:
// swift-tools-version:5.4
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "long-package-name-ios",
defaultLocalization: "en",
platforms: [
.iOS(.v14),
.macOS(.v10_15)
],
products: [
.library(
name: "PackageName",
targets: ["PackageName"]),
.library(
name: "PackageNameImproved",
targets: ["PackageNameImproved"]),
.library(
name: "PackageNameUI",
targets: ["PackageNameUI"]),
],
dependencies: [
.package(
name: "PackageLib",
url: "ssh://apple.com/packagelib.git",
.upToNextMinor(from: "1.2.3")
)
],
targets: [
.target(
name: "PackageName",
dependencies: [
.product(name: "PackageLib", package: "PackageLib"),
],
path: "PackageName"),
.target(
name: "PackageName",
dependencies: [
"PackageName",
.product(name: "PackageLib", package: "PackageLib"),
],
path: "PackageNameImproved"),
.target(
name: "PackageNameUI",
dependencies: [
"PackageNameImproved",
],
path: "PackageNameUI")
]
)
Package Manifest summary:
- 3 targets
- 1 target depends on the other one
- Only
PackageName
is compatible with macOS, the other ones are iOS-only
Build commands
Building long-package-name-ios-Package
(builds all targets within the package) for iOS:
swift build -Xswiftc "-sdk" -Xswiftc "$(xcrun --sdk iphonesimulator --show-sdk-path)" -Xswiftc "-target" -Xswiftc "arm64-apple-ios15.0-simulator"
[137/137] Build complete!
Now trying to build just the PackageName
for macOS:
swift build -Xswiftc "-sdk" -Xswiftc "$(xcrun --sdk macosx --show-sdk-path)" --product "PackageName"
[1/1] Planning buildwarning: '--product' cannot be used with the automatic product 'PackageName'; building the default target instead
And it proceeds with building the default target long-package-name-ios-Package
for the macOS platform which obviously fails due to inability to import, e.g. UIKit or any other iOS-only framework.
Question
How can I specify to build only PackageName
for the macOS platform? I'm open to creating an Xcode Package, Schemes and other different configurations, but the end goals should be to:
- Integrate
long-package-name-ios-Package
(all targets) for iOS only - Integrate
PackageName
for macOS