Skip to content
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

Add support for load-pass-plugin option #1472

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,11 @@ extension Driver {
if !hasToolchainStdlib {
try addPluginPathArguments(commandLine: &commandLine)
}

if let passPluginPath = parsedOptions.getLastArgument(.loadPassPluginEQ),
isFrontendArgSupported(.loadPassPluginEQ) {
commandLine.appendFlag("-load-pass-plugin=\(passPluginPath.asSingle)")
}
}

mutating func addBridgingHeaderPCHCacheKeyArguments(commandLine: inout [Job.ArgTemplate],
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftOptions/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ extension Option {
public static let linkObjcRuntime: Option = Option("-link-objc-runtime", .flag, attributes: [.doesNotAffectIncrementalBuild], helpText: "Deprecated")
public static let lldbRepl: Option = Option("-lldb-repl", .flag, attributes: [.helpHidden, .noBatch], helpText: "LLDB-enhanced REPL mode", group: .modes)
public static let reuseDependencyScanCache: Option = Option("-load-dependency-scan-cache", .flag, attributes: [.frontend, .noDriver], helpText: "After performing a dependency scan, serialize the scanner's internal state.")
public static let loadPassPluginEQ: Option = Option("-load-pass-plugin=", .joined, attributes: [.frontend, .argumentIsPath], metaVar: "<path>", helpText: "Load LLVM pass plugin from a dynamic shared object file.")
public static let loadPluginExecutable: Option = Option("-load-plugin-executable", .separate, attributes: [.frontend, .doesNotAffectIncrementalBuild, .argumentIsPath], metaVar: "<path>#<module-names>", helpText: "Path to a compiler plugin executable and a comma-separated list of module names where the macro types are declared", group: .pluginSearch)
public static let loadPluginLibrary: Option = Option("-load-plugin-library", .separate, attributes: [.frontend, .doesNotAffectIncrementalBuild, .argumentIsPath], metaVar: "<path>", helpText: "Path to a dynamic library containing compiler plugins such as macros", group: .pluginSearch)
public static let loadResolvedPlugin: Option = Option("-load-resolved-plugin", .separate, attributes: [.frontend, .doesNotAffectIncrementalBuild, .argumentIsPath], metaVar: "<library-path>#<executable-path>#<module-names>", helpText: "Path to resolved plugin configuration and a comma-separated list of module names where the macro types are declared. Library path and exectuable path can be empty if not used", group: .pluginSearch)
Expand Down Expand Up @@ -1520,6 +1521,7 @@ extension Option {
Option.linkObjcRuntime,
Option.lldbRepl,
Option.reuseDependencyScanCache,
Option.loadPassPluginEQ,
Option.loadPluginExecutable,
Option.loadPluginLibrary,
Option.loadResolvedPlugin,
Expand Down
15 changes: 15 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8335,6 +8335,21 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertTrue(jobs[0].commandLine.contains(subsequence: featureArgs.map { Job.ArgTemplate.flag($0) }))
}
}

func testFrontendLoadPassPlugin() throws {
#if os(Windows)
throw XCTSkip("'-load-pass-plugin' is not available on Windows.")
#else
var driver = try Driver(args: ["swiftc", "foo.swift", "-load-pass-plugin=/path/to/plugin"])
guard driver.isFrontendArgSupported(.loadPassPluginEQ) else {
throw XCTSkip("Skipping: compiler does not support '-load-pass-plugin'.")
}
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs[0].kind, .compile)
XCTAssertTrue(plannedJobs[0].tool.name.hasSuffix("swift-frontend"))
XCTAssertTrue(plannedJobs[0].commandLine.contains(.flag("-load-pass-plugin=/path/to/plugin")))
#endif
}
}

func assertString(
Expand Down