swift 构建 - 默认参数(c++ 包)

swift build - default arguments (c++ package)

我有多个 Swift 生成跨平台库(iOS、macOS)的包。

我正在尝试构建这些包(作为 CI 的一部分),并得到以下观察结果:

当运行 swift build:

swift build
[1/1] Build complete!

然后,在具体指定 iOS Simulator 时:

xcodebuild -showsdks                 

iOS SDKs:
    iOS 15.0                        -sdk iphoneos15.0

iOS Simulator SDKs:
    Simulator - iOS 15.0            -sdk iphonesimulator15.0

macOS SDKs:
    macOS 12.0                      -sdk macosx12.0


swift build --sdk iphonesimulator15.0
clang: warning: no such sysroot directory: '/Users/louis/Code/json/iphonesimulator15.0' [-Wmissing-sysroot]
In file included from /Users/louis/Code/json/_SwiftPackageManagerFile.cpp:5:
In file included from /Users/louis/Code/json/single_include/nlohmann/json.hpp:37:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:641:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:60:
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string.h:60:15: fatal error: 'string.h' file not found
#include_next <string.h>

当我尝试不同的 SDK 时得到完全相同的错误,例如: swift build --sdk macosx12.0

怎么会swift build成功了,但是每当我指定一个SDK它就失败了?默认 SDK 是什么?

注意:我正在使用的包是 C++ 包。

试试这个标志。

swift build -v 

-v, --verbose 增加信息输出的详细程度

它在我的机器上打印出以下字符串:

还有很多其他信息)

这有效:

swift build -Xswiftc "-sdk" -Xswiftc "$(xcrun --sdk iphonesimulator --show-sdk-path)" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios14.0-simulator"