Basic setup for SPM buildTool plugins for xcode and SPM targets

SPMPlugin

Contains a plugin conveniently called Plug that can be used on both Swift Package Manager targets as on xcode project targets.

This project was made because there where several issues for me to actually get it to run with visual output on SPM and Xcode targets. This was due to:

  • plugins do not provide breakpoints when run
  • both input and output files need to exist or they will not run
  • plugins that run in the build system of Xcode and/or SPM have to be executables that Xcode/SPM will run on your behave, command tools not necessarily
  • output should be located into the pluginWorkingDirectory which is not your sources folder but in the dreaded DerivedData folder
  • If output needs to be compiled than all output generated by your tool should be listed in the output files, or they will just be generated but not compiled

For this project output will be

  • ~/DerivedData/SPMPluginXcode-<#uuid#>/SourcePackages/plugins/SPMPluginXcode.output/SPMPluginXcode/Plug/Output.swift
  • ~/DerivedData/SPMPlugin-<#uuid#>/SourcePackages/plugins/SPMPluginXcode.output/SPMPluginXcode/Plug/Output.swift

Setup

This is tested with and might work better with future versions of xcode

Potential

  • swiftgen can be used to have type safe asset accessors in swift and you do not have to worry about them being up to date or have to commit them
  • sourcery would be awesome for custom code generation but at present no artefact is ready to be used as input

GitHub

View Github