Skip to content

Commit faa70f5

Browse files
committed
[Macros] Set -external-plugin-path when the toolchain is not Xcode
1 parent cf0429d commit faa70f5

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,30 @@ extension Driver {
280280
commandLine.appendPath(localPluginPath)
281281
}
282282

283+
// Pass -external-plugin-path if the current toolchain is not a Xcode
284+
// default toolchain.
285+
if
286+
isFrontendArgSupported(.externalPluginPath),
287+
let darwinToolchain = toolchain as? DarwinToolchain,
288+
let xcodeExecutableDir = try darwinToolchain.findXcodeExecutableDir(),
289+
try xcodeExecutableDir != toolchain.executableDir
290+
{
291+
let xcodePluginServerPath = xcodeExecutableDir
292+
.appending(component: "swift-plugin-server")
293+
294+
let xcodePluginPath = xcodeExecutableDir
295+
.parentDirectory // bin
296+
.appending(components: "lib", "swift", "host", "plugins")
297+
298+
if
299+
fileSystem.isExecutableFile(xcodePluginServerPath),
300+
fileSystem.exists(xcodePluginPath)
301+
{
302+
commandLine.appendFlag(.externalPluginPath)
303+
commandLine.appendFlag(xcodePluginPath.pathString + "#" + xcodePluginPath.pathString)
304+
}
305+
}
306+
283307
// Pass down -user-module-version if we are working with a compiler that
284308
// supports it.
285309
if let ver = parsedOptions.getLastArgument(.userModuleVersion)?.asSingle,

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,18 @@ private extension Version {
421421
return self.description
422422
}
423423
}
424+
425+
extension DarwinToolchain {
426+
func findXcodeExecutableDir() throws -> AbsolutePath? {
427+
let result = try executor.checkNonZeroExit(
428+
args: "xcrun", "-toolchain", "default", "-f", "swiftc",
429+
environment: env
430+
).trimmingCharacters(in: .whitespacesAndNewlines)
431+
432+
guard !result.isEmpty else {
433+
return nil
434+
}
435+
return try AbsolutePath(validating: result)
436+
.parentDirectory // swiftc
437+
}
438+
}

0 commit comments

Comments
 (0)