How can I build a Swift Package for iOS over command line?
Starting with Xcode 11, xcodebuild
supports SwiftPM packages out of the box.
An example invocation would look like this:
xcodebuild -scheme Foo \
-destination 'platform=iOS Simulator,OS=13.5,name=iPhone 11 Pro'
where Foo
would be the name of the library product you're trying to build. You can
get the full list of available schemes for you SwiftPM package with xcodebuild -list
.
You can get the list of available destinations for a given scheme with this invocation:
xcodebuild -showdestinations -scheme Foo
At time of writing (Feb 16, 2019), a working solution is:
swift build -v \
-Xswiftc "-sdk" \
-Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" \
-Xswiftc "-target" \
-Xswiftc "x86_64-apple-ios13.0-simulator"
This command uses -Xswiftc
to workaround the issue by overriding the sdk from macOS to iphonesimulator.
Strictly we add these flags so developers can work around issues, but they also should report a bug so that we can provide a proper solution for their needs.
Source
So I'm guessing there will be a more elegant solution in the future.