SwiftPackageIndex-Server icon indicating copy to clipboard operation
SwiftPackageIndex-Server copied to clipboard

plugin-only packages don’t build

Open tayloraswift opened this issue 2 years ago • 3 comments

swift-package-catalog is a package that just vends a single plugin, Catalog. this causes its Linux builds to fail (since it contains no buildable targets), and ironically, it also causes its iOS, watchOS, and tvOS builds to succeed, even though plugins don’t exist on those platforms!

tayloraswift avatar Jul 20 '22 01:07 tayloraswift

I’ll let @finestructure handle the Linux case as he knows far more about that side of things, but I can chime in on the iOS/watchOS/tvOS issue.

I added your package to a test iOS project, and I think we’re doing the correct thing by flagging it as compatible because technically, it is! You can add the package and build an iOS project (and watchOS/tvOS, too) without any errors. It makes little sense to do that, but Xcode raises no issues if you do.

If you want to indicate that this package is incompatible, you’ll need to add something that deliberately breaks the build (with an #error or similar) on those platforms. However, I just tried doing this using the following code, and it doesn’t break the build in Xcode:

#if os(iOS) || os(tvOS) || os(watchOS)
#error("This package is not compatible with iOS, tvOS, or watchOS.")
#endif

In fact, nothing I could do in that file, including inserting completely invalid code for all platforms, broke the build on iOS/tvOS/watchOS platforms. I guess that it doesn’t even compile that file as it knows it is only used by a plugin.

daveverwer avatar Jul 20 '22 12:07 daveverwer

I'm not sure what we could do here. Here's another package that fails its SPM builds for that same reason: https://swiftpackageindex.com/MarcoEidinger/SwiftFormatPlugin

[builder] error: the package does not contain a buildable target

Both the SPM build on macOS and Linux share that issue. I guess package builds for plugin-only packages make very little sense. But I'm not sure how we could determine compatibility in this case.

We could exclude packages with "plugin only" products from build result reporting. Perhaps give them a different kind of display (no build matrix instead of all "?" of "X").

Not sure what the mechanism could/should be to determine what platforms they work on short concocting some mechanism to actually run the plugin in a project. That's pretty much infeasible at scale though...

finestructure avatar Jul 20 '22 13:07 finestructure

what if you create an empty client package and target that depends on the plugin, and try building (without running) the client package?

tayloraswift avatar Jul 22 '22 03:07 tayloraswift