From 05ca21cd313d6ada5dc33cf56ed348cb47f37810 Mon Sep 17 00:00:00 2001 From: Owen Voorhees Date: Thu, 11 Dec 2025 12:27:55 -0800 Subject: [PATCH] API digester support for Xcc options --- include/swift/Option/Options.td | 2 +- lib/DriverTool/swift_api_digester_main.cpp | 7 +++++++ lib/Option/features.json | 3 +++ test/api-digester/Inputs/XccTest/XccTest.h | 9 +++++++++ test/api-digester/Inputs/XccTest/module.modulemap | 4 ++++ test/api-digester/Xcc-preprocessor-define.swift | 13 +++++++++++++ 6 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/api-digester/Inputs/XccTest/XccTest.h create mode 100644 test/api-digester/Inputs/XccTest/module.modulemap create mode 100644 test/api-digester/Xcc-preprocessor-define.swift diff --git a/include/swift/Option/Options.td b/include/swift/Option/Options.td index c9ae020129f97..abc06ad0de710 100644 --- a/include/swift/Option/Options.td +++ b/include/swift/Option/Options.td @@ -1556,7 +1556,7 @@ def Xfrontend : Separate<["-"], "Xfrontend">, Flags<[HelpHidden]>, def Xcc : Separate<["-"], "Xcc">, Flags<[FrontendOption, SwiftSymbolGraphExtractOption, - SwiftSynthesizeInterfaceOption]>, + SwiftSynthesizeInterfaceOption, SwiftAPIDigesterOption]>, MetaVarName<"">, HelpText<"Pass to the C/C++/Objective-C compiler">; diff --git a/lib/DriverTool/swift_api_digester_main.cpp b/lib/DriverTool/swift_api_digester_main.cpp index 777d141c6ed44..ef778c59ca005 100644 --- a/lib/DriverTool/swift_api_digester_main.cpp +++ b/lib/DriverTool/swift_api_digester_main.cpp @@ -2273,6 +2273,7 @@ class SwiftAPIDigesterInvocation { std::string ResourceDir; std::string ModuleCachePath; bool DisableFailOnError; + std::vector ClangImporterArgs; public: SwiftAPIDigesterInvocation(const std::string &ExecPath) @@ -2375,6 +2376,7 @@ class SwiftAPIDigesterInvocation { ParsedArgs.getAllArgValues(OPT_use_interface_for_module); ResourceDir = ParsedArgs.getLastArgValue(OPT_resource_dir).str(); ModuleCachePath = ParsedArgs.getLastArgValue(OPT_module_cache_path).str(); + ClangImporterArgs = ParsedArgs.getAllArgValues(OPT_Xcc); DebugMapping = ParsedArgs.hasArg(OPT_debug_mapping); DisableFailOnError = ParsedArgs.hasArg(OPT_disable_fail_on_error); @@ -2456,6 +2458,11 @@ class SwiftAPIDigesterInvocation { InitInvoke.getLangOptions().Target.isOSDarwin(); InitInvoke.getClangImporterOptions().ModuleCachePath = ModuleCachePath; + // Pass -Xcc arguments to the Clang importer + for (const auto &arg : ClangImporterArgs) { + InitInvoke.getClangImporterOptions().ExtraArgs.push_back(arg); + } + if (!SwiftVersion.empty()) { using version::Version; bool isValid = false; diff --git a/lib/Option/features.json b/lib/Option/features.json index 7d521787a4dd8..554868bb3b4f9 100644 --- a/lib/Option/features.json +++ b/lib/Option/features.json @@ -53,6 +53,9 @@ }, { "name": "internal-import-bridging-header" + }, + { + "name": "api-digester-Xcc" } ] } diff --git a/test/api-digester/Inputs/XccTest/XccTest.h b/test/api-digester/Inputs/XccTest/XccTest.h new file mode 100644 index 0000000000000..bd571ae5a2120 --- /dev/null +++ b/test/api-digester/Inputs/XccTest/XccTest.h @@ -0,0 +1,9 @@ +@import ObjectiveC; + +#ifdef MY_MACRO +@interface Hidden : NSObject +@end +#endif + +@interface NotHidden : NSObject +@end diff --git a/test/api-digester/Inputs/XccTest/module.modulemap b/test/api-digester/Inputs/XccTest/module.modulemap new file mode 100644 index 0000000000000..f51c5875e1452 --- /dev/null +++ b/test/api-digester/Inputs/XccTest/module.modulemap @@ -0,0 +1,4 @@ +module XccTest { + header "XccTest.h" + export * +} diff --git a/test/api-digester/Xcc-preprocessor-define.swift b/test/api-digester/Xcc-preprocessor-define.swift new file mode 100644 index 0000000000000..ffb34bd9569c0 --- /dev/null +++ b/test/api-digester/Xcc-preprocessor-define.swift @@ -0,0 +1,13 @@ +// REQUIRES: VENDOR=apple + +// RUN: %empty-directory(%t) +// RUN: %empty-directory(%t.module-cache) + +// RUN: %api-digester -dump-sdk -module XccTest -o %t.with-define.json -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %S/Inputs/XccTest -Xcc -DMY_MACRO +// RUN: %api-digester -dump-sdk -module XccTest -o %t.without-define.json -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %S/Inputs/XccTest + +// RUN: grep -q "Hidden" %t.with-define.json +// RUN: grep -q "NotHidden" %t.with-define.json + +// RUN: not grep -q "Hidden" %t.without-define.json +// RUN: grep -q "NotHidden" %t.without-define.json \ No newline at end of file