# SwiftPM support for binary packages which depends on another open source package

**URL:** <https://forums.swift.org/t/swiftpm-support-for-binary-packages-which-depends-on-another-open-source-package/57482>\
**Category:** Package Manager\
**Tags:** packagemanager, binary-framework\
**Created:** [May 20, 2022, 7:23pm UTC](https://forums.swift.org/t/swiftpm-support-for-binary-packages-which-depends-on-another-open-source-package/57482 "2022-05-20T19:23:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![raosanat](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/raosanat/32/23391_2.png) [@raosanat](https://forums.swift.org/u/raosanat)\
**Post date:** [May 20, 2022, 7:23pm UTC](https://forums.swift.org/t/swiftpm-support-for-binary-packages-which-depends-on-another-open-source-package/57482/1 "2022-05-20T19:23:55Z")

</div>

Hi,

We are trying to distribute our binary framework with Swift PM. Swift PM does support distributing binary packages but our scenario is a bit different.

We have 3 different packages

1. Package A =\> Swift based open source project
2. Package B =\> Another Swift based open source project
3. Package C =\> Closed source project distributed as a binary written in ObjC

Package C and Package A both depend on Package B.

I tried different posts here before posting a new one  
[SwiftPM - Binary target with sub-dependencies - Using Swift - Swift Forums](https://forums.swift.org/t/swiftpm-binary-target-with-sub-dependencies/40197)

But in my case the problem is the dependency is on an open source project which my binary relies on Swift PM compiling it.  
When Swift PM builds the open source Package B it does not install the bridging header file which the binary framework (written in ObjC) depends on.

It could be because of this in Swift PM source code here

> ```
> // We currently deliberately do not support Swift ObjC interface headers.
> settings[.SWIFT_INSTALL_OBJC_HEADER] = "NO"
> 
> ```

[swift-package-manager/PIFBuilder.swift at main · apple/swift-package-manager (github.com)](https://github.com/apple/swift-package-manager/blob/main/Sources/XCBuildSupport/PIFBuilder.swift)

ObjC header is emitted because this is enabled by SwiftPm `-emit-objc-header` and `-emit-objc-header-path` is enabled but not installing it in the correct place ?

This is what my current Package.swift looks like

```swift
// swift-tools-version:5.3
import PackageDescription

let package = Package(
    name: "PackageC",
    platforms: [
        .macOS(.v11), .iOS(.v12)
    ],
    products: [
        .library(name: "PackageC", targets: ["PackageCWrapper"])
    ],
    dependencies: [
            .package(name: "PackageB", url: "https://github.com/SwiftPM-PackageB.git", from: "1.0.2")
    ],
    targets: [
        .binaryTarget(
            name: "PackageC",
            url: "https://PackageC-2.2.0.zip",
            checksum: "3dfc0b9e1ae79e1d8df622f39b1c85db8998518d2c02eb1fe6b9ae58333c6de9"
        ),
        .target(
            name: "PackageCWrapper",
            dependencies: [
                .target(name: "PackageC"),
                .product(name: "PackageB", package: "PackageB")
            ],
            path: "PackageCWrapper"
        )
    ],
    swiftLanguageVersions: [.v5]
)

```

I am assuming Swift PM does not support this scenario yet ?

---

<div class="post-metadata">

**Author:** ![icanzilb](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/icanzilb/32/20473_2.png) [@icanzilb](https://forums.swift.org/u/icanzilb)\
**Post date:** [May 22, 2022, 7:57am UTC](https://forums.swift.org/t/swiftpm-support-for-binary-packages-which-depends-on-another-open-source-package/57482/2 "2022-05-22T07:57:41Z")

</div>

xcframework doesn't support source dependencies, in that sense when you have a binaryTarget — it cannot have other dependencies in source.

The only thing that comes to mind is to bundle your source dependency with your own source code and make the xcframework out of both (e.g. basically include your dependency with your own source). But, I can't say I've tried that myself — in general using binary targets with SwiftPM seems in a pre-release state to me.

---

<div class="post-metadata">

**Author:** ![raosanat](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/raosanat/32/23391_2.png) [@raosanat](https://forums.swift.org/u/raosanat)\
**Post date:** [June 16, 2022, 9:44pm UTC](https://forums.swift.org/t/swiftpm-support-for-binary-packages-which-depends-on-another-open-source-package/57482/4 "2022-06-16T21:44:36Z")

</div>

I dont think having the dependency inside xcframework is a good idea. Because that kind of goes down another rabit hole 🙂 Problem happens when an object from the open source code B passed down to Package C which might have another version of Package A bundled inside Package C.

---

<div class="post-metadata">

**Author:** ![paulb777](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/paulb777/32/7986_2.png) [@paulb777](https://forums.swift.org/u/paulb777)\
**Post date:** [June 16, 2022, 9:58pm UTC](https://forums.swift.org/t/swiftpm-support-for-binary-packages-which-depends-on-another-open-source-package/57482/5 "2022-06-16T21:58:17Z")

</div>

We work around the `binaryTarget` dependency limitation by wrapping the `binaryTarget` in a dedicated "Wrapper" target that provides the dependencies. See an example [here](https://github.com/firebase/firebase-ios-sdk/blob/master/Package.swift#L323).

---

<div class="post-metadata">

**Author:** ![raosanat](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/raosanat/32/23391_2.png) [@raosanat](https://forums.swift.org/u/raosanat)\
**Post date:** [June 16, 2022, 10:16pm UTC](https://forums.swift.org/t/swiftpm-support-for-binary-packages-which-depends-on-another-open-source-package/57482/6 "2022-06-16T22:16:24Z")

</div>

> [@paulb777](#):
>
> example

I did look at that example, but it looks like in your case you do not depend on a Swift open source project where you rely on SwiftPM to compile the source code ?

---

<div class="post-metadata">

**Author:** ![sagar-d](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sagar-d/32/35169_2.png) [@sagar-d](https://forums.swift.org/u/sagar-d)\
**Post date:** [May 2, 2024, 12:11pm UTC](https://forums.swift.org/t/swiftpm-support-for-binary-packages-which-depends-on-another-open-source-package/57482/7 "2024-05-02T12:11:50Z")

</div>

Hi @raosanat ,  
I have the exact issue - I am distributing a binary framework that depends on an open-source framework. I have tried the wrapper approach as mentioned [here](https://github.com/firebase/firebase-ios-sdk/blob/master/Package.swift#L323):  
but when the client app integrates via SPM, the app crashes at runtime with `Library not loaded: @rpath/A.framework/A` where A=The open source framework. Did you have any luck solving this?

EDIT: I am facing the exact issue mentioned here: [swift package manager - Can I define my binary framework which has open source dependencies without specifying the 'type' parameter in each of my framework's dependencies? - Stack Overflow](https://stackoverflow.com/questions/77274207/can-i-define-my-binary-framework-which-has-open-source-dependencies-without-spec)

---

<div class="post-metadata">

**Author:** ![raosanat](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/raosanat/32/23391_2.png) [@raosanat](https://forums.swift.org/u/raosanat)\
**Post date:** [May 2, 2024, 5:22pm UTC](https://forums.swift.org/t/swiftpm-support-for-binary-packages-which-depends-on-another-open-source-package/57482/8 "2024-05-02T17:22:52Z")

</div>

Hi @sagar-d ,  
No we still do not support SwiftPM for our binary package yet. We are working on re-writing our package to Swift.
