3

我有一个Package.swift清单如下:

// 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")
    ]
)

包清单摘要:

  • 3个目标
  • 1 个目标取决于另一个目标
  • PackageName与 macOS 兼容,其他仅适用于 iOS

构建命令

long-package-name-ios-Package为 iOS构建(构建包中的所有目标):

swift build -Xswiftc "-sdk" -Xswiftc "$(xcrun --sdk iphonesimulator --show-sdk-path)" -Xswiftc "-target" -Xswiftc "arm64-apple-ios15.0-simulator"

[137/137] 构建完成!

现在尝试PackageName为 macOS 构建:

swift build -Xswiftc "-sdk" -Xswiftc "$(xcrun --sdk macosx --show-sdk-path)" --product "PackageName"

[1/1] 规划构建警告:“--product”不能与自动产品“PackageName”一起使用;改为构建默认目标

它继续为 macOS 平台构建默认目标long-package-name-ios-Package,这显然由于无法导入而失败,例如 UIKit 或任何其他仅限 iOS 的框架。

问题

如何指定仅为PackageNamemacOS 平台构建?我愿意创建 Xcode 包、方案和其他不同的配置,但最终目标应该是:

  1. long-package-name-ios-Package仅适用于 iOS 的集成(所有目标)
  2. PackageName为 macOS集成
4

0 回答 0