Skip to content

Commit 1b17f33

Browse files
committed
[Macros on Darwin] Use device platform paths when building for the simulator
To avoid having duplicated macro implementations in both the device and simulator platforms, when building for a simulator platform, pass `-external-plugin-path` that points into the *device* platform. There is no need to have macro implementations in the simulator platforms. Implements rdar://112563633
1 parent e98ddbd commit 1b17f33

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,23 @@ public final class DarwinToolchain: Toolchain {
434434
commandLine.appendFlag(.externalPluginPath)
435435
commandLine.appendFlag("\(sdkPathRoot.localPluginPath.name)#\(sdkPathRoot.pluginServerPath.name.spm_shellEscaped())")
436436

437-
// Default paths for compiler plugins within the platform (accessed via that
438-
// platform's plugin server).
439-
let platformPathRoot = VirtualPath.lookup(sdkPath)
437+
// Determine the platform path. For simulator platforms, look into the
438+
// corresponding device platform instance.
439+
let origPlatformPath = VirtualPath.lookup(sdkPath)
440440
.parentDirectory
441441
.parentDirectory
442442
.parentDirectory
443-
.appending(components: "Developer", "usr")
443+
let platformPath: VirtualPath
444+
if let simulatorRange = origPlatformPath.basename.range(of: "Simulator.platform") {
445+
let devicePlatform = origPlatformPath.basename.replacingCharacters(in: simulatorRange, with: "OS.platform")
446+
platformPath = origPlatformPath.parentDirectory.appending(component: devicePlatform)
447+
} else {
448+
platformPath = origPlatformPath
449+
}
450+
451+
// Default paths for compiler plugins within the platform (accessed via that
452+
// platform's plugin server).
453+
let platformPathRoot = platformPath.appending(components: "Developer", "usr")
444454
commandLine.appendFlag(.externalPluginPath)
445455
commandLine.appendFlag("\(platformPathRoot.pluginPath.name)#\(platformPathRoot.pluginServerPath.name.spm_shellEscaped())")
446456

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"Version": "13.0",
3+
"CanonicalName": "iphoneos13.0"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"Version": "15.0",
3+
"CanonicalName": "iphonesimulator15.0"
4+
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6869,7 +6869,13 @@ final class SwiftDriverTests: XCTestCase {
68696869
}
68706870

68716871
func testPluginPaths() throws {
6872-
let sdkRoot = testInputsPath.appending(component: "SDKChecks").appending(component: "iPhoneOS.sdk")
6872+
try pluginPathTest(platform: "iPhoneOS", searchPlatform: "iPhoneOS")
6873+
try pluginPathTest(platform: "iPhoneSimulator", searchPlatform: "iPhoneOS")
6874+
}
6875+
6876+
func pluginPathTest(platform: String, searchPlatform: String) throws {
6877+
let sdkRoot = testInputsPath.appending(
6878+
components: ["PlatformChecks", "\(platform).platform", "Developer", "SDKs", "\(platform).sdk"])
68736879
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"])
68746880
guard driver.isFrontendArgSupported(.pluginPath) && driver.isFrontendArgSupported(.externalPluginPath) else {
68756881
return
@@ -6909,7 +6915,11 @@ final class SwiftDriverTests: XCTestCase {
69096915
XCTAssertNotNil(sdkLocalPluginPathIndex)
69106916
XCTAssertLessThan(sdkPluginPathIndex!, sdkLocalPluginPathIndex!)
69116917

6912-
let platformPath = sdkRoot.parentDirectory.parentDirectory.parentDirectory.appending(components: "Developer", "usr")
6918+
let origPlatformPath =
6919+
sdkRoot.parentDirectory.parentDirectory.parentDirectory.parentDirectory
6920+
.appending(component: "\(searchPlatform).platform")
6921+
6922+
let platformPath = origPlatformPath.appending(components: "Developer", "usr")
69136923
let platformServerPath = platformPath.appending(components: "bin", "swift-plugin-server").pathString
69146924

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

0 commit comments

Comments
 (0)