Home > Software engineering >  Adding swift-docc-plugin to my project makes Swift 5.5 builds fail
Adding swift-docc-plugin to my project makes Swift 5.5 builds fail

Time:04-01

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.

CodePudding user response:

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

CodePudding user response:

I modified the script I use the generate the docs, so that it adds the swift-docc-plugin dependency on the fly:

#! /bin/bash

# Insert swift-docc-plugin as a dependency, needed to export the docs
cp Package.swift Package.swift.orig
awk 'NR==15{print "    .package(url: \"https://github.com/apple/swift-docc-plugin.git\", from: \"1.0.0\"),"}7' Package.swift.orig > Package.swift

# See https://apple.github.io/swift-docc-plugin/documentation/swiftdoccplugin/publishing-to-github-pages
swift package --allow-writing-to-directory ./docs generate-documentation --target Saga --output-path ./docs --transform-for-static-hosting --hosting-base-path Saga

# Restore the original Package.swift file
mv Package.swift.orig Package.swift

It's a workaround that I certainly hope won't be needed in the long term, but for now it's the best I could come up with

  • Related