Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -473,21 +473,24 @@ extension Driver {
commandLine.appendFlag($0)
}

let toolchainStdlibPath = VirtualPath.lookup(frontendTargetInfo.runtimeResourcePath.path)
.appending(components: frontendTargetInfo.target.triple.platformName() ?? "", "Swift.swiftmodule")
let hasToolchainStdlib = try fileSystem.exists(toolchainStdlibPath)

// If the resource directory has the standard library, prefer the toolchain's plugins
// to the platform SDK plugins.
if hasToolchainStdlib {
try addPluginPathArguments(commandLine: &commandLine)
}

try toolchain.addPlatformSpecificCommonFrontendOptions(commandLine: &commandLine,
inputs: &inputs,
frontendTargetInfo: frontendTargetInfo,
driver: &self)

// Platform-agnostic options that need to happen after platform-specific ones.
if isFrontendArgSupported(.pluginPath) {
// Default paths for compiler plugins found within the toolchain
// (loaded as shared libraries).
let pluginPathRoot = VirtualPath.absolute(try toolchain.executableDir.parentDirectory)
commandLine.appendFlag(.pluginPath)
commandLine.appendPath(pluginPathRoot.pluginPath)

commandLine.appendFlag(.pluginPath)
commandLine.appendPath(pluginPathRoot.localPluginPath)
// Otherwise, prefer the platform's plugins.
if !hasToolchainStdlib {
try addPluginPathArguments(commandLine: &commandLine)
}
}

Expand Down Expand Up @@ -774,6 +777,22 @@ extension Driver {
try explicitDependencyBuildPlanner?.resolveBridgingHeaderDependencies(inputs: &inputs, commandLine: &commandLine)
}

mutating func addPluginPathArguments(commandLine: inout [Job.ArgTemplate]) throws {
guard isFrontendArgSupported(.pluginPath) else {
return
}

// Default paths for compiler plugins found within the toolchain
// (loaded as shared libraries).
let pluginPathRoot = VirtualPath.absolute(try toolchain.executableDir.parentDirectory)
commandLine.appendFlag(.pluginPath)
commandLine.appendPath(pluginPathRoot.pluginPath)

commandLine.appendFlag(.pluginPath)
commandLine.appendPath(pluginPathRoot.localPluginPath)
}


/// If explicit dependency planner supports creating bridging header pch command.
public func supportsBridgingHeaderPCHCommand() throws -> Bool {
return try explicitDependencyBuildPlanner?.supportsBridgingHeaderPCHCommand() ?? false
Expand Down
10 changes: 9 additions & 1 deletion Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7395,7 +7395,15 @@ final class SwiftDriverTests: XCTestCase {

let toolchainPluginPathIndex = job.commandLine.firstIndex(of: .path(.absolute(try driver.toolchain.executableDir.parentDirectory.appending(components: "lib", "swift", "host", "plugins"))))
XCTAssertNotNil(toolchainPluginPathIndex)
XCTAssertLessThan(platformLocalPluginPathIndex!, toolchainPluginPathIndex!)

let toolchainStdlibPath = VirtualPath.lookup(driver.frontendTargetInfo.runtimeResourcePath.path)
.appending(components: driver.frontendTargetInfo.target.triple.platformName() ?? "", "Swift.swiftmodule")
let hasToolchainStdlib = try driver.fileSystem.exists(toolchainStdlibPath)
if hasToolchainStdlib {
XCTAssertGreaterThan(platformLocalPluginPathIndex!, toolchainPluginPathIndex!)
} else {
XCTAssertLessThan(platformLocalPluginPathIndex!, toolchainPluginPathIndex!)
}
#endif

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