swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.76k stars 1.35k forks source link

Distribute XCFramework with dependency via SPM - not possible without a wrapper #8058

Open LakshmiChidambaranathan opened 1 month ago

LakshmiChidambaranathan commented 1 month ago

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

Description

I have an XCFramework A, which has it's dependencies on XCFramework B and XCFramework C. Now I need to distribute this XCFramework A via SPM.

How to declare dependencies B and C for this XCFramework A, which is a binary target?

I need to distribute only Framework A through SPM, not every other dependent frameworks. How to do this? Is this possible?

let package = Package(
    name: "XCFrameworkAPackage",
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(name: "XCFrameworkAPackage", targets: ["XCFrameworkA"]),
    ],
    dependencies: [
        .package(url: "https://github.com/XYZ/XCFrameworkB.git", from: "1.0.0"),
        .package(url: "https://github.com/XYZ/XCFrameworkC.git", from: "1.0.0")
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
                .target(
            name: "XCFrameworkAPackage",
            dependencies: [
                .product(name: "XCFrameworkB", package: "XCFrameworkB"),
                .product(name: "XCFrameworkC", package: "XCFrameworkC"),
            ]),
        .binaryTarget(name: "XCFrameworkA", url: "https://maven.com/XCFrameworkA.zip", checksum: "9b4eb139697d5b54f5a8a41cbba4dc3317ee80f6f0a9f15564e4d85954ec4420"),
    ]
)

Currently using as such, it exposes, two modules XCFrameworkAPackage and XCFrameworkA, but I want to use only the XCFrameworkA. How to achieve this?

In simple words, My binary target has dependencies with other binary targets, how to achieve that using SPM?

Expected behavior

To distribute a binary framework, that has dependencies, I have to use a wrapper package, as suggested here.

Actual behavior

It would be nice to have declared the dependencies for the binary target. Or any other way I could try

Steps to reproduce

No response

Swift Package Manager version/commit hash

swift-tools-version: 5.9

Swift & OS version (output of swift --version ; uname -a)

swift --version : Target: x86_64-apple-macosx14.0 uname -a : Darwin lakshmi-12493 23.6.0 Darwin Kernel Version 23.6.0: Wed Jul 31 20:49:39 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_T6000 x86_64