将Modulemap用于Swift框架时OpenSSL库的非模块化标头 [英] Non-modular headers of OpenSSL library when using modulemap for Swift framework

查看:218
本文介绍了将Modulemap用于Swift框架时OpenSSL库的非模块化标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用XCode将OpenSSL库静态链接到我的Swift框架。在线上提到的大多数方法都不正确,因为它们建议使用导入路径( SWIFT_INCLUDE_PATHS )。结果,框架二进制文件被锁定到文件系统中的特定位置,并且二进制文件本身不可移植。虽然这还不是世界末日,但我仍然希望能够例如通过迦太基分发二进制文件,并且遵循上述方法不能启用二进制文件。

I'm trying to link statically OpenSSL library to my Swift framework, using XCode. Most approaches mentioned online are not correct, because they suggest using Import path (SWIFT_INCLUDE_PATHS). As a result, the framework binary is locked to a specific location in the file system and the binary itself is not portable. While this is not end of the world, I'd still like to be able to distribute the binary via Carthage for example and following above-mentioned approach doesn't enable that.

我尝试按照以下文章中介绍的方法,使用框架的伞形头文件创建自己的模块映射,并将OpenSSL库作为显式模块包括在内: https://badootech.badoo.com/bundling-c-library-in-swift-framework-3d9dae950774

I have attempted to create my own module map with an umbrella header file for the framework and including OpenSSL library as an explicit module, following approaches described in articles like these: https://badootech.badoo.com/bundling-c-library-in-swift-framework-3d9dae950774

这是我的modulemap文件,我将其插入 MODULEMAP_FILE 构建配置变量中。

This is my modulemap file, path of which I inserted into MODULEMAP_FILE build config variable.

framework module MyFramework {
    umbrella header "MyFramework.h"
    requires objc

    export *
    module * { export * }

    module COpenSSL [system] {
        header "shim.h"
        link "ssl"
        link "crypto"
        export *
    }
}

其中 shim.h 文件是如下所示的头文件:

where shim.h file is a header file that looks like this:

#ifndef __COPENSSL_SHIM_H__
#define __COPENSSL_SHIM_H__

#include <openssl/conf.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/md4.h>
#include <openssl/md5.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
#include <openssl/rand.h>
#include <openssl/ripemd.h>
#include <openssl/pkcs12.h>
#include <openssl/x509v3.h>

__attribute__((swift_name("SSL_set_tlsext_host_name(_:_:)")))
static inline int shim_SSL_set_tlsext_host_name(const SSL *s, const char *name) {
    return SSL_set_tlsext_host_name(s, name);
};

#endif

这里的问题是,我在尝试编译有关包含非模块化头文件的项目时会出错。

The problem here is, that I get errors when trying to compile the project about including non-modular headers.

我试图将所有头文件作为公共头文件包含到XCode项目中( conf.h evp.h 等)。但是问题仍然存在,大概是因为它无法使用标头包含 #include< openssl / conf.h> 的语法。将包含更改为 #include conf.h 等是可行的,但随后将相同样式的标头包含与 conf.h 以及来自Open SSL库的所有其他头文件,因此并没有真正的帮助。

I've attempted to include all the header files to the XCode project as public header files (conf.h, evp.h, etc, all of them). But the problem still persists, presumably because it's unable to work with the syntax of the header inclusion #include <openssl/conf.h>. Changing inclusions to #include "conf.h" etc. works, but then the same style of header inclusion is used with conf.h and all the other header files that come from the Open SSL library, so that doesn't really help.

我真的不想修改OpenSSL库中的每个头文件只是为了使其工作,似乎必须有一些更简单的方法。

I really don't want to modify every single header file from the OpenSSL library just to make it work, it seems like there must be some easier way out of this.

有没有办法不必将这些标头包含到XCode项目中,以便它们仍可以使用 #include< openssl / conf.h>

Is there any way to not have to include these headers to the XCode project so that they still work with the original syntax of #include <openssl/conf.h>?

我尝试将 HEADER_SEARCH_PATHS 设置为到每个标头的相对路径的路径是 openssl / conf.h 等,但是它根本没有帮助。

I've tried setting HEADER_SEARCH_PATHS to a path from which the relative path to each header is openssl/conf.h etc., but that it didn't help at all.

谢谢。

推荐答案

最后,我找不到比将所有必要的标头都列出来更好的解决方案了模块映射和重写SSL库文件的include宏(从<> 语法改为普通包含)。我使用了这个小shell脚本来帮助我解决这个问题:

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

这篇关于将Modulemap用于Swift框架时OpenSSL库的非模块化标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