My Swift app accesses the USB serial port via a C++ API built as a universal dylib. When the dylib is added as a framework via "Frameworks, Libraries, and Embedded Content", it works fine. When instead the dylib is included as a binary target within an xcframework inside a Package, I get an error indicating a permissions issue.
I’d like more details about that. Is this permissions error reported when you run the code? If so, what system call reports the error? And what error is it? EPERM?
macOS Apps are by default sandboxed and need a special USB entitlement to be able to access USB devices. Because you said that it works with a universal dylib but not as an XCFramework, you probably already have the right settings but it may be worth double checking. At least I run into this issue when I first tried to access a serial device: Always Getting failedToOpen Error · Issue #9 · yeokm1/SwiftSerial · GitHub
The screenshot that shows how to add the entitlement is quite old and the tab for it is now called "Signing & Capabilities". Everything else looks quite similar.
I also see that you have a test target BrainFlowTests. AFAIK, SwiftPM tests run in a sandbox too and I don't think you can change the entitlement for it. Therefore you will not be able to access any device from this test target.
Thanks David. I already tried your suggestion but it did not help. It did however prompt me to revisit my Xcode project and target settings, and to retry embedding the dylib directly as a framework instead of via the Package (I removed the Package from the project entirely.) Much to my chagrin I get the same error. So now the issue seems no longer related to the Package.
I have another project where the open() call is working via embedded framework. I am now comparing the project and target settings between that project and my non-working project, to see where I went wrong.
I scoured my project and target settings but could not find a setting that made any difference. So I made a copy of my working project and then, in the copy, replaced the embedded frameworks with the Package. The copy is working fine, hence it is definitely not a package issue.
My working project was created more than 1 year ago using an older 12.x version of Xcode. The non-working project I created a few days ago using the latest version of Xcode. Therefore I suspected it might be an issue with Info.plist being generated automatically in Xcode 13, so I tried copying the Info.plist from working to non-working and updating the appropriate build settings, but still no luck.
I will start from scratch, creating a new project using the App template for macOS. Any tips or suggestions would be most welcome.