Skip to content

[Macros on Darwin] Use device platform paths when building for the simulator #1400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
26 changes: 18 additions & 8 deletions Sources/SwiftDriver/Toolchains/DarwinToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -429,23 +429,33 @@ public final class DarwinToolchain: Toolchain {
// that SDK's plugin server).
let sdkPathRoot = VirtualPath.lookup(sdkPath).appending(components: "usr")
commandLine.appendFlag(.externalPluginPath)
commandLine.appendFlag("\(sdkPathRoot.pluginPath.name)#\(sdkPathRoot.pluginServerPath.name.spm_shellEscaped())")
commandLine.appendFlag("\(sdkPathRoot.pluginPath.name)#\(sdkPathRoot.pluginServerPath.name)")

commandLine.appendFlag(.externalPluginPath)
commandLine.appendFlag("\(sdkPathRoot.localPluginPath.name)#\(sdkPathRoot.pluginServerPath.name.spm_shellEscaped())")
commandLine.appendFlag("\(sdkPathRoot.localPluginPath.name)#\(sdkPathRoot.pluginServerPath.name)")

// Default paths for compiler plugins within the platform (accessed via that
// platform's plugin server).
let platformPathRoot = VirtualPath.lookup(sdkPath)
// Determine the platform path. For simulator platforms, look into the
// corresponding device platform instance.
let origPlatformPath = VirtualPath.lookup(sdkPath)
.parentDirectory
.parentDirectory
.parentDirectory
.appending(components: "Developer", "usr")
let platformPath: VirtualPath
if let simulatorRange = origPlatformPath.basename.range(of: "Simulator.platform") {
let devicePlatform = origPlatformPath.basename.replacingCharacters(in: simulatorRange, with: "OS.platform")
platformPath = origPlatformPath.parentDirectory.appending(component: devicePlatform)
} else {
platformPath = origPlatformPath
}

// Default paths for compiler plugins within the platform (accessed via that
// platform's plugin server).
let platformPathRoot = platformPath.appending(components: "Developer", "usr")
commandLine.appendFlag(.externalPluginPath)
commandLine.appendFlag("\(platformPathRoot.pluginPath.name)#\(platformPathRoot.pluginServerPath.name.spm_shellEscaped())")
commandLine.appendFlag("\(platformPathRoot.pluginPath.name)#\(platformPathRoot.pluginServerPath.name)")

commandLine.appendFlag(.externalPluginPath)
commandLine.appendFlag("\(platformPathRoot.localPluginPath.name)#\(platformPathRoot.pluginServerPath.name.spm_shellEscaped())")
commandLine.appendFlag("\(platformPathRoot.localPluginPath.name)#\(platformPathRoot.pluginServerPath.name)")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Version": "13.0",
"CanonicalName": "iphoneos13.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Version": "15.0",
"CanonicalName": "iphonesimulator15.0"
}
18 changes: 14 additions & 4 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6869,8 +6869,14 @@ final class SwiftDriverTests: XCTestCase {
}

func testPluginPaths() throws {
let sdkRoot = testInputsPath.appending(component: "SDKChecks").appending(component: "iPhoneOS.sdk")
var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift", "-sdk", VirtualPath.absolute(sdkRoot).name, "-plugin-path", "PluginA", "-external-plugin-path", "PluginB#Bexe", "-load-plugin-library", "PluginB2", "-plugin-path", "PluginC"])
try pluginPathTest(platform: "iPhoneOS", sdk: "iPhoneOS13.0", searchPlatform: "iPhoneOS")
try pluginPathTest(platform: "iPhoneSimulator", sdk: "iPhoneSimulator15.0", searchPlatform: "iPhoneOS")
}

func pluginPathTest(platform: String, sdk: String, searchPlatform: String) throws {
let sdkRoot = testInputsPath.appending(
components: ["Platform Checks", "\(platform).platform", "Developer", "SDKs", "\(sdk).sdk"])
var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift", "-sdk", VirtualPath.absolute(sdkRoot).name, "-plugin-path", "PluginA", "-external-plugin-path", "Plugin~B#Bexe", "-load-plugin-library", "PluginB2", "-plugin-path", "PluginC"])
guard driver.isFrontendArgSupported(.pluginPath) && driver.isFrontendArgSupported(.externalPluginPath) else {
return
}
Expand All @@ -6883,7 +6889,7 @@ final class SwiftDriverTests: XCTestCase {
let pluginAIndex = job.commandLine.firstIndex(of: .path(VirtualPath.relative(.init("PluginA"))))
XCTAssertNotNil(pluginAIndex)

let pluginBIndex = job.commandLine.firstIndex(of: .path(VirtualPath.relative(.init("PluginB#Bexe"))))
let pluginBIndex = job.commandLine.firstIndex(of: .path(VirtualPath.relative(.init("Plugin~B#Bexe"))))
Comment on lines -6886 to +6892
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC we're only shell escaping the SDK paths, not the ones that were already passed in. Could we just rename PlatformChecks to eg. Platform Checks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that's a good idea.

XCTAssertNotNil(pluginBIndex)
XCTAssertLessThan(pluginAIndex!, pluginBIndex!)

Expand All @@ -6909,7 +6915,11 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertNotNil(sdkLocalPluginPathIndex)
XCTAssertLessThan(sdkPluginPathIndex!, sdkLocalPluginPathIndex!)

let platformPath = sdkRoot.parentDirectory.parentDirectory.parentDirectory.appending(components: "Developer", "usr")
let origPlatformPath =
sdkRoot.parentDirectory.parentDirectory.parentDirectory.parentDirectory
.appending(component: "\(searchPlatform).platform")

let platformPath = origPlatformPath.appending(components: "Developer", "usr")
let platformServerPath = platformPath.appending(components: "bin", "swift-plugin-server").pathString

let platformPluginPath = platformPath.appending(components: "lib", "swift", "host", "plugins")
Expand Down