Running executable product from dependency with Swift 5.2

I've made a small text manipulation utility in Swift and have a Package.swift that publishes it as an executable product.

Prior to Swift 5.2, I was able to run this from a different path using this Package.swift:

// swift-tools-version:5.0
import PackageDescription

let package = Package(
name: "podspec-renderer",
dependencies: [
.package(url: "git@github.com:gamechanger/inline-template-renderer.git", from: "0.0.3"),
]
)

and executing:
swift run inline-template-renderer

swift would retrieve the source files from GitHub, compile in .build and then execute it.

As of Swift 5.2, this now gives me an error message that a default target is not specified.
I don't know if this is a regression or if my usage was never supported, but it was very useful as a way to distribute this small and use my utility on different iOS projects.

If it was unintended behavior, is there some way to get this to work? When I try specifying a target in the Package.swift in my destination (where I want to execute the script), it wants a local directory with source files.

Thanks to an example from Jesse Squires, I was able to figure out how to get this to work though it seems a bit inelegant.

swift run --package-path /PATH/TO/inline-template-renderer inline-template-renderer <args>

The default path will be .build/checkouts/inline-template-renderer.

1 Like