Skip to content

Commit

Permalink
Add support for load-pass-plugin option
Browse files Browse the repository at this point in the history
`Options.swift` has been regenerated so as to
include `load-pass-plugin` option as well.
  • Loading branch information
antoniofrighetto committed Apr 30, 2024
1 parent 2ed37d1 commit 3128d28
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ extension Driver {
commandLine.appendFlag(.pluginPath)
commandLine.appendPath(pluginPathRoot.localPluginPath)
}

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 @@ -572,6 +572,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 locale: Option = Option("-locale", .separate, attributes: [.frontend, .doesNotAffectIncrementalBuild], metaVar: "<locale-code>", helpText: "Choose a language for diagnostic messages")
Expand Down Expand Up @@ -1416,6 +1417,7 @@ extension Option {
Option.linkObjcRuntime,
Option.lldbRepl,
Option.reuseDependencyScanCache,
Option.loadPassPluginEQ,
Option.loadPluginExecutable,
Option.loadPluginLibrary,
Option.locale,
Expand Down
15 changes: 15 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7771,6 +7771,21 @@ final class SwiftDriverTests: XCTestCase {
}
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-emit-module", "-cache-compile-job", "-explicit-module-build")
}

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

0 comments on commit 3128d28

Please sign in to comment.