passepartoutvpn / openssl-apple

A script for compiling OpenSSL for Apple Devices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot use framework in Swift

mcmurrym opened this issue · comments

commented

I'm able to build and generate the xcframework just fine, but when it comes to using it, both in my own project and the provided demo project, I can't import the framework in code. i.e. import openssl or import OpenSSL using xcode 12.2

Maybe some new entry in Xcode "Build settings" regarding xcframeworks specifically (search paths come to my mind)? To be honest I use this in ObjC code only.

To use it from Swift, you'll need to add a Modules/module.modulemap file inside each openssl.framework folder that tells Swift what the the module definition is. This one has worked for my needs, though I haven't tested whether it exposes the full API:

framework module openssl [system] {
    umbrella "."
    textual header "e_os2.h"
    textual header "opensslconf.h"
    textual header "opensslv.h"
    exclude header "asn1_mac.h"

    export *
}
commented

@keeshux was this implemented? I cannot figure out what I need to import in Swift or what header I need to include in my bridging header to make to make this work. The Demo project includes neither in its source code. I've tried adding the cocoapod to my project, installing via the SwiftPM, and copying the final xcframework to my project after checking out the project.

I also tried adding objective-c files to my project, but it fails on #include <OpenSSL/OpenSSL.h>. And I'm not sure what header to replace it with.

Any kind of guidance would be helpful.

In Obj-C, you may want to try @import OpenSSL;. For explicit headers, use #import over #include.

commented

With @import OpenSSL (and @import openssl) are still giving me module not found errors with the xcframework copied to my project and also with cl-openssl added via the SwiftPM.