Consider the following code to verify the compilation of some swift package (for the Swift Package Manager)
xcodebuild \
-scheme name-Package \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,OS=17.0,name=iPhone 15' \
-configuration Debug
And the equivalent swift build
command:
swift build -Xswiftc -warnings-as-errors -Xswiftc "-sdk" -Xswiftc "$(xcrun --sdk iphonesimulator --show-sdk-path)" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios15.0-simulator"
Questions:
Simulator,OS=17.0,name=iPhone 15
and remove this one from the 2nd one: x86_64-apple-ios15.0-simulator
scheme
name from the 1st command, i.e. name-Package
, or discover it in some way and paste the scheme containing the Package
word, so that the xcodebuild
will try to build the whole package and not just some single target in that package.Motivation: Create a generic build script that can work on any Swift Package repository.
PACKAGE_SCHEME=$(xcodebuild -list | (awk '/Schemes:/ {p=1; next} p && NF; !p {p=0}' | grep "Package" || xcodebuild -list | awk '/Schemes:/ {p=1; next} p && NF; !p {p=0}' | head -1) | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
xcodebuild \
-scheme "$PACKAGE_SCHEME" \
-sdk iphonesimulator \
-destination "platform=iOS Simulator,name=iPhone" \
-configuration Debug
It works as follows:
Package
suffix or the first scheme