Skip to content

Commit 4f93870

Browse files
authored
Merge pull request #534 from hyp/maccatalyst_driver
Upstream macCatalyst driver support
2 parents dfbcbcc + df42f69 commit 4f93870

15 files changed

+318
-75
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ def warn_invalid_ios_deployment_target : Warning<
206206
"invalid iOS deployment version '%0', iOS 10 is the maximum deployment "
207207
"target for 32-bit targets">, InGroup<InvalidIOSDeploymentTarget>,
208208
DefaultError;
209+
def err_invalid_macos_32bit_deployment_target : Error<
210+
"32-bit targets are not supported when building for Mac Catalyst">;
209211
def err_drv_conflicting_deployment_targets : Error<
210212
"conflicting deployment targets, both '%0' and '%1' are present in environment">;
211213
def err_arc_unsupported_on_runtime : Error<

clang/include/clang/Driver/DarwinSDKInfo.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_CLANG_DRIVER_DARWIN_SDK_INFO_H
1111

1212
#include "clang/Basic/LLVM.h"
13+
#include "llvm/ADT/StringMap.h"
1314
#include "llvm/Support/Error.h"
1415
#include "llvm/Support/VersionTuple.h"
1516
#include "llvm/Support/VirtualFileSystem.h"
@@ -20,12 +21,26 @@ namespace driver {
2021
/// The information about the darwin SDK that was used during this compilation.
2122
class DarwinSDKInfo {
2223
public:
24+
/// Represents the mapping between macOS and IosMac versions.
25+
class IOSMacVersionMapping {
26+
public:
27+
VersionTuple getiOSMacVersionForMacOSVersion();
28+
29+
llvm::StringMap<VersionTuple> MacOS2iOSMacMapping;
30+
llvm::StringMap<VersionTuple> IosMac2macOSMapping;
31+
};
32+
2333
DarwinSDKInfo(llvm::VersionTuple Version) : Version(Version) {}
2434

2535
const llvm::VersionTuple &getVersion() const { return Version; }
2636

37+
IOSMacVersionMapping &getVersionMap() { return VersionMap; }
38+
39+
const IOSMacVersionMapping &getVersionMap() const { return VersionMap; }
40+
2741
private:
2842
llvm::VersionTuple Version;
43+
IOSMacVersionMapping VersionMap;
2944
};
3045

3146
/// Parse the SDK information from the SDKSettings.json file.

clang/lib/Driver/DarwinSDKInfo.cpp

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,42 @@
1515
using namespace clang::driver;
1616
using namespace clang;
1717

18+
static Optional<DarwinSDKInfo>
19+
parseDarwinSDKSettingsJSON(const llvm::json::Object *Obj) {
20+
auto VersionString = Obj->getString("Version");
21+
if (!VersionString)
22+
return None;
23+
VersionTuple Version;
24+
if (Version.tryParse(*VersionString))
25+
return None;
26+
DarwinSDKInfo SDKInfo(Version);
27+
if (const auto *VM = Obj->getObject("VersionMap")) {
28+
auto parseVersionMap = [](const llvm::json::Object &Obj,
29+
llvm::StringMap<VersionTuple> &Mapping) -> bool {
30+
for (const auto &KV : Obj) {
31+
if (auto Val = KV.getSecond().getAsString()) {
32+
llvm::VersionTuple Version;
33+
if (Version.tryParse(*Val))
34+
return true;
35+
Mapping[KV.getFirst()] = Version;
36+
}
37+
}
38+
return false;
39+
};
40+
if (const auto *Mapping = VM->getObject("macOS_iOSMac")) {
41+
if (parseVersionMap(*Mapping,
42+
SDKInfo.getVersionMap().MacOS2iOSMacMapping))
43+
return None;
44+
}
45+
if (const auto *Mapping = VM->getObject("iOSMac_macOS")) {
46+
if (parseVersionMap(*Mapping,
47+
SDKInfo.getVersionMap().IosMac2macOSMapping))
48+
return None;
49+
}
50+
}
51+
return std::move(SDKInfo);
52+
}
53+
1854
Expected<Optional<DarwinSDKInfo>>
1955
driver::parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath) {
2056
llvm::SmallString<256> Filepath = SDKRootPath;
@@ -31,12 +67,8 @@ driver::parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath) {
3167
return Result.takeError();
3268

3369
if (const auto *Obj = Result->getAsObject()) {
34-
auto VersionString = Obj->getString("Version");
35-
if (VersionString) {
36-
VersionTuple Version;
37-
if (!Version.tryParse(*VersionString))
38-
return DarwinSDKInfo(Version);
39-
}
70+
if (auto SDKInfo = parseDarwinSDKSettingsJSON(Obj))
71+
return std::move(SDKInfo);
4072
}
4173
return llvm::make_error<llvm::StringError>("invalid SDKSettings.json",
4274
llvm::inconvertibleErrorCode());

0 commit comments

Comments
 (0)