Non-Modular Headers of Openssl Library When Using Modulemap for Swift Framework

Non-modular headers of OpenSSL library when using modulemap for Swift framework

In the end I couldn't find any better solution than listing all necessary headers into module map and rewriting include macros of the SSL library files from <> syntax to just plain include. I used this little shell script to help me with that:

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

OpenSSL fails to compile for swift framework

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 *
}
}

Swift compiler error: non-modular header inside framework module

Is your header public?

Select the header file in the project explorer. Then in the section on the right in xcode, you'll notice there is a dropdown next to the target. Change that from "project" to "public". This worked for me.

public header

Wrapping an existing C library as a Framework

One unsatisfying solution is to switch to an XCFramework comprised of Libraries instead of Frameworks.

xcodebuild \
-create-xcframework \
-library <path/to/library> \
-header <path/to/headers> \
-output MyCool.xcframework

Then header search paths work correctly, but you lose the .modulemap and the nice framework structure that keeps everything together neatly per SDK build.



Related Topics



Leave a reply



Submit