Skip to content

Commit f2cbb46

Browse files
authored
Merge pull request #1590 from rintaro/toolchain-plugin
2 parents 20926ef + 64cc0be commit f2cbb46

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

+29-10
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

+9-1
Original file line numberDiff line numberDiff line change
@@ -7395,7 +7395,15 @@ final class SwiftDriverTests: XCTestCase {
73957395

73967396
let toolchainPluginPathIndex = job.commandLine.firstIndex(of: .path(.absolute(try driver.toolchain.executableDir.parentDirectory.appending(components: "lib", "swift", "host", "plugins"))))
73977397
XCTAssertNotNil(toolchainPluginPathIndex)
7398-
XCTAssertLessThan(platformLocalPluginPathIndex!, toolchainPluginPathIndex!)
7398+
7399+
let toolchainStdlibPath = VirtualPath.lookup(driver.frontendTargetInfo.runtimeResourcePath.path)
7400+
.appending(components: driver.frontendTargetInfo.target.triple.platformName() ?? "", "Swift.swiftmodule")
7401+
let hasToolchainStdlib = try driver.fileSystem.exists(toolchainStdlibPath)
7402+
if hasToolchainStdlib {
7403+
XCTAssertGreaterThan(platformLocalPluginPathIndex!, toolchainPluginPathIndex!)
7404+
} else {
7405+
XCTAssertLessThan(platformLocalPluginPathIndex!, toolchainPluginPathIndex!)
7406+
}
73997407
#endif
74007408

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

0 commit comments

Comments
 (0)