Hi everyone,
starting this thread to collect community input and eventually end up with a recommendations about using macros in some of the more “foundational” packages.
This comes from a specific need: introducing @Traced to swift-distributed-tracing (PR, and even older PR from 2024).
For reasons of “don’t pull any dependencies” recently we started trying to split out parts of swift-java into a dependency free (including free of swift-syntax / macros) package. And the same question was posed there as now appears in tracing, and many other repositories:
Question:
Is it ok for foundational packages, like e.g. swift-distributed-tracing, which will be used by many packages in the ecosystem, to use macros?
Recent improvements:
Recently, the pre-built swift-syntax was introduced to solve some of the build-time problems. However, still, many folks have quite a strong reaction about shipping macros in core libraries. Target based dependency resolution has improved in recent years in SwiftPM, however it still resolves “not used” by a target dependencies, so e.g. doing a TracingMacros target still causes the resolver to consider it during resolution. Future work may improve this, but we’re looking at present day approaches.
Package traits also don’t yet prevent the resolution of “not used” dependencies, which may perhaps also be improved in the future, but AFAIK at present package traits are also insufficient to avoid unused dependencies from being resolved.
I’d like to collect input and thoughts about this subject, and eventually propose to make this a form of SSWG or ESG recommendation, so we can have a consistent approach in packages.