How to exclude platforms in SPM

Previously if platforms were left out of the platforms list in a Package.swift manifest, generated Xcode projects wouldn't include those platforms. Now that there are minimum default platforms, generated projects include the ability to build for all platforms, and there doesn't seem to be any way to make my package not build for a specific platform.

I have a package that I'd like to only build for iOS. I import it into a project that has both iOS and watchOS targets. I don't want Xcode to build that package when I'm building for watchOS.

Is there any way to do this?

1 Like

In the current release, the best you can do is frame every source file with #if os(iOS).

However, SE‐0273 should remove the need for it in future releases (though it works from the side of the importer, not the side of the imported).

Previously if platforms were left out of the platforms list in a Package.swift manifest, generated Xcode projects wouldn't include those platforms.

???—That has never been the case.

???—That has never been the case.

ah yeah you're right. Apologies I was misreading https://github.com/apple/swift-package-manager/blob/master/Documentation/PackageDescription.md