Skip to content

Commit 854bf59

Browse files
committed
[Driver] Add unversioned triple to the output of -print-target-info.
SwiftPM wants to use the unversioned triple to know where to put results. Vend this as part of -print-target-info.
1 parent 05f447c commit 854bf59

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

include/swift/Basic/Platform.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ namespace swift {
9191
/// llvm::Triple::normalize() would not affect it.
9292
llvm::Triple getTargetSpecificModuleTriple(const llvm::Triple &triple);
9393

94-
94+
/// Computes the target triple without version information.
95+
llvm::Triple getUnversionedTriple(const llvm::Triple &triple);
96+
9597
/// Get the Swift runtime version to deploy back to, given a deployment target expressed as an
9698
/// LLVM target triple.
9799
Optional<llvm::VersionTuple>

lib/Basic/Platform.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,20 @@ llvm::Triple swift::getTargetSpecificModuleTriple(const llvm::Triple &triple) {
342342
return triple;
343343
}
344344

345+
llvm::Triple swift::getUnversionedTriple(const llvm::Triple &triple) {
346+
StringRef unversionedOSName = triple.getOSName().take_until(llvm::isDigit);
347+
if (triple.getEnvironment()) {
348+
StringRef environment =
349+
llvm::Triple::getEnvironmentTypeName(triple.getEnvironment());
350+
351+
return llvm::Triple(triple.getArchName(), triple.getVendorName(),
352+
unversionedOSName, environment);
353+
}
354+
355+
return llvm::Triple(triple.getArchName(), triple.getVendorName(),
356+
unversionedOSName);
357+
}
358+
345359
Optional<llvm::VersionTuple>
346360
swift::getSwiftRuntimeCompatibilityVersionForTarget(
347361
const llvm::Triple &Triple) {

lib/FrontendTool/FrontendTool.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,10 @@ static void printTargetInfo(CompilerInvocation &invocation,
18801880
out.write_escaped(langOpts.Target.getTriple());
18811881
out << "\",\n";
18821882

1883+
out << " \"unversionedTriple\": \"";
1884+
out.write_escaped(getUnversionedTriple(langOpts.Target).getTriple());
1885+
out << "\",\n";
1886+
18831887
out << " \"moduleTriple\": \"";
18841888
out.write_escaped(getTargetSpecificModuleTriple(langOpts.Target).getTriple());
18851889
out << "\",\n";

test/Driver/print_target_info.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
// CHECK-IOS: "target": {
88
// CHECK-IOS: "triple": "arm64-apple-ios12.0",
9+
// CHECK-IOS: "unversionedTriple": "arm64-apple-ios",
910
// CHECK-IOS: "moduleTriple": "arm64-apple-ios",
1011
// CHECK-IOS: "swiftRuntimeCompatibilityVersion": "5.0",
1112
// CHECK-IOS: "librariesRequireRPath": true

test/Driver/print_target_info_macos.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77

88
// REQUIRES: OS=macosx
99

10-
// CHECK: "triple": "x86_64-apple-macosx
10+
// CHECK: "triple": "x86_64-apple-macosx10
11+
// CHECK: "unversionedTriple": "x86_64-apple-macosx"

0 commit comments

Comments
 (0)