如何通过命令行为 iOS 构建 Swift 包? [英] How can I build a Swift Package for iOS over command line?

查看:31
本文介绍了如何通过命令行为 iOS 构建 Swift 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Xcode 中,我可以选择我的目的地作为通用 iOS 设备"或任何 iOS 模拟器,我的包将为 ios 构建特定于平台的代码.

In Xcode, I can select my destination as a "generic iOS device" or any iOS simulator, and my package will build platform-specific code for ios.

通过命令行swift build"为 macOS 构建我的目标.

Via command line "swift build" only builds my target for macOS.

我想为 iOS 构建目标以用于 CI 目的.为 macOS 构建的问题在于不会构建 UIKit 特定的代码.

I want to build the target for iOS for CI purposes. The problem with building for macOS is that UIKit-specific code won't be built.

例如:

#if canImport(UIKit)
    // some invalid code
#endif

无效代码不会被注意到,并且会通过构建阶段.

The invalid code will not be noticed and will pass the build phase.

理想情况下,我可以说类似swift build -platform iOS.有没有办法做这样的事情?

Ideally, I could say something like swift build -platform iOS. Is there a way to do something like this?

推荐答案

在撰写本文时(2019 年 2 月 16 日),一个可行的解决方案是:

At time of writing (Feb 16, 2019), a working solution is:

swift build -v -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios13.0-simulator"

此命令使用 -Xswiftc 通过将 sdk 从 macOS 覆盖到 iphonesimulator 来解决此问题.

This command uses -Xswiftc to workaround the issue by overriding the sdk from macOS to iphonesimulator.

严格来说,我们添加这些标志是为了让开发人员可以解决问题,但他们也应该报告错误,以便我们能够为他们的需求提供适当的解决方案.

Strictly we add these flags so developers can work around issues, but they also should report a bug so that we can provide a proper solution for their needs.

来源

所以我猜未来会有更优雅的解决方案.

So I'm guessing there will be a more elegant solution in the future.

这篇关于如何通过命令行为 iOS 构建 Swift 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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