首页 > 解决方案 > SwiftPM 中目标的条件依赖

问题描述

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

基于这个(https://github.com/apple/swift-evolution/blob/master/proposals/0273-swiftpm-conditional-target-dependencies.md)除了Swift包规范,我想我可以使用一个条件排除对 mac 的依赖,但是当我尝试以下 Swift.package 文件时,在为 mac 构建时仍然遇到相同的错误。这是一个错误还是我做错了什么?似乎它也应该基于这篇文章工作(Swift包管理器:如何最好地指示平台相关代码?

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



标签: swiftswiftpm

解决方案


推荐阅读