How can i avoid re-compiling my command plugin for multiple projects

i have an SPM command plugin that i need to add as a dependency and run for several dozen projects, as part of an automation workflow. since each project has a separate Package.swift manifest, this would require re-compiling the plugin for every project.

is there a way to cache the build somehow, or distribute the plugin as a binary to avoid recompilation? the tool needs to be an SPM plugin because it needs access to the PackagePlugin context.

3 Likes

Wrestling with this exact same problem right now.

One approach could be to move the majority of the code for the plugin into an executable and just use the plugin to forward arguments, then you could a binary target for the executable itself (see SE-305).

3 Likes

that’s a great idea, the tool i am trying to invoke is already a module, so i could just distribute the module as a binary. i can’t believe i didn’t think of that, thanks!

@taylorswift You can have a look at how swiftgen did it GitHub - SwiftGen/SwiftGenPlugin: SwiftGen plugin for SPM

But it is in steps rather easy

  1. swift build -c release your project
  2. create a binary artefact as described download this one to see the included https://github.com/SwiftGen/SwiftGen/releases/download/6.6.0-prerelease/swiftgen-6.6.0.artifactbundle.zip
  3. generate checksum, bit weird to me but you have to do this in the root of your project where your package.swift is swift package compute-checksum /path/to/some.xcframework.zip

This works out grate for iOS targets too as you do not run into problems that your plugin is being build when you build or run tests on iOS targets. Also not the whole dependency tree needs to be loaded in.

1 Like