passepartoutvpn / openssl-apple

A script for compiling OpenSSL for Apple Devices.
Apache License 2.0
139 stars 65 forks source link

Cannot use framework in Swift #29

Closed mcmurrym closed 2 years ago

mcmurrym commented 3 years ago

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

keeshux commented 3 years ago

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.

bjhomer commented 3 years ago

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 *
}
knightcode commented 2 years ago

@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.

keeshux commented 2 years ago

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

knightcode commented 2 years ago

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.