Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ def Xfrontend : Separate<["-"], "Xfrontend">, Flags<[HelpHidden]>,

def Xcc : Separate<["-"], "Xcc">,
Flags<[FrontendOption, SwiftSymbolGraphExtractOption,
SwiftSynthesizeInterfaceOption]>,
SwiftSynthesizeInterfaceOption, SwiftAPIDigesterOption]>,
MetaVarName<"<arg>">,
HelpText<"Pass <arg> to the C/C++/Objective-C compiler">;

Expand Down
7 changes: 7 additions & 0 deletions lib/DriverTool/swift_api_digester_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,7 @@ class SwiftAPIDigesterInvocation {
std::string ResourceDir;
std::string ModuleCachePath;
bool DisableFailOnError;
std::vector<std::string> ClangImporterArgs;

public:
SwiftAPIDigesterInvocation(const std::string &ExecPath)
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions lib/Option/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
},
{
"name": "internal-import-bridging-header"
},
{
"name": "api-digester-Xcc"
}
]
}
9 changes: 9 additions & 0 deletions test/api-digester/Inputs/XccTest/XccTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import ObjectiveC;

#ifdef MY_MACRO
@interface Hidden : NSObject
@end
#endif

@interface NotHidden : NSObject
@end
4 changes: 4 additions & 0 deletions test/api-digester/Inputs/XccTest/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module XccTest {
header "XccTest.h"
export *
}
13 changes: 13 additions & 0 deletions test/api-digester/Xcc-preprocessor-define.swift
Original file line number Diff line number Diff line change
@@ -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