SwiftPM: Platform-specific targets/products


I'm developing a cross-platform graphics library which can use several rendering backends, one of which requires freetype (which I'm including as a system library). This is posing a bit of a problem, since iOS/iPadOS/tvOS/watchOS don't have a system package manager and can't use that backend. SwiftPM doesn't seem to have any way to conditionally include that system-library target, nor the C targets which depend on it, based on the target OS. Similarly, I have a CoreGraphics backend, and rather than listing out every single Apple device (which gets very annoying, very quickly), I'd rather model that as an optional system-library target and conditionally add targets which depend on it based on its availability.

Ultimately, those conditional targets could then give rise to conditional products.

Is there any kind of outline or sketch about how these could be modelled in SwiftPM? Is there anything I or the rest of the community could do to help push it forward?

CC @Aciid

P.S. I know you can compile freetype for those platforms, but some quick googling suggests that it might not be trivial and I really can't be bothered with it. Maybe one day, but not now. Besides, it wouldn't solve the CoreGraphics problem.

1 Like

Yeah, this is a known hole right now. @hartbit is planning work on a proposal to express platform conditional target dependencies.


Yep! I've started work on a proposal and accompanying implementation that will use the same syntax as for build settings conditions, but for target dependencies. I hope to have it up for discussion within a week.


That's great to hear, I'm really looking forward to it. Between this and the recent resources proposal, we're finally closing long-standing holes in the package manager, and that makes me really happy. It's good for whole ecosystem.

The Pitch is up if you want to give your feedback and try it out (there's a working implementation): Package Manager Conditional Target Dependencies

Terms of Service

Privacy Policy

Cookie Policy