swift_macro

Swift compiler-plugin executable built for the host.

Description#

Compiles Swift sources into a macOS host executable that the Swift compiler loads at compile time. The macro implementation typically depends on a swift-syntax checkout supplied through deps. Any apple_library dependency edge that reaches a swift_macro target picks up the executable and declaring module automatically.

Attributes#

AttributeTypeRequiredDefaultDescription
minimum_osstringno"13.0"Minimum macOS version for the host plugin
module_namestringnotarget nameCompiled module name (not configurable)
swift_flagslist<string>no[]Extra Swift compiler flags
xcode_developer_dirstringnoPin a specific Xcode by overriding DEVELOPER_DIR. Folded into the action cache key

Dependency Edges#

EdgeAcceptsDescription
depsapple_linkableLibraries the plugin links against (typically a swift-syntax checkout)

Providers#

The target emits apple_swift_plugin.

Capabilities#

CapabilityOutput groups
builddefault, plugin_executable, swiftmodule

Provider record#

FieldTypeMeaning
label_idstringCanonical target id
plugin_executablestringPath to the produced macOS host executable
plugin_module_namestringDeclaring module name paired with the executable by downstream compilers
transitive_plugin_executableslist<string><path>#<module> descriptors propagated through libraries and frameworks

Outputs#

OutputLocation
Plugin executable.once/out/<target>/<module_name>-tool
Swift module.once/out/<target>/<module_name>.swiftmodule

Example#

toml
[[target]]
name = "StringifyMacro"
kind = "swift_macro"
srcs = ["Sources/**/*.swift"]
deps = [
"//third_party/swift-syntax:SwiftSyntax",
"//third_party/swift-syntax:SwiftCompilerPlugin",
]