问题标签 [module-map]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
992 浏览

ios - 模块映射文件中是否需要“链接框架”行?

一些框架文件附带一个module.modulemap包含“链接框架”行的文件。例如,这是对讲机module.modulemap文件的当前内容:

我想找出为什么这些link framework行是必要的,所以我尝试在 Xcode 10.2 上为框架目标创建一个新项目,但无论我做什么,似乎该module.modulemap文件都不会被触及(这是可以理解的,它似乎这个文件是要手动修改的)。

我想知道的是,为什么这首先是必要的?责备信息+相应的发行说明似乎表明添加了所述行以解决动态框架和重复符号的问题,但仅此而已。

0 投票
1 回答
131 浏览

swift - 切换到 macOS Catalina 后 Modulemap 无法编译 - tcp_var.h

我是一个跟踪网络速度的小工具的开发者。该代码位于一个使用模块映射的小型框架中,因此我可以在 Swift 中使用 C 代码。

这是我的(旧)模块图:

切换到 macOS Catalina 后,找不到 /usr/include/ 文件夹,所以我不得不更改它们:

我已经做了一些更改,因为添加完整路径后,模块映射不再编译。我收到以下错误:

Declaration of 'tcp_seq' must be imported from module 'Darwin.POSIX.netinet.tcp' before it is required

完整版: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/netinet/tcp_var.h:120:2: Declaration of 'tcp_seq' must be imported from module 'Darwin.POSIX.netinet.tcp' before it is required

我不明白这一点,因为定义结构的标头 tcp.h 是在 tcp_var.h 标头之前导入的。

我怎样才能解决这个问题?

0 投票
0 回答
45 浏览

ios - 将 ac 库封装在一个用于 iOS 开发的 swift 框架中

我在 Linux 上用 clang 交叉编译了 iOS 的 c 库。现在我想为 Swift 项目创建一个可重用的框架。我拥有的是 dylib 和 C-Header。但我不确定如何从这里开始。我发现的大多数教程都已经过时了。我已经阅读了有关桥接头和模块映射的信息。后者似乎是当今要走的路。如果有人能从那里指出我正确的方向,我将不胜感激。

0 投票
0 回答
32 浏览

objective-c - Swift modulemap 树结构解析

我想为 Swift iOS 框架创建一个模块映射。它将是 ac 库的包装器。问题是 c 库包含另一个目录中的文件。例如“lib.h”有以下一行#include "directory/function.h"。但是当然找不到。我该如何解决?名字是虚构的,但问题是真实的。我会很感激任何答案,谢谢。

示例结构

0 投票
0 回答
264 浏览

swift - 如何将 cassandra c++ 驱动程序包装在 swift 模块中

我正在尝试针对 cassandra c++ 驱动程序编写一个服务器端 swift 应用程序(据我所知,没有 swift 本机支持)

我能够在我的 Mac 上本地安装 cassandra c++,如下所示:

已验证

也 :

我使用太多教程创建了一个快速包。

主要是:

https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#requiring-system-libraries

https://medium.com/shopify-mobile/wrapping-ac-library-in-swift-part-1-6dd240070cef

但似乎每个线程的说明都是错误的?

https://forums.swift.org/t/system-library-targets-package-has-unsupported-layout-modulemap/16614/6

目前我的结构如下所示:

内容是:

我有一个 2 测试项目。第一个测试项目是一个使用SPM集成支持并添加 git repo 参考的 mac XCode 应用程序

另一个项目是引用 SPM 包的 SPM 生成的项目

两者都不能正常工作。

我已经玩了几个小时了。

我希望它可以在 XCode for dev 中本地工作,并且可以移植(假设通过spm)在 swift docker 容器中运行。

0 投票
0 回答
134 浏览

ios - 在混合的 Swift Cocoapod 库中隐藏 Objective C

我正在开发一个 Swift Cocoapod 库,它实际上是一些 Objective C 代码的包装器。我的目标是只公开库的 Swift 部分,同时使 Objective C 尽可能私有。然而,由于 Swift 部分是 Objective C 代码的包装器,它需要访问它,尽管只是在内部。

我已经搜索并尝试了各种方法,但它们都没有奏效。


首先,我尝试通过使用模块映射文件来解决它。这个想法是创建一个 Swift 模块,称为MyLibrary包含所有 Swift 代码的东西,而 Objective C 代码将在MyLibrary.Private模块上(我知道模块仍然可以访问,但这种分离对我来说已经足够了)。模块映射看起来像:

MyLibrary.podspec并在文件中添加以下行

但是,通过使用这种方法,即使我只导入MyLibrary模块仍然可以访问所有的 Objective C 类,而不必导入MyLibrary.Private模块来这样做。


