Skip to content

Commit 670879d

Browse files
committed
Add support for macro frontend options
Pass through options for macros, especially compiler plugin search paths. Add a default search path into `lib/swift/host/plugins`. Driver side of rdar://105095761
1 parent 16ce19d commit 670879d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,19 @@ extension Driver {
237237
commandLine.appendFlag(.emptyAbiDescriptor)
238238
}
239239

240+
if isFrontendArgSupported(.emitMacroExpansionFiles) {
241+
try commandLine.appendLast(.emitMacroExpansionFiles, from: &parsedOptions)
242+
}
243+
244+
if isFrontendArgSupported(.pluginPath) {
245+
try commandLine.appendAll(.pluginPath, from: &parsedOptions)
246+
247+
let defaultPluginPath = try toolchain.executableDir.parentDirectory
248+
.appending(components: "lib", "swift", "host", "plugins")
249+
commandLine.appendFlag(.pluginPath)
250+
commandLine.appendPath(defaultPluginPath)
251+
}
252+
240253
// Pass down -user-module-version if we are working with a compiler that
241254
// supports it.
242255
if let ver = parsedOptions.getLastArgument(.userModuleVersion)?.asSingle,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6633,6 +6633,19 @@ final class SwiftDriverTests: XCTestCase {
66336633
#endif
66346634
}
66356635

6636+
func testPluginPaths() throws {
6637+
var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift"])
6638+
guard driver.isFrontendArgSupported(.pluginPath) else {
6639+
return
6640+
}
6641+
6642+
let jobs = try driver.planBuild().removingAutolinkExtractJobs()
6643+
XCTAssertEqual(jobs.count, 1)
6644+
let job = jobs.first!
6645+
XCTAssertTrue(job.commandLine.contains(.flag("-plugin-path")))
6646+
XCTAssertTrue(job.commandLine.contains(.path(.absolute(try driver.toolchain.executableDir.parentDirectory.appending(components: "lib", "swift", "host", "plugins")))))
6647+
}
6648+
66366649
func testRegistrarLookup() throws {
66376650
#if os(Windows)
66386651
let SDKROOT: AbsolutePath = localFileSystem.currentWorkingDirectory!.appending(components: "SDKROOT")

0 commit comments

Comments
 (0)