This post summarizes some of the features and enhancements that landed in SwiftPM trunk recently. It would be great if the community can try some of these features and possibly provide feedback. These features are available in the latest trunk or Swift 4.2 toolchain. If you find something unexpected, feel free to reply to this post or create a bug report in JIRA.
Improved scheme generation logic:
The scheme generation logic is improved and generates schemes as follows:
One scheme containing all regular and test targets of the root package.
One scheme per executable target containing the test targets whose dependencies intersect with the dependencies of the exectuable target.
This is implementation of SE-0201. You will need to update the tools version comment to 4.2 in order to use this feature.
Known bug: if you convert an existing dependency to a local dependency, you will need to run swift package update or blow away the .build directory in order for the local package to take effect. Fixed by #1616.
Automatic Xcode project generation:
The generate-xcodeproj has a new --watch option to watch the file system and automatically regenerate the Xcode project if needed. This uses the watchman tool to watch the required files. In future, we can add this option to other commands like swift-build, swift-test, swift-run.
System library targets:
This is implementation for SE-0208. You will need to the update tools version comment to 4.2 in order to use this feature.
Embedable Xcode projects:
For various complex reasons, C language targets are not mapped to "real" framework targets in the generated Xcode project. In practice, this means that the "defines module" and "enable modules" build settings are turned off in the generated framework target. This causes issues when trying to use the generated project as a subproject.
The issue is resolved for C language targets that have an umbrella header. To create an umbrella header, place a file named <targetname>.h inside the include/ directory of that target and include all the public headers in the umbrella header.
OVERVIEW: Watches over your Swift project's source
Tasks (-x & -s) are executed in the order they appear.
USAGE: swift watch [options]
-c, --clear Clear output before each execution
-d, --dry-run Do not run any commands, just print them
-q, --quiet Suppress output from swift-watch itself
-p, --postpone Postpone initial execution until the first change
-m, --monochrome Suppress coloring of output from swift-watch itself
-x, --exec=<cmd> Swift command(s) to execute on changes
-s, --shell=<cmd> Shell command(s) to execute on changes
-h, --help The help menu
I built it almost a year ago in an attempt to replicate my Rust workflow (Atom + iTerm2 + cargo-watch), but it became apparent rather quickly that Swift's CLI is not meant to actually be used by humans, productively and efficiently. The output of swift build and swift test is so damn obfuscated with noise and lacking output coloring, that despite having built swift-watch as an almost feature-complete port of my beloved cargo-watch replicating my workflow in Swift just isn't the same. There is juts no joy in searching for signal in all that noise over and over again.
Nice! I know the output of swift build and swift test is not very good right now but it is one of the goals to have great CLI experience, which includes pretty output. We do have pretty output in some commands like swift test --parallel
I think SwiftPM's support for C/ObjC/C++ language is still far more way to go. Many corner cases, which can be easily resolved by raw Xcode subproject, or even CocoaPods. However, no luck for SwiftPM current weak DSL sytnax