Skip to content

Commit 688dd23

Browse files
committed
Define __SWIFT_ATTR_SUPPORTS_MACROS when the MacrosOnImports features is available
1 parent 70980b9 commit 688dd23

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,11 @@ void importer::getNormalInvocationArguments(
622622
if (clangSupportsPragmaAttributeWithSwiftAttr())
623623
invocationArgStrs.push_back("-D__SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS=1");
624624

625+
// Indicate that the compiler will respect macros applied to imported
626+
// declarations via '__attribute__((swift_attr("@...")))'.
627+
if (LangOpts.hasFeature(Feature::MacrosOnImports))
628+
invocationArgStrs.push_back("-D__SWIFT_ATTR_SUPPORTS_MACROS=1");
629+
625630
if (triple.isXROS()) {
626631
// FIXME: This is a gnarly hack until some macros get adjusted in the SDK.
627632
invocationArgStrs.insert(invocationArgStrs.end(), {
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
void async_divide(double x, double y, void (* _Nonnull completionHandler)(double x))
2-
__attribute__((swift_attr("@macro_library.AddAsync")));
1+
#if __SWIFT_ATTR_SUPPORTS_MACROS
2+
#define ADD_ASYNC __attribute__((swift_attr("@macro_library.AddAsync")))
3+
#else
4+
#define ADD_ASYNC
5+
#endif
6+
7+
void async_divide(double x, double y, void (* _Nonnull completionHandler)(double x)) ADD_ASYNC;
38

49
typedef struct SlowComputer {
510
} SlowComputer;
611

712
void computer_divide(const SlowComputer *computer, double x, double y, void (* _Nonnull completionHandler)(double x))
8-
__attribute__((swift_attr("@macro_library.AddAsync")))
13+
ADD_ASYNC
914
__attribute__((swift_name("SlowComputer.divide(self:_:_:completionHandler:)")));
1015

1116

@@ -14,7 +19,7 @@ void computer_divide(const SlowComputer *computer, double x, double y, void (* _
1419

1520
@interface Computer: NSObject
1621
-(void)multiply:(double)x by:(double)y afterDone:(void (^ _Nonnull)(double x))afterDone
17-
__attribute__((swift_attr("@macro_library.AddAsync")))
22+
ADD_ASYNC
1823
__attribute__((swift_async(none)));
1924
@end
2025
#endif

0 commit comments

Comments
 (0)