Swift 包管理器 - 如何 `Always Embed Swift Standard Libraries`?

标签 swift build compiler-flags swift-package-manager

我们有用 Swift 编写的 CLI 工具,供 macOS 上的常用工具(Android 和 iOS 开发人员)使用。 没有安装 Xcode 的 Android 开发者会收到以下错误:

dyld: Library not loaded: @rpath/libswiftCore.dylib
Referenced from: ~/git/myClITool/macosBin Reason: image not found
Abort trap: 6

我们发现在 Xcode 中启用始终嵌入 Swift 标准库很可能会有所帮助,但此 CLI 工具是通过 SPM 导出的,忽略所有 Xcode 设置。

如何仅使用 SPM 实现此构建行为?

最佳答案

找到以下命令行参数:--static-swift-stdlib

使用示例: swift build --static-swift-stdlib -c release

这将产生我们正在寻找的输出。不幸的是,从 Swift 5 开始,这个论点不再适用于任何平台。

使用时,SPM 会抛出以下警告:

warning: Swift compiler no longer supports statically linking the Swift libraries. They're included in the OS by default starting with macOS Mojave 10.14.4 beta 3. For macOS Mojave 10.14.3 and earlier, there's an optional Swift library package that can be downloaded from "More Downloads" for Apple Developers at https://developer.apple.com/download/more/

相关 Swift 错误单:https://bugs.swift.org/browse/SR-648

关于Swift 包管理器 - 如何 `Always Embed Swift Standard Libraries`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58063771/

相关文章:

ios - 如何更快地在 MKMapSnapshotter 上绘图?

iOS Swift 如何监控 UIViewController 生命周期

Xcode 项目范围的编译器标志

arrays - 解开一个实际有值的可选时为零

ios - 如何更改类的属性而不必使用 Realm 删除应用程序

ios - “此版本缺少导出合规信息。”

build - CMake将非编译文件导入构建目录

android - 构建 Android 内核时出错 : "multiple target patterns"

c - 简单浮点运算的奇怪结果 - FPU 内部状态错误?