Pitch - Swift Tooling Workgroup

certainly. i will use swift-json as an example.

there is a perception that “‘server’ libraries” like swift-json do not give a shit about iOS/watchOS/tvOS users. i have always tried to make my libraries build on as many platforms as is feasible, but SPM makes it weirdly difficult to get any kind of CI set up for these platforms, because SPM thinks of itself as a macOS/linux build system.

the relevant issue ticket here is Packages that contain tools (e.g. swift-markdown) don't seem to build on iOS · Issue #1299 · SwiftPackageIndex/SwiftPackageIndex-Server · GitHub .

the gist of it is that SPM builds all executable and plugin targets on all platforms, even platforms (like iOS) that have no concept of executables or plugins. this automatically fails cross-compilation builds, and the only way to get SPM to stop impaling itself on the executables is to disable them on any source platform that could potentially cross-compile to a deployment-only platform.

practically speaking, this means the only way to meaningfully develop swift-json on macOS is to patch the package manifest for local development, reverting it before submitting changes upstream, because macOS is the cross-compilation source platform for iOS, tvOS, and watchOS.

why #1299 is being tracked as a swiftpackageindex.com bug and not an SPM bug is beyond me, because it affects anyone who has CI for non-desktop platforms, and is also using “modern” SPM features, like snippets and plugins, and apparently, command-line tools.

ever since SPM got snippets, a separate but related problem has also cropped up: packages that adopt snippets are not backwards-compatible with swift <=5.6 (meaning, every currently-available release toolchain). for some reason, SPM 5.6 knows about snippets, but it cannot serialize them properly (it crashes), and it also cannot conditionally ignore them, because the path to the Snippets/ directory is hard-coded.

fortunately, the snippets problem doesn’t affect consumers of the library, because they don’t need to run any of the project’s tools (which crash on SPM <= 5.6). but adding even a single snippet to an SPM project directory effectively means every one of its tools must be gated to swift >= 5.7, including the tools that have nothing to do with snippets, because SPM attempts to serialize the whole package for each tool.

i originally filed the snippets crash as a DocC plugin issue, but have since discovered that it also affects swift-package-catalog and other tools that depend on PackagePlugin.

2 Likes