Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shipping xcframework with multiple dependency manager #1438

Closed
mnabulsi92 opened this issue Aug 25, 2023 · 10 comments
Closed

Shipping xcframework with multiple dependency manager #1438

mnabulsi92 opened this issue Aug 25, 2023 · 10 comments
Assignees
Labels
compilation issue SDK doesn't compile or gives warnings.

Comments

@mnabulsi92
Copy link

The issue

We have a CustomFramework where we support integration using cocoapods, carthage and SPM and we want to integrate Datadog v2.

In cocoapods and carthage we don't have any issues but in SPM we are getting this run time error:

Library not loaded: @rpath/DatadogRUM.framework/DatadogRUM

We add DataDog frameworks to the Frameworks and libraries with Do not embed option
Screenshot 2023-08-25 at 13 02 30

Our Packge.swift file

let package = Package(
    name: "CustomFramework",
    defaultLocalization: "en",
    platforms: [
        .iOS(.v11)
    ],
    products: [
        .library(
            name: "CustomFramework",
            targets: ["CustomFrameworkBundle"]
        ),
    ],
    dependencies: [
        .package(
            name: "Datadog",
            url: "https://github.com/Datadog/dd-sdk-ios.git",
            .upToNextMajor(from: "2.0.0")
        )
    ],
    targets: [
        .target(name: "CustomFrameworkBundle",
                dependencies: [
                    "CustomFramework",
                    .product(name: "DatadogCore", package: "Datadog"),
                    .product(name: "DatadogRUM", package: "Datadog")
                ]
        ),
        .binaryTarget(
            name: "CustomFrameworkBundle",
            path: "CustomFrameworkBundle.xcframework.zip"
        ),
    ]
)

Datadog SDK version:

2.1.1

Last working Datadog SDK version:

We didn't have SPM support before

Dependency Manager:

SPM

Xcode version:

Xcode 14.3.1

Swift version:

5.8.1

Deployment Target:

iOS 11, iPhone

@mnabulsi92 mnabulsi92 added the compilation issue SDK doesn't compile or gives warnings. label Aug 25, 2023
@ncreated ncreated self-assigned this Aug 25, 2023
@ncreated
Copy link
Member

Hey @mnabulsi92 👋. This issue is similar to #1402 and it looks you're experiencing the SPM limitations explained in #1402 (comment). We recommend using the workaround discovered by @akovalov (🍺) in there: #1402 (comment).

@mnabulsi92
Copy link
Author

Hi @ncreated , i tried the workaround in that commit but it didn't work i assume because there is no Framework generated when we use SPM and since we add it to the Frameworks and libraries it crashes because its not there.

@ncreated
Copy link
Member

@mnabulsi92 So, we must better understand the setup that leads to this error, so we can reproduce it our side to have a closer look. Could you please describe the minimal example of your configuration?

@akovalov
Copy link

@mnabulsi92 have you tried to add type: .dynamic into your .library(? Apple ref

@mnabulsi92
Copy link
Author

@mnabulsi92 So, we must better understand the setup that leads to this error, so we can reproduce it our side to have a closer look. Could you please describe the minimal example of your configuration?

We have our SDK where we link the DataDog frameworks as xcframework in Frameworks and libraries but we don't embed them when generating our xcframework, and we use xcodebuild command to generate the xcframework.
The package.swift file as provided above.

Not sure if this answers your question, If not can you please let me know which configuration you are referring to exactly.

@mnabulsi92
Copy link
Author

@mnabulsi92 have you tried to add type: .dynamic into your .library(? Apple ref

No i didn't, i will try it.

but i think this refers to how the . library should be delivered or how SPM should generate it but we ship the SDK as binary so it's already dynamic, i will try it anyway.

Thanks.

@mnabulsi92
Copy link
Author

Hi @ncreated, any updates? any more info required from my side ?

@ncreated
Copy link
Member

Hey @mnabulsi92 👋. Sorry for delay and thanks for describing the framework setup. I more wonder on when is the Library not loaded: @rpath/DatadogRUM.framework/DatadogRUM error emitted? Does it come from an example project that you test your framework in? If so, what are the XCFrameworks you integrate into this example project?

@mnabulsi92
Copy link
Author

Hi @ncreated, yes its from an example app that imports our framework using SPM and our framework depends on Datadog as it shows in the provided package.swift file.
So the Error gets emitted from our SDK because we expect that there will be Datadog xcframeworks.
Our SDK link the Framework but does not embed it so at run time we get this error.

@ncreated
Copy link
Member

@mnabulsi92 Sadly, it seems you're struggling SPM limitations and this is not something we can solve in our SDK. The problem occurs after integrating your CustomFramework framework to an example app, not when integrating our SDK into your package.

Please see this open proposal in SPM repo: swiftlang/swift-package-manager#4449 as it explains the limited constraints of dependencies in binary frameworks like yours. We also found this community thread where possible workarounds are mentioned: https://forums.swift.org/t/swiftpm-binary-target-with-sub-dependencies/40197. Unfortunately, there seems to be no good & first-class solution at this moment.

I'll close this thread for now as there isn't anything actionable for us. Feel free to start another one if there is anything we can do that could help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compilation issue SDK doesn't compile or gives warnings.
Projects
None yet
Development

No branches or pull requests

3 participants