使用Carthage进行构建时如何选择Swift工具链 [英] How to select Swift toolchains when building with Carthage
问题描述
我正在创建一个iOS应用,并使用Carthage构建外部库.由于我目前使用的库都是Swift 2和Swift 3,所以我有点挤.因此,我想拥有一个Swift 2分支和一个Swift 3分支进行开发,然后在所有库都兼容Swift 3时合并它们.
I am creating an iOS app and use Carthage to build external libraries. Since the libraries I use are currently both Swift 2 and Swift 3 I am in a bit of a squeeze. Thus I want to have one Swift 2 branch and one Swift 3 branch for development and then merge them when the libraries are all Swift 3 compatible.
但是,我无法选择要使用Carthage(版本0.18)进行构建的工具链.
However, I am not able to select which toolchain for build for with Carthage (version 0.18).
这是我的Cartfile的内容:
Here is the contents of my Cartfile:
# Swift 2 libraries
github "stephencelis/SQLite.swift" ~> 0.10.1
github "Haneke/HanekeSwift"
# Swift 3 libraries
#github "stephencelis/SQLite.swift" "swift3"
#github "Haneke/HanekeSwift" "feature/swift-3"
#github "kitasuke/PagingMenuController"
#github "Alamofire/Alamofire" ~> 4.0
当前使用carthage update
构建.这是一些输出,验证我当前正在使用Swift 2:
This currently builds by using carthage update
. Here are some output verifying that I am currently using Swift 2:
$ swift --version
Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31)
Target: x86_64-apple-macosx10.9
$ ls -lh $(which swift)
-rwxr-xr-x 1 root wheel 18K Jul 8 19:52 /usr/bin/swift
现在我想切换到使用Swift 3进行构建.我在/Library/Developer/Toolchains
中安装了多个工具链,这是OSX在运行安装程序时在其中安装它们的地方:
Now I want to switch to build with Swift 3. I have multiple toolchains installed in /Library/Developer/Toolchains
, which is where OSX installs them when I run the installer:
$ ls -lh /Library/Developer/Toolchains
drwxr-xr-x 6 root wheel 204B Sep 30 20:07 swift-2.2.1-SNAPSHOT-2016-04-23-a.xctoolchain
drwxr-xr-x 7 root wheel 238B Sep 30 17:41 swift-3.0-RELEASE.xctoolchain
drwxr-xr-x 7 root wheel 238B Oct 6 20:53 swift-3.0.1-PREVIEW-2.xctoolchain
lrwxr-xr-x 1 root wheel 30B Oct 8 12:51 swift-latest.xctoolchain -> swift-3.0-RELEASE.xctoolchain/
请注意,我同时安装了Xcode8和Xcode7:
Note that I have both Xcode8 and Xcode7 installed:
$ ls /Applications/Xcode*
/Applications/Xcode.app:
Contents
/Applications/Xcode8.app:
Contents
$ xcodebuild -version
Xcode 7.3.1
Build version 7D1014
现在,可以说我有以下情况:
Now, lets say I have the following scenario:
$ cat Cartfile
github "Alamofire/Alamofire" ~> 4.0
$ carthage update --toolchain com.apple.dt.toolchain.Swift_3_0
*** Fetching Alamofire
*** Checking out Alamofire at "4.0.1"
*** xcodebuild output can be found in /var/folders/wg/fjk346qs7mx8fhplf8_805wm0000gn/T/carthage-xcodebuild.zfHVn5.log
*** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
warning: failed to load toolchain 'com.apple.dt.toolchain.Swift_3_0': Could not find toolchain: com.apple.dt.toolchain.Swift_3_0
我只是无法使它正常工作.所以我的问题是:
I just cannot get this to work. So my question is:
如何通过其他工具链使用迦太基进行构建?
这是我尝试过的:
- 将
swift-latest.xctoolchain
的符号链接更改为其他内容.没有区别. -
像这样将工具链手动添加到我在
.bashrc
中的PATH
变量中,但这没什么区别.
- Changing the symbolic link of
swift-latest.xctoolchain
to other things. Does no difference. Manually adding the toolchains to my
PATH
variable in.bashrc
like this, but it makes no difference.
$ cat ~/.bashrc
export PATH="$PATH:/Library/Developer/Toolchains/swift-2.2.1-SNAPSHOT-2016-04-23-a.xctoolchain/usr/bin/"
export PATH="$PATH:/Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/"
export PATH="$PATH:/Library/Developer/Toolchains/swift-3.0.1-PREVIEW-2.xctoolchain/usr/bin/"
使用TOOLCHAINS=com.apple.dt.toolchain.Swift_3_0 carthage build
和类似版本运行构建,但是没有区别(仍然找不到工具链).
Running the build with TOOLCHAINS=com.apple.dt.toolchain.Swift_3_0 carthage build
and similar, but it makes no difference (still cannot find the toolchain).
推荐答案
从迦太基开始 0.17 有一个选项--toolchain
,它允许您指定要用于构建的确切工具链ID.用法示例:
As of Carthage 0.17 there is an option --toolchain
that allows one to specify an exact toolchain ID to use for the build. Example usage:
carthage update --toolchain org.swift.402017072a
工具链的ID来自工具链Info.plist
文件中的键CFBundleIdentifier
.
The ID of the toolchain comes from the key CFBundleIdentifier
in Info.plist
file of the toolchain.
这篇关于使用Carthage进行构建时如何选择Swift工具链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!