We are trying to go all in on Swift Package Manager, reorganising our dependency trees etc. around it. It’s going well, big thank you to everyone who has contributed to SwiftPM’s success!
We have a small, but fairly important (for us) hiccup with this: swift test
tries to build all targets, instead of just those needed to build and run the tests.
The reason this is important to us: we have a Swift Package containing a core library (that we want to test), and then numerous other dynamic library and executable targets that use the core library, but often on esoteric platforms like postgresql, as a python plugin, etc.
To build the esoteric Products we need to provide specific build invocations with multiple flags, header search paths, etc. We can’t put those flags into Package.swift specific to those targets, because they require unsafe flags, which from my understanding would make our package unconsumable from other packages, including our own.
Basically we’re stuck with a workaround, and even it doesn’t really work reliably:
swift build --product OurCoreLibrary
swift test --skip-build
The workaround also doesn’t play well with Xcode, VSCode, or other “IDE-like” environments that want to be able to just run swift test
.
At the end of the day, what I think would solve the entire issue (and significantly improve build speeds in some cases) would be for SwiftPM to treat our testTarget
as a separate product, and only build it and its dependencies.
That said, I think all of the above actually also applies to swift build --product XYZ
– instead of just building the targets required for XYZ, it tries to build everything. At least, this was my experience many times in the past; maybe this particular issue has been fixed in the meantime.
Is this a known issue? Can we expect that this is on someone’s radar already, or is this something I should try to tackle myself and try to bring a PR to SwiftPM?