[Pitch] Package Manager Command Plugins

There isn't a specific guide for this feature beyond what is in CONTRIBUTING.md in the SwiftPM repository, but it is a good idea to add some more detailed steps to the implementation PR since it requires PackagePlugin changes. Because the implementation-in-progress is guarded by setting SWIFTPM_ENABLE_COMMAND_PLUGINS to 1 in the environment, I am hoping to get this into the main toolchain fairly quickly so that everyone can try it out in nightly builds.

This will be possible using this proposal, if you are fine with running the build from your plugin. In other words, this proposal is for cases where the custom command is the primary entry point. It can then do a build as a part of its implementation, but that isn't how users invoke the command plugin.

A separate kind of plugin that would be useful (but which is not this proposal) would be a kind of "build event watcher" plugin that would automatically run at some stage of the build, e.g. after an executable that uses SwiftArgumentParser is linked. Such a plugin would be activated as a side effect of doing a normal build. But that is not possible using this proposal.

The review has started at SE-0332: Package Manager Command Plugins.

Thanks a lot for all the feedback during the pitch!

5 Likes

To be sure, I know SwiftPM doesn’t allow us to build app targets yet, but the command could be invoked as a separate step, passing the path to the archived release build, until it becomes possible we can achieve the goal of not having to deal with multiple tech stacks and have automated, deterministic and secure processes.

I have a tool called swift-bundler that I have been using to build a macOS app with SwiftPM, and this proposal looks like it will help me to integrate swift-bundler with SwiftPM better, and improve its stability! The parts that I love about this proposal are that it provides context to the plugin (currently I have to parse package manifests manually); and that it allows plugins to request builds and such. The original extensible build tools proposal added most of what I needed, but this one brings it to the next level, and I look forward to this proposal (hopefully) getting implemented!

3 Likes

I had some problems with initial setup of buildTool and made a basic example to https://github.com/doozMen/SPMPluginif this helps somebody

3 Likes

I've used

swift package  --allow-writing-to-directory /Users/daniele/Desktop generate-documentation --target Glider --disable-indexing --output-path /Users/daniele/Desktop/GliderDoc --transform-for-static-hosting

to generate documentation for a project of mine.
The output is a folder of 14MB.
Is this expected? 14MB??
(I would upload it on Github)

Hi @danielemm, the query you have is related to the Swift-DocC plugin specifically. The size issue you're seeing is being discussed here.

1 Like