Adding swift-docc-plugin to my project makes Swift 5.5 builds fail

840 Views Asked by At

I have a project that I recently added swift-docc-plugin to, so that I can export the DocC documentation as a static website.

// swift-tools-version:5.5
import PackageDescription

let package = Package(
  name: "Saga",
  platforms: [
    .macOS(.v12)
  ],
  products: [
    .library(name: "Saga", targets: ["Saga"]),
    .executable(name: "watch", targets: ["SagaCLI"])
  ],
  dependencies: [
    .package(url: "https://github.com/kylef/PathKit", from: "1.0.1"),
    .package(url: "https://github.com/JohnSundell/Codextended.git", from: "0.1.0"),
    .package(url: "https://github.com/apple/swift-docc-plugin.git", branch: "main"),
  ],
  targets: [
    .target(
      name: "Saga",
      dependencies: [
        "PathKit",
        "Codextended",
      ]
    ),
    .executableTarget(
      name: "SagaCLI",
      dependencies: ["PathKit"]
    ),
    .testTarget(
      name: "SagaTests",
      dependencies: ["Saga"]
    ),
  ]
)

The problem is that on Swift Package Index all builds on Swift 5.5 and below are failing:

error: package at 'https://github.com/apple/swift-docc-plugin.git' @ 859caac534e94ace18b894ccd9ed301ae4aeda84 is using Swift tools version 5.6.0 but the installed version is 5.5.0 in https://github.com/apple/swift-docc-plugin.git

See https://swiftpackageindex.com/builds/1DF06709-E2CA-4F56-B793-9CC7C8FC0A9D for a full build log.

How do I solve this? I could remove swift-docc-plugin from the dependencies I guess, and add it every time I want to export the docs, but that seems like a ridiculously annoying workaround. I don't really want to increase the minimum version of my library just because of swift-docc-plugin either.

2

There are 2 best solutions below

0
On

The solution was pretty easy in the end. Just add this to the end of Package.swift

#if swift(>=5.6)
package.dependencies += [
    .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
  ]
#endif
0
On

Unfortunately, I don’t think there’s a way around that due to the way we’re testing a package by building it.

Here's some more detail: https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/1633#issuecomment-1075899345