Skip to content

Commit 052c89d

Browse files
committed
ClangImporter: make bridging header more portable
`#import` on Windows is problematic at as the default behaviour in C/C++ mode is to be an import of a type library (COM feature). This can be adjusted by always enabling Objective-C interop on Windows, but the runtime is not always built with ObjC interop. Unfortunately, always using `#include` breaks semantics on Apple where some places rely on the include-once semantics of `#import`. For now, control the inclusion technique to be based on whether ObjC interop is enabled or not.
1 parent 611b0c9 commit 052c89d

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,12 @@ bool ClangImporter::importBridgingHeader(StringRef header, ModuleDecl *adapter,
13521352
return true;
13531353
}
13541354

1355-
llvm::SmallString<128> importLine{"#import \""};
1355+
llvm::SmallString<128> importLine;
1356+
if (Impl.SwiftContext.LangOpts.EnableObjCInterop)
1357+
importLine = "#import \"";
1358+
else
1359+
importLine = "#include \"";
1360+
13561361
importLine += header;
13571362
importLine += "\"\n";
13581363

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2+
#ifndef app_bridging_header_to_pch_h
3+
#define app_bridging_header_to_pch_h
4+
15
static inline int app_function(int x) {
26
return x + 27;
37
}
8+
9+
#endif
10+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
2+
#ifndef chained_unit_test_bridging_header_to_pch_h
3+
#define chained_unit_test_bridging_header_to_pch_h
4+
15
#include "app-bridging-header-to-pch.h"
26

37
static inline int unit_test_function(int x) {
48
return x + 28;
59
}
10+
11+
#endif
12+

0 commit comments

Comments
 (0)