https://github.com/ian-twilightcoder updated 
https://github.com/llvm/llvm-project/pull/177748

>From 95198fb1e280eb9e347b0884fa8857fad77b9da7 Mon Sep 17 00:00:00 2001
From: Alex Lorenz <[email protected]>
Date: Sat, 24 Jan 2026 00:44:28 -0800
Subject: [PATCH] macCatalyst: add SDKSettings.json as a dependency file if its
 potentially needed by the compiler

---
 clang/include/clang/Basic/DarwinSDKInfo.h          | 12 +++++++++---
 clang/lib/Basic/DarwinSDKInfo.cpp                  |  8 +++++---
 clang/lib/Driver/ToolChains/Darwin.cpp             | 14 +++++++++++++-
 .../darwin-depfile-sdksettings-maccatalyst.m       |  4 ++++
 clang/unittests/Basic/DarwinSDKInfoTest.cpp        | 10 +++++-----
 5 files changed, 36 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/Driver/darwin-depfile-sdksettings-maccatalyst.m

diff --git a/clang/include/clang/Basic/DarwinSDKInfo.h 
b/clang/include/clang/Basic/DarwinSDKInfo.h
index 54e4df5988526..ae44b953e1e4c 100644
--- a/clang/include/clang/Basic/DarwinSDKInfo.h
+++ b/clang/include/clang/Basic/DarwinSDKInfo.h
@@ -181,17 +181,21 @@ class DarwinSDKInfo {
   using PlatformInfoStorageType = SmallVector<SDKPlatformInfo, 2>;
 
   DarwinSDKInfo(
-      VersionTuple Version, VersionTuple MaximumDeploymentTarget,
+      std::string FilePath, VersionTuple Version,
+      VersionTuple MaximumDeploymentTarget,
       PlatformInfoStorageType PlatformInfos,
       llvm::DenseMap<OSEnvPair::StorageType,
                      std::optional<RelatedTargetVersionMapping>>
           VersionMappings =
               llvm::DenseMap<OSEnvPair::StorageType,
                              std::optional<RelatedTargetVersionMapping>>())
-      : Version(Version), MaximumDeploymentTarget(MaximumDeploymentTarget),
+      : FilePath(FilePath), Version(Version),
+        MaximumDeploymentTarget(MaximumDeploymentTarget),
         PlatformInfos(std::move(PlatformInfos)),
         VersionMappings(std::move(VersionMappings)) {}
 
+  StringRef getFilePath() const { return FilePath; }
+
   const llvm::VersionTuple &getVersion() const { return Version; }
 
   const SDKPlatformInfo &getCanonicalPlatformInfo() const {
@@ -224,9 +228,11 @@ class DarwinSDKInfo {
   }
 
   static std::optional<DarwinSDKInfo>
-  parseDarwinSDKSettingsJSON(const llvm::json::Object *Obj);
+  parseDarwinSDKSettingsJSON(std::string FilePath,
+                             const llvm::json::Object *Obj);
 
 private:
+  std::string FilePath;
   VersionTuple Version;
   VersionTuple MaximumDeploymentTarget;
   PlatformInfoStorageType PlatformInfos;
diff --git a/clang/lib/Basic/DarwinSDKInfo.cpp 
b/clang/lib/Basic/DarwinSDKInfo.cpp
index b55ffd1c39a86..4fa2febe0f650 100644
--- a/clang/lib/Basic/DarwinSDKInfo.cpp
+++ b/clang/lib/Basic/DarwinSDKInfo.cpp
@@ -176,7 +176,8 @@ static std::optional<VersionTuple> getVersionKey(const 
llvm::json::Object &Obj,
 }
 
 std::optional<DarwinSDKInfo>
-DarwinSDKInfo::parseDarwinSDKSettingsJSON(const llvm::json::Object *Obj) {
+DarwinSDKInfo::parseDarwinSDKSettingsJSON(std::string FilePath,
+                                          const llvm::json::Object *Obj) {
   auto Version = getVersionKey(*Obj, "Version");
   if (!Version)
     return std::nullopt;
@@ -226,7 +227,7 @@ DarwinSDKInfo::parseDarwinSDKSettingsJSON(const 
llvm::json::Object *Obj) {
     }
   }
 
-  return DarwinSDKInfo(std::move(*Version),
+  return DarwinSDKInfo(std::move(FilePath), std::move(*Version),
                        std::move(*MaximumDeploymentVersion),
                        std::move(PlatformInfos), std::move(VersionMappings));
 }
@@ -247,7 +248,8 @@ clang::parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, 
StringRef SDKRootPath) {
     return Result.takeError();
 
   if (const auto *Obj = Result->getAsObject()) {
-    if (auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON(Obj))
+    if (auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON(
+            Filepath.str().str(), Obj))
       return std::move(SDKInfo);
   }
   return llvm::make_error<llvm::StringError>("invalid SDKSettings.json",
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index fb75739360328..8c6576364c419 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1917,7 +1917,7 @@ struct DarwinPlatform {
     StringRef PlatformPrefix =
         (Platform == DarwinPlatformKind::DriverKit) ? "/System/DriverKit" : "";
     return DarwinSDKInfo(
-        getOSVersion(), /*MaximumDeploymentTarget=*/
+        "", getOSVersion(), /*MaximumDeploymentTarget=*/
         VersionTuple(getOSVersion().getMajor(), 0, 99),
         {DarwinSDKInfo::SDKPlatformInfo(llvm::Triple::Apple, OS,
                                         llvm::Triple::UnknownEnvironment,
@@ -3289,6 +3289,18 @@ void Darwin::addClangTargetOptions(
 
   addClangCC1ASTargetOptions(DriverArgs, CC1Args);
 
+  if (SDKInfo) {
+    // Make the SDKSettings.json an explicit dependency for the compiler
+    // invocation, in case the compiler needs to read it to remap macCatalyst
+    // versions.
+    if ((isTargetMacCatalyst() || TargetVariantTriple) &&
+        !SDKInfo->getFilePath().empty()) {
+      SmallString<64> ExtraDepOpt("-fdepfile-entry=");
+      ExtraDepOpt += SDKInfo->getFilePath();
+      CC1Args.push_back(DriverArgs.MakeArgString(ExtraDepOpt));
+    }
+  }
+
   // Enable compatibility mode for NSItemProviderCompletionHandler in
   // Foundation/NSItemProvider.h.
   CC1Args.push_back("-fcompatibility-qualified-id-block-type-checking");
diff --git a/clang/test/Driver/darwin-depfile-sdksettings-maccatalyst.m 
b/clang/test/Driver/darwin-depfile-sdksettings-maccatalyst.m
new file mode 100644
index 0000000000000..12bccda94cb88
--- /dev/null
+++ b/clang/test/Driver/darwin-depfile-sdksettings-maccatalyst.m
@@ -0,0 +1,4 @@
+// RUN: %clang -target x86_64-apple-ios13.1-macabi -isysroot 
%S/Inputs/MacOSX10.15.sdk -c %s -### 2>&1 \
+// RUN:   | FileCheck %s
+
+// CHECK: -fdepfile-entry={{.*}}MacOSX10.15.sdk{{/|\\\\}}SDKSettings.json
diff --git a/clang/unittests/Basic/DarwinSDKInfoTest.cpp 
b/clang/unittests/Basic/DarwinSDKInfoTest.cpp
index 61b1b93dcb328..e2735a7a3e7d0 100644
--- a/clang/unittests/Basic/DarwinSDKInfoTest.cpp
+++ b/clang/unittests/Basic/DarwinSDKInfoTest.cpp
@@ -103,7 +103,7 @@ TEST(DarwinSDKInfo, PlatformPrefix) {
   SupportedTargets["driverkit"] = std::move(DriverKit);
   SDKSettings["SupportedTargets"] = std::move(SupportedTargets);
 
-  auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON(&SDKSettings);
+  auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON("", &SDKSettings);
   ASSERT_TRUE(SDKInfo);
   EXPECT_EQ(SDKInfo->getPlatformPrefix(Triple("arm64-apple-macos26.0")),
             "/System/macOSSupport");
@@ -133,7 +133,7 @@ TEST(DarwinSDKInfoTest, ParseAndTestMappingMacCatalyst) {
   MacOS2iOSMac["macOS_iOSMac"] = std::move(VersionMap);
   Obj["VersionMap"] = std::move(MacOS2iOSMac);
 
-  auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON(&Obj);
+  auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON("", &Obj);
   ASSERT_TRUE(SDKInfo);
   EXPECT_EQ(SDKInfo->getVersion(), VersionTuple(11, 0));
 
@@ -180,7 +180,7 @@ TEST(DarwinSDKInfoTest, ParseAndTestMappingIOSDerived) {
   IOSToTvOS["iOS_tvOS"] = std::move(VersionMap);
   Obj["VersionMap"] = std::move(IOSToTvOS);
 
-  auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON(&Obj);
+  auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON("", &Obj);
   ASSERT_TRUE(SDKInfo);
   EXPECT_EQ(SDKInfo->getVersion(), VersionTuple(15, 0));
 
@@ -226,7 +226,7 @@ TEST(DarwinSDKInfoTest, ParseAndTestMappingIOSDerived) {
 
 TEST(DarwinSDKInfoTest, MissingKeys) {
   llvm::json::Object Obj;
-  ASSERT_FALSE(DarwinSDKInfo::parseDarwinSDKSettingsJSON(&Obj));
+  ASSERT_FALSE(DarwinSDKInfo::parseDarwinSDKSettingsJSON("", &Obj));
   Obj["Version"] = "11.0";
-  ASSERT_FALSE(DarwinSDKInfo::parseDarwinSDKSettingsJSON(&Obj));
+  ASSERT_FALSE(DarwinSDKInfo::parseDarwinSDKSettingsJSON("", &Obj));
 }

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to