Skip to content

Commit 432d6e0

Browse files
authored
Merge pull request #1592 from ktoso/pick-toolchain-plugin
2 parents 9861561 + 822330d commit 432d6e0

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -473,21 +473,24 @@ extension Driver {
473473
commandLine.appendFlag($0)
474474
}
475475

476+
let toolchainStdlibPath = VirtualPath.lookup(frontendTargetInfo.runtimeResourcePath.path)
477+
.appending(components: frontendTargetInfo.target.triple.platformName() ?? "", "Swift.swiftmodule")
478+
let hasToolchainStdlib = try fileSystem.exists(toolchainStdlibPath)
479+
480+
// If the resource directory has the standard library, prefer the toolchain's plugins
481+
// to the platform SDK plugins.
482+
if hasToolchainStdlib {
483+
try addPluginPathArguments(commandLine: &commandLine)
484+
}
485+
476486
try toolchain.addPlatformSpecificCommonFrontendOptions(commandLine: &commandLine,
477487
inputs: &inputs,
478488
frontendTargetInfo: frontendTargetInfo,
479489
driver: &self)
480490

481-
// Platform-agnostic options that need to happen after platform-specific ones.
482-
if isFrontendArgSupported(.pluginPath) {
483-
// Default paths for compiler plugins found within the toolchain
484-
// (loaded as shared libraries).
485-
let pluginPathRoot = VirtualPath.absolute(try toolchain.executableDir.parentDirectory)
486-
commandLine.appendFlag(.pluginPath)
487-
commandLine.appendPath(pluginPathRoot.pluginPath)
488-
489-
commandLine.appendFlag(.pluginPath)
490-
commandLine.appendPath(pluginPathRoot.localPluginPath)
491+
// Otherwise, prefer the platform's plugins.
492+
if !hasToolchainStdlib {
493+
try addPluginPathArguments(commandLine: &commandLine)
491494
}
492495
}
493496

@@ -774,6 +777,22 @@ extension Driver {
774777
try explicitDependencyBuildPlanner?.resolveBridgingHeaderDependencies(inputs: &inputs, commandLine: &commandLine)
775778
}
776779

780+
mutating func addPluginPathArguments(commandLine: inout [Job.ArgTemplate]) throws {
781+
guard isFrontendArgSupported(.pluginPath) else {
782+
return
783+
}
784+
785+
// Default paths for compiler plugins found within the toolchain
786+
// (loaded as shared libraries).
787+
let pluginPathRoot = VirtualPath.absolute(try toolchain.executableDir.parentDirectory)
788+
commandLine.appendFlag(.pluginPath)
789+
commandLine.appendPath(pluginPathRoot.pluginPath)
790+
791+
commandLine.appendFlag(.pluginPath)
792+
commandLine.appendPath(pluginPathRoot.localPluginPath)
793+
}
794+
795+
777796
/// If explicit dependency planner supports creating bridging header pch command.
778797
public func supportsBridgingHeaderPCHCommand() throws -> Bool {
779798
return try explicitDependencyBuildPlanner?.supportsBridgingHeaderPCHCommand() ?? false

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7342,7 +7342,15 @@ final class SwiftDriverTests: XCTestCase {
73427342

73437343
let toolchainPluginPathIndex = job.commandLine.firstIndex(of: .path(.absolute(try driver.toolchain.executableDir.parentDirectory.appending(components: "lib", "swift", "host", "plugins"))))
73447344
XCTAssertNotNil(toolchainPluginPathIndex)
7345-
XCTAssertLessThan(platformLocalPluginPathIndex!, toolchainPluginPathIndex!)
7345+
7346+
let toolchainStdlibPath = VirtualPath.lookup(driver.frontendTargetInfo.runtimeResourcePath.path)
7347+
.appending(components: driver.frontendTargetInfo.target.triple.platformName() ?? "", "Swift.swiftmodule")
7348+
let hasToolchainStdlib = try driver.fileSystem.exists(toolchainStdlibPath)
7349+
if hasToolchainStdlib {
7350+
XCTAssertGreaterThan(platformLocalPluginPathIndex!, toolchainPluginPathIndex!)
7351+
} else {
7352+
XCTAssertLessThan(platformLocalPluginPathIndex!, toolchainPluginPathIndex!)
7353+
}
73467354
#endif
73477355

73487356
XCTAssertTrue(job.commandLine.contains(.flag("-plugin-path")))

0 commit comments

Comments
 (0)