Skip to content

swift_macro

Swift compiler-plugin dylib built for the host.

Description

Compiles Swift sources into a loadable plugin (lib<module_name>.dylib) that the Swift compiler loads at compile time. The macro implementation typically depends on a swift-syntax checkout the user provides via deps. Any apple_library dep edge that points at a swift_macro target picks up -load-plugin-library <dylib> 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_dylib, swiftmodule

Provider record

FieldTypeMeaning
label_idstringCanonical target id
plugin_dylibstringPath to the produced lib<module_name>.dylib
plugin_module_namestringModule name a downstream apple_library passes to -load-plugin-library

Outputs

OutputLocation
Plugin dylib.once/out/<target>/lib<module_name>.dylib
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",
]

Limitations

The target kind does not vendor swift-syntax. The user supplies it as a regular dep edge, which matches how established Apple build systems handle the same dependency. Until a swift-syntax checkout is available as an apple_library, swift_macro targets cannot build end to end.

Released under an open-source license.