简体   繁体   English

Package.swift 和 Xcode 11 项目,如何同时使用 Carthage 和 SPM?

[英]Package.swift together with Xcode 11 Project, how to use Carthage and SPM alongside?

I feel caught between the Carthage world and the Swift Package Manager (SPM) world, like being stuck in purgatory.我感觉夹在迦太基世界和 Swift Package Manager (SPM) 世界之间,就像被困在炼狱中一样。

I'm developing a Swift library/SDK , and up until now, I've been using Carthage for dependencies.我正在开发一个 Swift library/SDK ,到目前为止,我一直在使用 Carthage 作为依赖项。 But since SPM finally works with iOS, I feel it would be great for people who want to use this library to be able to include it via SPM.但是由于 SPM 最终可以与 iOS 一起使用,我觉得对于想要使用这个库的人来说能够通过 SPM 包含它会很棒。

However, I've hit a wall.然而,我碰壁了。 One of my dependencies, namely BitcoinKit works with Carthage but SPM support is broken.我的依赖项之一,即BitcoinKit可与 Carthage 一起使用,但 SPM 支持已损坏。

In order to distribute my library, I need to have a Package.swift file, and some other critteria (README, source files in Sources , and tests in Tests ).为了分发我的库,我需要一个Package.swift文件和其他一些标准(README、 Sources中的源文件和 Tests 中的Tests )。 I also need to declare my dependencies in said Package.swift file, so that SPM recursivley can resolve all dependencies (when people install my library via SPM).我还需要在Package.swift文件中声明我的依赖项,以便 SPM recursivley 可以解决所有依赖项(当人们通过 SPM 安装我的库时)。 Here's where I get stuck...这就是我卡住的地方...

Since I'm still using Carthage I need a Xcode Project file to set up this Carthage dependency.由于我仍在使用 Carthage,因此我需要一个 Xcode 项目文件来设置此 Carthage 依赖项。 But now my source files cannot import the SPM dependencies.但现在我的源文件无法导入 SPM 依赖项。 They aren't found.他们没有被发现。 Seems like I MUST include the SPM package dependencies using Xcode and Add Package Dependency feature (Apple doc here) .似乎我必须使用 Xcode 包含 SPM package 依赖项并Add Package Dependency功能(Apple doc here) This is not what I want right, I want my Package.swift file to declare the same versions of the SPM packages my library uses.这不是我想要的,我想要我的Package.swift文件来声明我的库使用的相同版本的 SPM 包。 To make it clear, this problem arises due to the fact that I need a Xcode project, due to Carthage.为了清楚起见,由于迦太基,我需要一个 Xcode 项目,因此出现此问题。

So I thought maybe I could build BitcoinKit with Carthage (as I'm doing now), and include the built binary ( .Carthage/Build/iOS/BitcoinKit.framework ) my library, referencing it in Package.swift , but that does not work since SPM does not (yet?) support binaries ( relevant Swift Forum Thread ).所以我想也许我可以用 Carthage 构建 BitcoinKit(就像我现在正在做的那样),并包含构建的二进制文件( .Carthage/Build/iOS/BitcoinKit.framework )我的库,在Package.swift中引用它,但事实并非如此工作,因为 SPM 不(还?)支持二进制文件( 相关 Swift 论坛线程)。

So what are my options?那么我的选择是什么?

1) Wait until someone smart fixes the broken SPM support in BitcoinKit (I've tried myself and failed), and then remove my Xcode project file and complete the transition of to only SPM and for now stick with Carthage... 1) 等到有人聪明地修复了 BitcoinKit 中损坏的 SPM 支持(我自己试过但失败了),然后删除我的 Xcode 项目文件并完成向仅 SPM 的过渡,现在坚持使用 Carthage ...

2) Try to use SPM packages internally in my library installed through Xcode Add Package Dependency feature and manually sync those versions with the ones I declare in my Package.swift . 2) Try to use SPM packages internally in my library installed through Xcode Add Package Dependency feature and manually sync those versions with the ones I declare in my Package.swift . Will that even work?这甚至会起作用吗? Ugh, terrible solution anyway.呃,无论如何,糟糕的解决方案。

3) Hope to include BitcoinKit.framework built through Carthage as a binary when SPM supports it? 3) 希望在 SPM 支持时将通过 Carthage 构建的BitcoinKit.framework包含为二进制文件? When?什么时候? Might take a while?可能需要一段时间?

4) BitcoinKit also works with Cocoapods, but I guess that gets me nowhere, even worse actually, since Cocoapods creates a .xcworkspace file. 4) BitcoinKit 也适用于 Cocoapods,但我想这让我无处可去,实际上更糟的是,因为 Cocoapods 创建了一个.xcworkspace文件。

5) Wait until Apple hopefully (does anyone know if there are any plans?) changes so that we include Swift Packages via Package.swift file even when used together with an Xcode project file? 5) Wait until Apple hopefully (does anyone know if there are any plans?) changes so that we include Swift Packages via Package.swift file even when used together with an Xcode project file? That we I could keep on using Bitcoinkit via Carthage and only declare my SPM packages in one place and I guess SPM/Xcode/Swift would be responsible for integrating the dependencies into my Xcode project, but updated and managed through the Package.swift file...?我们可以继续通过 Carthage 使用 Bitcoinkit 并且只在一个地方声明我的 SPM 包,我猜 SPM/Xcode/Swift 将负责将依赖项集成到我的 Xcode 项目中,但通过Package.swift文件进行更新和管理..?

6) Any other alternative, real solution? 6)任何其他替代,真正的解决方案?

Without looking into the whole 'making bitcoinkit work with SPM' bit I think the 'linking a carthage prebuilt binary' idea sounds best as an interim solution at the very least.在不考虑整个“使 bitcoinkit 与 SPM 一起工作”的情况下,我认为“链接迦太基预构建二进制文件”的想法至少作为一种临时解决方案听起来最好。

It's not possible to link a binary in the package manifest (yet) but you can link it when you're building: When building an SPM package from the command line using swift build you can link the binary using -Xswiftc or -Xlinker to pass the args -F path/to/bitcoinkit if you're linking a framework. It's not possible to link a binary in the package manifest (yet) but you can link it when you're building: When building an SPM package from the command line using swift build you can link the binary using -Xswiftc or -Xlinker to pass args -F path/to/bitcoinkit如果你正在链接一个框架。 Keep in mind each argument must have a cross argument flag before it.请记住,每个参数之前必须有一个交叉参数标志。 When building in Xcode you should be able to solve it with an .xcconfig with the contents:在 Xcode 中构建时,您应该能够使用包含以下内容的.xcconfig来解决它:

FRAMEWORK_SEARCH_PATHS = path/to/bitcoinkit

You may have to tweak it a bit but I imagine this should work, worst case having a separate .xcodeproj generated by swift package generate-xcodeproj --xcconfig-overrides myconfig.xcconfig .您可能需要对其进行一些调整,但我想这应该可以工作,最坏的情况是由swift package generate-xcodeproj --xcconfig-overrides myconfig.xcconfig单独的.xcodeproj

There is a WalletExample in yenom/BitcoinKit on GitHub.在 GitHub 上的yenom/BitcoinKit 中有一个 WalletExample。 It comes with a workspace and project.它带有一个工作区和项目。

I was able to include yenom/BitcoinKit with SPM in my Package.swift and I don't use any projects/workspaces.我能够在我的 Package.swift 中包含带有 SPM 的yenom/BitcoinKit,并且我不使用任何项目/工作区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM