Support loading macros from a binary artifact#10210
Open
0xTim wants to merge 7 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
macroartifact 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