我尝试的第二种方法是使用private.modulemap文件。所以我最终会得到两个不同的模块映射文件:

MyLibrary.podspec然后我会在文件中添加以下行

但是,我得到一个失败的构建,说明它找不到MyLibrary.Private模块。


在这些方法中我做错了什么吗?或者有没有其他方法可以让我的库的 Swift 类私下访问 Objective C 类而不暴露那些,至少明确地,需要*.Private为它导入特定的模块?

0 投票
1 回答
150 浏览

ios - 如何在 iOS 框架的模块映射中提供相对标题路径

我正在尝试将 AdswizzSDK 嵌入到我的 swift 框架中。

当我给出绝对路径时,modulemap 标头起作用。

当我尝试给出相对路径时,它会抛出找不到错误头文件。

//这行得通

这不起作用

有没有办法将 AdswizzSDK 嵌入到我的自定义框架中?

0 投票
1 回答
415 浏览

objective-c - Objective-C and Swift interoperability inside framework with module mapping

Context

Years ago my company built an Objective-C framework that uses a C library and now we're trying to convert it to Swift. Since we need to use this C++ library, instead of completely eliminating objective-c code from the base we need to maintain the interoperability between these two languages. The key thing is that we need to do it in a way that not all interfaces are available to the app using the framework - that's where my problem relies on.

Attempts

First thing I searched was about how to use a C++ library with Swift, from all that I searched we needed to create a bridge between C++ and Swift using Objective C. So I started to focus on trying to create the interoperability between swift and objective c, whereas the C++ library comes naturally from the existing connection between C++ and Objective-C.

After a thousand of google searches and safari tabs, I discovered that inside an app all we needed to do is create a bridging header and we're good to go, not exactly easy nor difficult but kinda toilsome, but inside frameworks we don't have bridging headers, the only way this can achieved are ModuleMaps, these guys act like bridging headers encapsulating ObjC frameworks inside modules.

So I tried this and worked! Hurray!

But the problem is: in order to make this work I needed to make my headers public (and my new swift classes public as well). So more searching came along and I found out that are Private module maps. I tried to recreate one from tutorials like this:

but the compiler wasn't regarding the Private keyword at the modules' name ending, and I was being able to access it from outside the framework. Setting a name for it wasn't working either (e.g. MyDeprecatedObjCFrameworkPrivate or MyDeprecatedObjCFramework_Private or MyDeprecatedObjCFramework-Private and according to clang documentation the current pattern is _Private).

Creating one file apart and setting it as the Private Module Map in the build settings didn't work for me either, in this case there were two attempts, first one was like this:

In this case, the module couldn't be accessed by anyone, even internally by the framework. In a nutshell it wasn't being copied to the outputted framework inside Products Xcode folder. Adding the keyword framework before module resulted in include of non-modular header inside framework module.

I also found out that these clang things weren't stable enough and could break between major versions. From apple itself it doesn't seem to be a viable workaround and the only solution for this guy was to create a lint to prevent outer apps to import private headers/swift classes, which seems to me kinda of messy.

Final question

Is it possible to create interoperability between objective-c and swift inside a framework? Is this viable? Would it be better to recreate the entire framework from ground up? Or it's better to split it in other swift frameworks?

0 投票
0 回答
424 浏览

ios - Xcode 更改动态框架 Product Module Name

0 投票
0 回答
91 浏览

swift - 通过 Swift Framework Wrapping C Library 中的 C 标头

我正在从纯 C 源代码在 Xcode 中构建一个静态库。Viamodule.modulemap是一个我可以在 Swift 和 Objective-C 中使用的模块,包括一个关键的头文件enum.h。它看起来像这样:

我有一个用 Swift 编写的框架,它包装了 C 库。在框架内,我可以enum.h很好地使用符号。但是,我希望我的框架的用户也可以在 Swift 中访问来自enum.h.

如何在框架内处理,让框架用户不必enum.h单独导入文件?也就是说,完成后import MyFramework,我该如何enum.h以“正确”的方式公开?

现在我有这个复杂的过程。在我的框架中,我添加了一个如下所示的框架标头:

此时,它会导致有关导入非模块化标头的错误(即使此文件是 CLibMyLibrary 模块的一部分,如上所述)。所以我添加了一个额外的“假”模块,它只模块化这个文件,就像这样:

现在在一个应用程序中,我可以简单地Swift 识别import MyFramework所有enum.h符号。好的。这正是我所期望的。

不过,假模块困扰着我。它可能很脆弱,而且可能不是预期的使用方式。

除了在enum.h文件中包装数百行定义之外,是否有更好的方法可以传递符号,而不需要单独导入它们?也就是说,仅通过导入框架?

谢谢。