OpenSSL fails to compile for swift framework

484 views Asked by At

In a sample app that I have created, have used the openssl lib using module map. Following is the structure of module.modulemap file.

framework module TestApp {
    umbrella header "TestApp.h"
    export *
    module * { export * }
    header "opensslv.h"
    header "x509.h"
    header "pkcs12.h"
    header "pem.h"
}

Apart from that, I have also added include & lib folders to my project. This approach works perfectly fine for the sample swift app. Source code compiles and the openssl apis are exposed to swift.

Now comes the actual question. When I am creating a swift framework and following the above process of creating module map & adding include & lib folder to the project structure.

I get an error on this line of "pkcs12.h".

  include <openssl/bio.h>

'openssl/bio.h' file not found'

I have added the Import paths, Header Search Paths in build settings.

As the OpenSSL is C based library, It does not compile for the swift framework. The bridging header is also not working for the swift framework.

Can someone help me here or understand the better way to include the OpenSSL library for swift framework?

https://drive.google.com/file/d/1B4NFbTQG0JjSkZgFx0yy1jYw-lRxX1Oa/view?usp=sharing

I have added the sample project link. In TODO section, I want to use the OpenSSL methods.

Note: I was able compile the openSSL lib using the below script.

sed -E -i '' 's/#[[:space:]]*include <openssl\/(.*).h>/#include \"\1\.h"/' 
$SCRIPT_DIR/../Libraries/openssl/include/openssl/*.h
1

There are 1 answers

0
gm_Suraj On BEST ANSWER

I fixed the compilation issue and was able to access the OpenSSL API's.

I had to make a few changes to the module map file.

//
//  module.modulemap
//  NiksWay
//
//  Created by Suraj Gaikwad on 14/03/22.
//

framework module NiksWay {
    umbrella header "NiksWay.h"
    
    export *
    
    module * { export * }
    
    explicit module OpenSSL {
        
        header "pkcs12.h"
        header "pem.h"
        header "opensslv.h"
        header "err.h"
        
        link "libcrypto"
        link "openssl"
        
        export *
    }
}