How to check whether a binary-only Swift Package is valid?

We usually validate Swift Packages by calling swift build. But that command returns an error when used on valid swift packages that only contain binaryTarget.

Is there a good way to validate Swift packages that contain only binaryTargets?

(If not, it feels like swift build shouldn't return an error in those cases)

What's the error you're seeing? In general, binary targets are supported by swift build.

@NeoNacho I'm seeing: error: the package does not contain a buildable target

this is the manifest:

// swift-tools-version:5.5
import PackageDescription

let package = Package(
    name: "MyPackage",
    platforms: [.macOS(.v10_10)],
    products: [
            name: "MyPackage",
            targets: ["One", "Two"]
    targets: [
            name: "One",
            url: "",
            checksum: "b80e..."
            name: "Two",
            path: "two.xcframework"

So the package is definitely valid, but swift build fails with an error. How else can I validate the package?

If it were me, I would add a test target that imports and exercises the binary targets, and use swift test. Otherwise you are not really validating anything, regardless of how swift build decides to classify a null build. (Though the current error does seem unintuitive to me. It is also inconsistent with packages containing only tests, which succeed in building nothing.)

I'd expect swift build to not return an error if a package (such as the one above) is valid. We don't need to create a test target to validate packages that contain source code (as we can just call swift build) so I'd hope the same would apply to these kinds of packages.

Yah, test target would be the way to go.

The difference between a source target and a binary one is that if you'd build the binary target on its own, the only thing that could happen is the binary gets copied into the build directory which isn't a useful operation and also wouldn't really validate a whole lot, except maybe the download. So it makes sense to have a test target to determine that the binary can be used successfully.

Note that also for source targets, just building the target itself without any tests does not validate that the target can be used by any client, it just validates that it can build.