Conditional dependency for target in SwiftPM

1k Views Asked by At

I have a custom swift package I am building that has as one of its dependencies a package (Bugfender) that is an xcframework and is iOS only (and Mac Catalyst). Understandably, when I try to compile this package in Xcode (12.5) I get an error that a mac library for that package cannot be found (all iOS specific code is wrapped in a #if os(iOS) block).

Based on this (https://github.com/apple/swift-evolution/blob/master/proposals/0273-swiftpm-conditional-target-dependencies.md) addition to the Swift package spec, I thought I could use a condition to exclude the dependency for mac, but when I try the following Swift.package file, I still get the same error when building for mac. Is this a bug or am I doing something wrong? It seems like it should work based on this post as well (Swift package manager: How best to indicate 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"]),
    ])



0

There are 0 best solutions below