Binary Dependency fails on Archive

Hi,

I was in the process of switching over an existing framework to SwiftPM. It requires OpenCV as a binary dependency. Through incredible annoyance and plethora of crashes in xcframework and Xcode I managed to get OpenCV working in SwiftPM. It builds and runs correctly on device... fantastic.

But, as soon as I archive the project it fails due to missing OpenCV headers. Any ideas as to why? And to a fix? It works fine build on device, just not archiving.

1 Like

Are you able to share more information about the package(s) involved, e.g. their manifests? This thread on the SwiftPM slack could also be relevant: https://swiftpm.slack.com/archives/C14QU6CUU/p1601031366009400

So after a ton of trial and error I was able to get it sorted out, but this feels like a bug. The issue appears to be the headers are not correctly copied or the path is incorrect from the XCFramework during the archiving process. (Maybe xcframework cli tool is buggy?) Although Swift PM normally recognize the OpenCV headers from XCFramework, builds correctly, and runs correctly.

I had to manually copy the opencv headers for the target while retaining the correct directory structure and include them. But the exact same headers and structure exists inside XCFramework. So this feels like a big bug to me.

I included the working package.

I didn't take a look at the slack thread yet, but if I get time I will.

let package = Package(
name: "MyCVPackage",
products: [
    .library(
        name: "MyCVPackage",
        targets: ["MyCVPackage", "opencv2"]),
],
dependencies: [
], targets: [
    .binaryTarget(
        name: "opencv2",
        url: "opencv2.xcframework.zip",
        checksum: "someValue"
    ),
    .target(
        name: "MyCVPackage",
        dependencies: ["opencv2"],
        resources:[.copy("include/")],
        publicHeadersPath:"include2",
        cxxSettings:[
            .headerSearchPath("include/")
        ]
        ),
    
    .testTarget(
        name: "MyCVPackageTests",
        dependencies: ["MyCVPackage"]),
], cxxLanguageStandard: .cxx11

)

Going off on a rant here. So this actually doesn't work. Everything works up to submitting to the App Store.

The App Store refuses to accept the archive about some nonsense that opencv2 is not permitted because it contains a standalone library or executable. Yet the same framework works if it's embedded in a regular project.....

I've wasted way too much time trying to get binary targets to work in Swift PM. I've tried every iteration under the sun. Honestly, it feels like a poorly built feature that just doesn't work and is so hacky it would probably randomly break one day for no reason other than Apple's crappy App Store.

Does opencv2.xcframework contain static libraries? We do have a known issue about static libraries / frameworks being embedded in the app bundle incorrectly.

1 Like

Yes, OpenCV does allow building a dynamic library. Do you think that will resolve the issue.

Is there an open bug report on this issue? I'm having a (probably) similar issue where my static frameworks are getting thrown into my other target's install locations (QuickLook Plugin and Safari App Extension)

I don’t have access to the Slack. Could you post relevant context here on the forums?

Do you have any update on the status of this bug or where I can track it? Would appreciate it!

Terms of Service

Privacy Policy

Cookie Policy