DeyaEldeen
DeyaEldeen

Reputation: 11857

Excluding SPM packages from building in specific targets

Say I have some debugging library, and I want it to not be included in the production versions of my iOS app, how can I achieve this with Swift Package Manager? so in short, I want it to be only part of development builds.

Upvotes: 2

Views: 1392

Answers (1)

cora
cora

Reputation: 2102

You can conditionally include a package in a target, reference.

// swift-tools-version:5.3

import PackageDescription

let package = Package(
    name: "BestPackage",
    dependencies: [
        .package(url: "https://github.com/pureswift/bluetooth", .branch("master")),
        .package(url: "https://github.com/pureswift/bluetoothlinux", .branch("master")),
    ],
    targets: [
        .target(
            name: "BestExecutable",
            dependencies: [
                .product(name: "Bluetooth", condition: .when(platforms: [.macOS])),
                .product(name: "BluetoothLinux", condition: .when(platforms: [.linux])),
                .target(name: "DebugHelpers", condition: .when(configuration: .debug)),
            ]
        ),
        .target(name: "DebugHelpers")
     ]
)

Upvotes: 0

Related Questions