Skip to content
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

[Explicit Modules] Handle re-mapped platform versions when specifying SDK-aligned -clang-target on Darwin platforms #1394

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
4 changes: 3 additions & 1 deletion Sources/SwiftDriver/Toolchains/DarwinToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ public final class DarwinToolchain: Toolchain {
if let explicitClangTripleArg = driver.parsedOptions.getLastArgument(.clangTarget)?.asSingle {
clangTargetTriple = explicitClangTripleArg
} else {
clangTargetTriple = frontendTargetInfo.target.unversionedTriple.triple + sdkInfo.versionString
let currentTriple = frontendTargetInfo.target.triple
let sdkVersionedOSString = currentTriple.osNameUnversioned + sdkInfo.sdkVersion(for: currentTriple).sdkVersionString
clangTargetTriple = currentTriple.triple.replacingOccurrences(of: currentTriple.osName, with: sdkVersionedOSString)
}

commandLine.appendFlag(.clangTarget)
Expand Down
4 changes: 2 additions & 2 deletions TestInputs/SDKChecks/MacOSX10.15.sdk/SDKSettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Version": "10.15",
"VersionMap": {
"macOS_iOSMac": {},
"iOSMac_macOS": {}
"macOS_iOSMac": {"10.15":"13.3"},
"iOSMac_macOS": {"13.3":"10.15"}
},
"CanonicalName": "macosx10.15"
}
28 changes: 24 additions & 4 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3747,7 +3747,7 @@ final class SwiftDriverTests: XCTestCase {

func testClangTargetForExplicitModule() throws {
#if os(macOS)
let sdkRoot = testInputsPath.appending(component: "SDKChecks").appending(component: "iPhoneOS.sdk")
let sdkRoot = testInputsPath.appending(component: "SDKChecks").appending(component: "MacOSX10.15.sdk")

// Check -clang-target is on by default when explicit module is on.
try withTemporaryDirectory { path in
Expand All @@ -3756,17 +3756,37 @@ final class SwiftDriverTests: XCTestCase {
$0 <<< "import Swift"
}
var driver = try Driver(args: ["swiftc", "-explicit-module-build",
"-target", "arm64-apple-ios14.0",
"-target", "arm64-apple-macos10.14",
"-sdk", sdkRoot.pathString,
main.pathString])
guard driver.isFrontendArgSupported(.clangTarget) else {
throw XCTSkip("Skipping: compiler does not support '-clang-target'")
}
let plannedJobs = try driver.planBuild()
XCTAssertTrue(plannedJobs.contains { job in
job.commandLine.contains(subsequence: [.flag("-clang-target"), .flag("arm64-apple-macos10.15")])
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does the macos10.15 come from here? Does it always pick the SDK version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it comes from the SDKSettings's:

"Version": "10.15",

})
}

// Check -clang-target is handled correctly with the MacCatalyst remap.
try withTemporaryDirectory { path in
let main = path.appending(component: "Foo.swift")
try localFileSystem.writeFileContents(main) {
$0 <<< "import Swift"
}
var driver = try Driver(args: ["swiftc", "-explicit-module-build",
"-target", "arm64e-apple-ios13.0-macabi",
"-sdk", sdkRoot.pathString,
main.pathString])
guard driver.isFrontendArgSupported(.clangTarget) else {
throw XCTSkip("Skipping: compiler does not support '-clang-target'")
}
let plannedJobs = try driver.planBuild()
XCTAssertTrue(plannedJobs.contains { job in
job.commandLine.contains(subsequence: [.flag("-clang-target"), .flag("arm64-apple-ios13.0")])
job.commandLine.contains(subsequence: [.flag("-clang-target"), .flag("arm64e-apple-ios13.3-macabi")])
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly here, are we remapping from the SDK version and not from the driver's -target flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For -clang-target, yes.
First added in #1274.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah interesting, thanks for the clarification!

})
}

// Check -disable-clang-target works
try withTemporaryDirectory { path in
let main = path.appending(component: "Foo.swift")
Expand All @@ -3775,7 +3795,7 @@ final class SwiftDriverTests: XCTestCase {
}
var driver = try Driver(args: ["swiftc", "-disable-clang-target",
"-explicit-module-build",
"-target", "arm64-apple-ios14.0",
"-target", "arm64-apple-macos10.14",
"-sdk", sdkRoot.pathString,
main.pathString])
guard driver.isFrontendArgSupported(.clangTarget) else {
Expand Down