@@ -280,6 +280,35 @@ extension Driver {
280
280
commandLine. appendPath ( localPluginPath)
281
281
}
282
282
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 xcodeDir = try darwinToolchain. findCurrentSelectedXcodeDir ( ) ,
289
+ try ! toolchain. executableDir. isDescendant ( of: xcodeDir) ,
290
+ let xcodeExecutableDir = try darwinToolchain. findXcodeExecutableDir ( )
291
+ {
292
+ try commandLine. appendAll ( . externalPluginPath, from: & parsedOptions)
293
+
294
+ let xcodePluginServerPath = xcodeExecutableDir
295
+ . appending ( component: " swift-plugin-server " )
296
+
297
+ if fileSystem. isExecutableFile ( xcodePluginServerPath) {
298
+ let xcodeToolchainUsrPath = xcodeExecutableDir. parentDirectory
299
+
300
+ let xcodePluginPath = xcodeToolchainUsrPath
301
+ . appending ( components: " lib " , " swift " , " host " , " plugins " )
302
+ commandLine. appendFlag ( . externalPluginPath)
303
+ commandLine. appendFlag ( xcodePluginPath. pathString + " # " + xcodePluginServerPath. pathString)
304
+
305
+ let xcodeLocalPluginPath = xcodeToolchainUsrPath
306
+ . appending ( components: " local " , " lib " , " swift " , " host " , " plugins " )
307
+ commandLine. appendFlag ( . externalPluginPath)
308
+ commandLine. appendFlag ( xcodeLocalPluginPath. pathString + " # " + xcodePluginServerPath. pathString)
309
+ }
310
+ }
311
+
283
312
// Pass down -user-module-version if we are working with a compiler that
284
313
// supports it.
285
314
if let ver = parsedOptions. getLastArgument ( . userModuleVersion) ? . asSingle,
0 commit comments