Skip to content

Support loading macros from a binary artifact#10210

Open
0xTim wants to merge 7 commits into
swiftlang:mainfrom
0xTim:feature/binary-macro-artifact-targets
Open

Support loading macros from a binary artifact#10210
0xTim wants to merge 7 commits into
swiftlang:mainfrom
0xTim:feature/binary-macro-artifact-targets

Conversation

@0xTim

@0xTim 0xTim commented Jun 16, 2026

Copy link
Copy Markdown
Member

Support loading macros from a binary artifact so they can be shipped alongside XCFrameworks. Related PR in Swift Build is here

Forum pitch: https://forums.swift.org/t/pitch-distributing-swift-macros-as-prebuilt-binaries/87447

Motivation:

Currently there's no way to ship macros in a binary artifact, which makes using them more difficult than they should be if you're trying to vend them from something like an XCFramework.

Modifications:

Hooked up the macro artifact type using the host variant and pass it through to the -load-plugin-executable. Works with both the old and new build systems.

Result:

You can ship macros in a binary artifact

0xTim and others added 4 commits June 14, 2026 23:11
Add a 'macro' artifact type to the artifact-bundle format so a compiler
plugin that implements a Swift macro can be shipped as a prebuilt,
host-keyed binary alongside (X)CFrameworks, instead of always being built
from a source .macro target.

A regular Swift target that depends on such a binary target now has the
matching host variant resolved and passed to the compiler via
-load-plugin-executable, exactly like a source-built macro.

Verified end-to-end on macOS (arm64) and Linux (aarch64) with the native
build system.
Teach the SwiftBuild PIF bridge to recognize a binary artifact-bundle
dependency that vends a prebuilt macro plugin (ArtifactType .macro):
select the host variant and set SWIFT_LOAD_BINARY_MACROS on the consuming
target (both the library path in buildSourceModule and the executable path
in makeMainModuleProduct), and skip registering the bundle as a linkable
file so the engine's artifact parser never sees the macro type.

Requires the companion one-line change in the swift-build package adding
SWIFT_LOAD_BINARY_MACROS to ProjectModel.BuildSettings.MultipleValueSetting
(otherwise the setting is dropped during PIF decoding).

Verified on macOS (arm64) and Linux (aarch64) with the default SwiftBuild
engine and the native engine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant