多年来,我一直在使用服务器端Swift进行服务器端开发,使用Xcode作为一种方便的编辑工具。现在,Xcode已经支持Swift包,这种情况已经普遍改善。我没有针对任何传统的苹果硬件,所以这可能是我的问题的根源,但看到这个问题最近才开始出现,我报告了它,以防其他人也遇到它。
使用我的一个包:http://github.com/SyncServerII/ServerDropboxAccount.git,我不能再用Xcode构建它了。
我的目的主要是编辑并消除语法错误--也就是说,我使用Xcode作为编辑器。在某些情况下,使用这些服务器端包,我可以在Xcode中运行单元测试。在某些情况下,我必须在我的Ubuntu目标平台上运行测试。
就在过去的几天里,我不能再用Xcode构建这个特定的包,也不能在Mac的命令行中构建它。
我得到的错误如下:
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:140:37: Cannot find type 'APICallResult' in scope
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds.swift:16:29: Cannot find type 'AccountAPICall' in scope
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds.swift:16:45: Cannot find type 'Account' in scope
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:49:14: Value of type 'DropboxCreds' has no member 'apiCall'
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:49:111: Cannot infer contextual base in reference to member 'string'
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:49:147: Cannot infer contextual base in reference to member 'json'
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:106:14: Value of type 'DropboxCreds' has no member 'apiCall'
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:106:133: Cannot infer contextual base in reference to member 'data'
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:106:167: Cannot infer contextual base in reference to member 'json'
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:106:190: Unable to infer type of a closure parameter 'apiResult' in the current context
/Users/chris/Desktop/NewSyncServer/ServerDropboxAccount/Sources/ServerDropboxAccount/DropboxCreds+CloudStorage.swift:106:201: Unable to infer type of a closure parameter 'statusCode' in the current context当我在Mac的命令行中使用swift build时,我得到了同样的错误。但是,当我在Ubuntu上使用swift build时,我没有得到任何错误--这个包可以干净地构建。
在Mac OS上:
MacBook-Pro-4:ServerDropboxAccount chris$ swift --version
Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
Target: x86_64-apple-darwin19.6.0在Ubuntu上:
root@7b763a0a0a3f:~/Apps/ServerDropboxAccount# swift --version
Swift version 5.3.1 (swift-5.3.1-RELEASE)
Target: x86_64-unknown-linux-gnu这可能是一个边缘用例,但在我完全放弃使用Xcode之前,我想了解一下为什么会发生这种情况。我很欣赏你的想法。谢谢!
我在这个问题中为Kitura添加了一个标签,因为我的服务器是基于Kitura的。而且因为Kitura最近正在经历一些转变,从IBM转移到社区支持。
发布于 2020-12-26 12:36:51
好吧,我现在觉得自己很傻。我在一个依赖库中的一个文件中有一个条件,它排除了一些代码。
#if os(Linux) || SERVER
// Code
#endif我将把这个问题留下来,只是为了展示解决方案。我需要将SERVER的定义添加到该依赖库的Package.swift中:
.target(
name: "ServerAccount",
dependencies: [
"ServerShared",
// For new condition feature, see https://forums.swift.org/t/package-manager-conditional-target-dependencies/31306/26
.product(name: "Kitura", package: "Kitura", condition: .when(platforms: [.linux, .macOS])),
.product(name: "HeliumLogger", package: "HeliumLogger", condition: .when(platforms: [.linux, .macOS])),
.product(name: "Credentials", package: "Kitura-Credentials", condition: .when(platforms: [.linux, .macOS])),
],
swiftSettings: [
// So I can do basic development and editing with this on Mac OS. Otherwise if some dependent library uses this it will not get Account related code. See Account.swift.
.define("SERVER", .when(platforms: [.macOS], configuration: .debug)),
]),哇哦。:)。
https://stackoverflow.com/questions/65452179
复制相似问题