Skip to content

Commit 54c7e19

Browse files
authored
Merge pull request #33139 from nkcsgexi/move-sdk-version-to-platforms
Front-end: sink SDK version implementation to lib/Basic. NFC
2 parents ff82551 + cc8d27c commit 54c7e19

File tree

3 files changed

+61
-50
lines changed

3 files changed

+61
-50
lines changed

include/swift/Basic/Platform.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/Basic/LLVM.h"
1717
#include "swift/Config.h"
1818
#include "llvm/ADT/StringRef.h"
19+
#include "clang/Driver/DarwinSDKInfo.h"
1920

2021
namespace llvm {
2122
class Triple;
@@ -106,6 +107,10 @@ namespace swift {
106107
/// LLVM target triple.
107108
Optional<llvm::VersionTuple>
108109
getSwiftRuntimeCompatibilityVersionForTarget(const llvm::Triple &Triple);
110+
111+
/// Retrieve the target SDK version for the given SDKInfo and target triple.
112+
llvm::VersionTuple getTargetSDKVersion(clang::driver::DarwinSDKInfo &SDKInfo,
113+
const llvm::Triple &triple);
109114
} // end namespace swift
110115

111116
#endif // SWIFT_BASIC_PLATFORM_H

lib/Basic/Platform.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,58 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
435435

436436
return None;
437437
}
438+
439+
440+
/// Remap the given version number via the version map, or produce \c None if
441+
/// there is no mapping for this version.
442+
static Optional<llvm::VersionTuple> remapVersion(
443+
const llvm::StringMap<llvm::VersionTuple> &versionMap,
444+
llvm::VersionTuple version) {
445+
// The build number is never used in the lookup.
446+
version = version.withoutBuild();
447+
448+
// Look for this specific version.
449+
auto known = versionMap.find(version.getAsString());
450+
if (known != versionMap.end())
451+
return known->second;
452+
453+
// If an extra ".0" was specified (in the subminor version), drop that
454+
// and look again.
455+
if (!version.getSubminor() || *version.getSubminor() != 0)
456+
return None;
457+
458+
version = llvm::VersionTuple(version.getMajor(), *version.getMinor());
459+
known = versionMap.find(version.getAsString());
460+
if (known != versionMap.end())
461+
return known->second;
462+
463+
// If another extra ".0" wa specified (in the minor version), drop that
464+
// and look again.
465+
if (!version.getMinor() || *version.getMinor() != 0)
466+
return None;
467+
468+
version = llvm::VersionTuple(version.getMajor());
469+
known = versionMap.find(version.getAsString());
470+
if (known != versionMap.end())
471+
return known->second;
472+
473+
return None;
474+
}
475+
476+
llvm::VersionTuple
477+
swift::getTargetSDKVersion(clang::driver::DarwinSDKInfo &SDKInfo,
478+
const llvm::Triple &triple) {
479+
// Retrieve the SDK version.
480+
auto SDKVersion = SDKInfo.getVersion();
481+
482+
// For the Mac Catalyst environment, we have a macOS SDK with a macOS
483+
// SDK version. Map that to the corresponding iOS version number to pass
484+
// down to the linker.
485+
if (tripleIsMacCatalystEnvironment(triple)) {
486+
return remapVersion(
487+
SDKInfo.getVersionMap().MacOS2iOSMacMapping, SDKVersion)
488+
.getValueOr(llvm::VersionTuple(0, 0, 0));
489+
}
490+
491+
return SDKVersion;
492+
}

lib/Driver/DarwinToolChains.cpp

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -501,60 +501,11 @@ toolchains::Darwin::addProfileGenerationArgs(ArgStringList &Arguments,
501501
}
502502
}
503503

504-
/// Remap the given version number via the version map, or produce \c None if
505-
/// there is no mapping for this version.
506-
static Optional<llvm::VersionTuple> remapVersion(
507-
const llvm::StringMap<llvm::VersionTuple> &versionMap,
508-
llvm::VersionTuple version) {
509-
// The build number is never used in the lookup.
510-
version = version.withoutBuild();
511-
512-
// Look for this specific version.
513-
auto known = versionMap.find(version.getAsString());
514-
if (known != versionMap.end())
515-
return known->second;
516-
517-
// If an extra ".0" was specified (in the subminor version), drop that
518-
// and look again.
519-
if (!version.getSubminor() || *version.getSubminor() != 0)
520-
return None;
521-
522-
version = llvm::VersionTuple(version.getMajor(), *version.getMinor());
523-
known = versionMap.find(version.getAsString());
524-
if (known != versionMap.end())
525-
return known->second;
526-
527-
// If another extra ".0" wa specified (in the minor version), drop that
528-
// and look again.
529-
if (!version.getMinor() || *version.getMinor() != 0)
530-
return None;
531-
532-
version = llvm::VersionTuple(version.getMajor());
533-
known = versionMap.find(version.getAsString());
534-
if (known != versionMap.end())
535-
return known->second;
536-
537-
return None;
538-
}
539-
540504
Optional<llvm::VersionTuple>
541505
toolchains::Darwin::getTargetSDKVersion(const llvm::Triple &triple) const {
542506
if (!SDKInfo)
543507
return None;
544-
545-
// Retrieve the SDK version.
546-
auto SDKVersion = SDKInfo->getVersion();
547-
548-
// For the Mac Catalyst environment, we have a macOS SDK with a macOS
549-
// SDK version. Map that to the corresponding iOS version number to pass
550-
// down to the linker.
551-
if (tripleIsMacCatalystEnvironment(triple)) {
552-
return remapVersion(
553-
SDKInfo->getVersionMap().MacOS2iOSMacMapping, SDKVersion)
554-
.getValueOr(llvm::VersionTuple(0, 0, 0));
555-
}
556-
557-
return SDKVersion;
508+
return swift::getTargetSDKVersion(*SDKInfo, triple);
558509
}
559510

560511
void

0 commit comments

Comments
 (0)