Swift 5
Swift 5 Package Manager now allows you to specify the minimum required target platform using platforms in Package.swift .... see the answer provided by Klaas.
Swift 4
I ended up creating bash swiftxcode , swiftbuild and swifttest as a workaround to simplify:
- setting a macOS target using
swift package generate-xcodeproj and - hiding
swift build -Xswiftc "-target" -Xswiftc "x86_64-β¦"
Customization
Edit and source ~/.bash_profile to add the aliases swiftxcode , swiftbuild and swifttest to the command line.
Modify Package.swift in the project to specify it using the Swift Package Manager version 4 tools:
// swift-tools-version:4.0 import PackageDescription let package = Package(β¦
Add Package.xcconfig to the project folder:
/// Package.xcconfig /// macOS Deployment Target /// /// Code will load on this and later versions of macOS. /// Framework APIs that are unavailable in earlier versions will be weak-linked
Note. If desired, the BuildSettingExtractor (xcodeproj β xcconfig) created by James Dempsey can be useful for exploring other settings added to the Package.xcconfig file.
Use
cd to/some_project_folder/ swiftxcode
Warnings
Package.xcconfig sets assembly parameter values ββonly at the target level in an Xcode project. The values ββof the assembly parameters at the project level remain unchanged.- The values ββof the
Package.xcconfig project are set the same for all purposes. It seems that there is currently no mechanism for xcconfig for each purpose. - Some
xcconfig values, such as SKIP_INSTALL , may need to be set manually in an Xcode project.
Road map
We hope that the current limited xcconfig approach shown above will be replaced by the ability to specify custom build options in the package manifest, as discussed in the Swift 4 Package Management Scheme .
Configuration file support
We are considering adding a configuration file mechanism, which may be user or package specific, to allow you to customize specific package manager behaviors. One of the direct applications of this may be a temporary mechanism for passing overriding compiler flags for a package, although we hope to solve this problem with a real build settings model. Other options for using the configuration file are under consideration.
It's also worth noting that Apple's βNew Build System (Preview)β, written in Swift and released with Xcode 9, can use xcconfig files to determine build settings.
Resources