SwiftPM 中目标的条件依赖

rob*_*mac 7 swift swiftpm

我正在构建一个自定义的 swift 包,它的依赖项之一是一个 xcframework 包(Bugfender),并且仅适用于 iOS(和 Mac Catalyst)。可以理解的是,当我尝试在 Xcode (12.5) 中编译此包时,我收到一条错误,指出无法找到该包的 mac 库(所有 iOS 特定代码都包含在 #if os(iOS) 块中)。

基于此(https://github.com/apple/swift-evolution/blob/master/proposals/0273-swiftpm-conditional-target-dependency.md)除了Swift包规范之外,我想我可以使用一个条件排除 mac 的依赖关系,但是当我尝试以下 Swift.package 文件时,在为 mac 构建时仍然遇到相同的错误。这是一个错误还是我做错了什么?看起来它也应该基于这篇文章工作(Swift package manager: How best to indicates platform dependent code?

// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "GTSApplicationLogging",
    platforms: [
        .iOS(.v12), .macOS(.v10_13),
    ],
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "GTSApplicationLogging",
            targets: ["GTSApplicationLogging"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        .package(name: "BugfenderPackage", url: "https://github.com/bugfender/BugfenderSDK-iOS", .exact("1.10.2")),
        .package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver.git", .exact("1.9.5")),
        .package(url: "https://github.com/marmelroy/Zip.git", .exact("2.1.1")),
        .package(path: "../GTSPureAppleExtensions"),
        .package(path: "../GTSApplicationError"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
        .target(
            name: "GTSApplicationLogging",
            dependencies: ["SwiftyBeaver", "GTSPureAppleExtensions", "GTSApplicationError", "Zip", .product(name: "BugfenderLibrary", package: "BugfenderPackage", condition: .when(platforms: [.iOS]))]),
        .testTarget(
            name: "GTSApplicationLoggingTests",
            dependencies: ["GTSApplicationLogging", "GTSApplicationError"]),
    ])



Run Code Online (Sandbox Code Playgroud)