Best way to introduce Macros in a project?

Hello everyone,

I've introduced a couple of macros into my project via SPM, and everything seems to be working correctly. However, as I later discovered to be a known issue, build times have significantly increased due to swift-syntax.

I found an article and a few forum posts discussing the possibility of importing macros as executable binaries, and I thought it might be the best solution to reduce build times. I'm aware that macros won't be debuggable anymore, but I don't expect them to need debugging.

Are there any other drawbacks to this approach?

However, I'm having trouble using macros in this way.
For some context, the project I'm working on is a multi-target project with a target, called X, that can be imported by all other targets and provides some basic functionalities. So, I thought this target X would be the best place to import my binary.

The steps I followed are:

  • created the executable binary MyMacros using the command swift build -c release
  • placed the executable under the Macros folder in the root of the project
  • added the flag -load-plugin-executable Macros/MyMacros#MyMacros only to the target X of my project
  • still in this target, created the Macros.swift file containing simply the declarations that were present in the macros Package's header file

In this way, I thought by importing target X, which is already imported by all targets of my app, I can use the macros anywhere in the app without each target needing to import the executable.

However, the error I encounter I:

External macro implementation type 'MyMacros.Macro1' could not be found for macro 'Macro1().

Am I doing something wrong?