Skip to content

Support macros as executables #6200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public final class SwiftTargetBuildDescription {
switch self.target.type {
case .library, .test:
return true
case .executable, .snippet:
case .executable, .snippet, .macro:
// This deactivates heuristics in the Swift compiler that treats single-file modules and source files
// named "main.swift" specially w.r.t. whether they can have an entry point.
//
Expand Down Expand Up @@ -394,8 +394,13 @@ public final class SwiftTargetBuildDescription {
args += ["-Xfrontend", "-load-plugin-library", "-Xfrontend", self.buildParameters.binaryPath(for: macro).pathString]
}
#else
if self.requiredMacroProducts.isEmpty == false {
throw InternalError("building macros is not supported yet")
try self.requiredMacroProducts.forEach { macro in
if let macroTarget = macro.targets.first {
let executablePath = self.buildParameters.binaryPath(for: macro).pathString
args += ["-Xfrontend", "-load-plugin-executable", "-Xfrontend", "\(executablePath)#\(macroTarget.c99name)"]
} else {
throw InternalError("macro product \(macro.name) has no targets") // earlier validation should normally catch this
}
}
#endif

Expand Down