Should MacroExpansionContext include target information about the current build?

I would like to slightly alter the behavior of one of my macros depending if I'm in the process of compiling for watchOS or macOS (say, maybe I would prefer to use a platform-specific type without emitting a bunch of #if's into the destination project, or change to a totally different syntactic construct altogether depending on the availability of different types on a per-platform basis.

Would it make sense to provide some target triple information on MacroExpansionContext so I could check it?

public static func expansion(
  of macro: some FreestandingMacroExpansionSyntax,
  in context: some MacroExpansionContext
) throws -> ExprSyntax {
    if context.target.os == .watchOS {
        return createDefinitionForWatchOSClients()
    }
    return createStandardDefinition()
}
2 Likes