From b73fd8eff7de70492e5ec819547621a5b52967cf Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Thu, 16 Jan 2025 15:19:23 -0800 Subject: [PATCH 1/2] [cxx-interop] Workaround compiler error when importing AppKit/UIKit with C++ interop The AppKit/UIKit overlay refers to symbols declared via NS_OPTIONS macro, which is causing issues in C++ language mode due to the macro definition being different. This teaches the module interface loader to drop the C++ interop flag when rebuilding the AppKit and UIKit overlay from its interface. This is the same fix as #78636, but for different modules. rdar://143033209 (cherry picked from commit 7323a752b6d7124280ce1059a617b3f418f690a1) --- lib/Frontend/ModuleInterfaceLoader.cpp | 5 ++++- .../Cxx/objc-correctness/appkit-uikit.swift | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/Interop/Cxx/objc-correctness/appkit-uikit.swift diff --git a/lib/Frontend/ModuleInterfaceLoader.cpp b/lib/Frontend/ModuleInterfaceLoader.cpp index d980c72ca6092..281b76d2feebb 100644 --- a/lib/Frontend/ModuleInterfaceLoader.cpp +++ b/lib/Frontend/ModuleInterfaceLoader.cpp @@ -2195,7 +2195,10 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName, // interop enabled by the Swift CI because it uses an old host SDK. // FIXME: Hack for CoreGraphics.swiftmodule, which cannot be rebuilt because // of a CF_OPTIONS bug (rdar://142762174). - if (moduleName == "Darwin" || moduleName == "CoreGraphics") { + // FIXME: Hack for AppKit.swiftmodule / UIKit.swiftmodule, which cannot be + // rebuilt because of an NS_OPTIONS bug (rdar://143033209) + if (moduleName == "Darwin" || moduleName == "CoreGraphics" + || moduleName == "AppKit" || moduleName == "UIKit") { subInvocation.getLangOptions().EnableCXXInterop = false; subInvocation.getLangOptions().cxxInteropCompatVersion = {}; BuildArgs.erase(llvm::remove_if(BuildArgs, diff --git a/test/Interop/Cxx/objc-correctness/appkit-uikit.swift b/test/Interop/Cxx/objc-correctness/appkit-uikit.swift new file mode 100644 index 0000000000000..4bde2ab69d9ca --- /dev/null +++ b/test/Interop/Cxx/objc-correctness/appkit-uikit.swift @@ -0,0 +1,16 @@ +// RUN: %target-swift-frontend -typecheck -verify -I %S/Inputs -cxx-interoperability-mode=default %s + +// REQUIRES: objc_interop +// REQUIRES: VENDOR=apple + +#if canImport(AppKit) +import AppKit + +var _: AttributeScopes.AppKitAttributes.UnderlineStyleAttribute! = nil + +#elseif canImport(UIKit) +import UIKit + +var _: AttributeScopes.AppKitAttributes.UnderlineStyleAttribute! = nil + +#endif From 4db47be6e762889c9a90c3750a3c9a5e9bdae26d Mon Sep 17 00:00:00 2001 From: Erik Eckstein Date: Mon, 20 Jan 2025 12:38:40 +0100 Subject: [PATCH 2/2] tests: fix Interop/Cxx/objc-correctness/appkit-uikit.swift for iOS (cherry picked from commit 34a68736ac6d171c78434374f8603915bb1b77f4) --- test/Interop/Cxx/objc-correctness/appkit-uikit.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Interop/Cxx/objc-correctness/appkit-uikit.swift b/test/Interop/Cxx/objc-correctness/appkit-uikit.swift index 4bde2ab69d9ca..2569d66f97cb7 100644 --- a/test/Interop/Cxx/objc-correctness/appkit-uikit.swift +++ b/test/Interop/Cxx/objc-correctness/appkit-uikit.swift @@ -2,6 +2,7 @@ // REQUIRES: objc_interop // REQUIRES: VENDOR=apple +// REQUIRES: OS=macosx || OS=ios #if canImport(AppKit) import AppKit @@ -11,6 +12,6 @@ var _: AttributeScopes.AppKitAttributes.UnderlineStyleAttribute! = nil #elseif canImport(UIKit) import UIKit -var _: AttributeScopes.AppKitAttributes.UnderlineStyleAttribute! = nil +var _: AttributeScopes.UIKitAttributes.UnderlineStyleAttribute! = nil #endif