Skip to content

[CxxInterop] Change C++ interop header ordering #67976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2023
Merged
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
9 changes: 4 additions & 5 deletions lib/PrintAsClang/ClangSyntaxPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,15 @@ void ClangSyntaxPrinter::printPrimaryCxxTypeName(

void ClangSyntaxPrinter::printIncludeForShimHeader(StringRef headerName) {
printIgnoredDiagnosticBlock("non-modular-include-in-framework-module", [&] {
os << "// Allow user to find the header using additional include paths\n";
os << "#if __has_include(<swiftToCxx/" << headerName << ">)\n";
os << "#include <swiftToCxx/" << headerName << ">\n";
os << "// Look for the C++ interop support header relative to clang's "
"resource dir:\n";
os << "// "
"'<toolchain>/usr/lib/clang/<version>/include/../../../swift/"
"swiftToCxx'.\n";
os << "#if __has_include(<../../../swift/swiftToCxx/" << headerName
os << "#elif __has_include(<../../../swift/swiftToCxx/" << headerName
<< ">)\n";
os << "#include <../../../swift/swiftToCxx/" << headerName << ">\n";
os << "#elif __has_include(<../../../../../lib/swift/swiftToCxx/"
Expand All @@ -404,10 +407,6 @@ void ClangSyntaxPrinter::printIncludeForShimHeader(StringRef headerName) {
"swift/swiftToCxx'.\n";
os << "#include <../../../../../lib/swift/swiftToCxx/" << headerName
<< ">\n";
os << "// Alternatively, allow user to find the header using additional "
"include path into '<toolchain>/lib/swift'.\n";
os << "#elif __has_include(<swiftToCxx/" << headerName << ">)\n";
os << "#include <swiftToCxx/" << headerName << ">\n";
os << "#endif\n";
});
}
Expand Down
25 changes: 14 additions & 11 deletions test/Interop/SwiftToCxx/stdlib/swift-stdlib-in-cxx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,19 @@
// CHECK-EMPTY:
// CHECK-NEXT: #endif
// CHECK-NEXT: #define SWIFT_CXX_INTEROP_STRING_MIXIN

// CHECK-NEXT: #pragma clang diagnostic push
// CHECK-NEXT: #pragma clang diagnostic ignored "-Wnon-modular-include-in-framework-module"
// CHECK-NEXT: // Allow user to find the header using additional include paths
// CHECK-NEXT: #if __has_include(<swiftToCxx/_SwiftStdlibCxxOverlay.h>)
// CHECK-NEXT: #include <swiftToCxx/_SwiftStdlibCxxOverlay.h>
// CHECK-NEXT: // Look for the C++ interop support header relative to clang's resource dir:
// CHECK-NEXT: // '<toolchain>/usr/lib/clang/<version>/include/../../../swift/swiftToCxx'.
// CHECK-NEXT: #if __has_include(<../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
// CHECK-NEXT: // '<toolchain>/usr/lib/clang/<version>/include/../../../swift/swiftToCxx'.
// CHECK-NEXT: #elif __has_include(<../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
// CHECK-NEXT: #include <../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>
// CHECK-NEXT: #elif __has_include(<../../../../../lib/swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
// CHECK-NEXT: #include <../../../../../lib/swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>
// CHECK-NEXT: // Alternatively, allow user to find the header using additional include path into '<toolchain>/lib/swift'.
// CHECK-NEXT: #elif __has_include(<swiftToCxx/_SwiftStdlibCxxOverlay.h>)
// CHECK-NEXT: #include <swiftToCxx/_SwiftStdlibCxxOverlay.h>
// CHECK-NEXT: #endif
// CHECK-NEXT: #pragma clang diagnostic pop
// CHECK-NEXT: private:
Expand All @@ -129,14 +130,16 @@

// CHECK: #pragma clang diagnostic push
// CHECK: #pragma clang diagnostic ignored "-Wnon-modular-include-in-framework-module"
// CHECK: #if __has_include(<../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
// CHECK-NEXT: // Allow user to find the header using additional include paths
// CHECK-NEXT: #if __has_include(<swiftToCxx/_SwiftStdlibCxxOverlay.h>)
// CHECK-NEXT: #include <swiftToCxx/_SwiftStdlibCxxOverlay.h>
// CHECK-NEXT: // Look for the C++ interop support header relative to clang's resource dir:
// CHECK-NEXT: // '<toolchain>/usr/lib/clang/<version>/include/../../../swift/swiftToCxx'.
// CHECK-NEXT: #elif __has_include(<../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
// CHECK-NEXT: #include <../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>
// CHECK-NEXT: #elif __has_include(<../../../../../lib/swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
// CHECK-NEXT: #include <../../../../../lib/swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>
// CHECK-NEXT: // Alternatively, allow user to find the header using additional include path into '<toolchain>/lib/swift'.
// CHECK-NEXT: #elif __has_include(<swiftToCxx/_SwiftStdlibCxxOverlay.h>)
// CHECK-NEXT: #include <swiftToCxx/_SwiftStdlibCxxOverlay.h>
// CHECK-NEXT: #endif
// CHECK-NEXTZ: #pragma clang diagnostic pop

Expand Down
12 changes: 6 additions & 6 deletions test/PrintAsCxx/empty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@
// CHECK-NEXT: #if defined(__cplusplus)
// CHECK-NEXT: #pragma clang diagnostic push
// CHECK-NEXT: #pragma clang diagnostic ignored "-Wnon-modular-include-in-framework-module"
// CHECK-NEXT: // Allow user to find the header using additional include paths
// CHECK-NEXT: #if __has_include(<swiftToCxx/_SwiftCxxInteroperability.h>)
// CHECK-NEXT: #include <swiftToCxx/_SwiftCxxInteroperability.h>
// CHECK-NEXT: // Look for the C++ interop support header relative to clang's resource dir:
// CHECK-NEXT: // '<toolchain>/usr/lib/clang/<version>/include/../../../swift/swiftToCxx'.
// CHECK-NEXT: #if __has_include(<../../../swift/swiftToCxx/_SwiftCxxInteroperability.h>)
// CHECK-NEXT: // '<toolchain>/usr/lib/clang/<version>/include/../../../swift/swiftToCxx'.
// CHECK-NEXT: #elif __has_include(<../../../swift/swiftToCxx/_SwiftCxxInteroperability.h>)
// CHECK-NEXT: #include <../../../swift/swiftToCxx/_SwiftCxxInteroperability.h>
// CHECK-NEXT: #elif __has_include(<../../../../../lib/swift/swiftToCxx/_SwiftCxxInteroperability.h>)
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
// CHECK-NEXT: #include <../../../../../lib/swift/swiftToCxx/_SwiftCxxInteroperability.h>
// CHECK-NEXT: // Alternatively, allow user to find the header using additional include path into '<toolchain>/lib/swift'.
// CHECK-NEXT: #elif __has_include(<swiftToCxx/_SwiftCxxInteroperability.h>)
// CHECK-NEXT: #include <swiftToCxx/_SwiftCxxInteroperability.h>
// CHECK-NEXT: #endif
// CHECK-NEXT: #pragma clang diagnostic pop
// CHECK-NEXT: #if __has_feature(objc_modules)
Expand Down