Skip to content
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
37 changes: 37 additions & 0 deletions lib/PrintAsClang/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
set(datafiles
_SwiftCxxInteroperability.h
)

set(SWIFTLIB_DIR
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/swift")
set(output_dir "${SWIFTLIB_DIR}/swiftToCxx")

add_custom_command(
OUTPUT "${output_dir}"
COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${output_dir}")

set (outputs)

foreach(input ${datafiles})
set(source "${CMAKE_CURRENT_SOURCE_DIR}/${input}")
set(dest "${output_dir}/${input}")
add_custom_command(OUTPUT
"${output_dir}/${input}"
DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/${input}"
COMMAND
"${CMAKE_COMMAND}" "-E" "copy" "${source}" "${dest}")
list(APPEND outputs "${output_dir}/${input}")
endforeach()
list(APPEND outputs "${output_dir}")

add_custom_target("copy_swiftToCxx_shims"
DEPENDS "${output_dir}" "${outputs}"
COMMENT "Copying Swift to C++ shims to ${output_dir}")

swift_install_in_component(FILES ${datafiles}
DESTINATION "lib/swift/swiftToCxx"
COMPONENT compiler)

add_swift_host_library(swiftPrintAsClang STATIC
ClangSyntaxPrinter.cpp
Expand All @@ -17,4 +51,7 @@ target_link_libraries(swiftPrintAsClang PRIVATE
swiftIDE
swiftIRGen)

add_dependencies(swiftPrintAsClang
"copy_swiftToCxx_shims")

set_swift_llvm_is_available(swiftPrintAsClang)
16 changes: 9 additions & 7 deletions lib/PrintAsClang/PrintAsClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,16 @@ static void writePrologue(raw_ostream &out, ASTContext &ctx,
out << "#include <stdlib.h>\n";
out << "#include <new>\n";
out << "#include <type_traits>\n";
// FIXME: Look for the header in the SDK.
out << "// Look for the C++ interop support header relative to clang's resource dir:\n";
out << "// '<toolchain>/usr/lib/clang/<version>/include/../../../swift/shims'.\n";
out << "#if __has_include(<../../../swift/shims/_SwiftCxxInteroperability.h>)\n";
out << "#include <../../../swift/shims/_SwiftCxxInteroperability.h>\n";
out << "// Alternatively, allow user to find the header using additional include path into 'swift'.\n";
out << "#elif __has_include(<shims/_SwiftCxxInteroperability.h>)\n";
out << "#include <shims/_SwiftCxxInteroperability.h>\n";
out << "// '<toolchain>/usr/lib/clang/<version>/include/../../../swift/swiftToCxx'.\n";
out << "#if __has_include(<../../../swift/swiftToCxx/_SwiftCxxInteroperability.h>)\n";
out << "#include <../../../swift/swiftToCxx/_SwiftCxxInteroperability.h>\n";
out << "#elif __has_include(<../../../../lib/swift/swiftToCxx/_SwiftCxxInteroperability.h>)\n";
out << "// '<toolchain>/usr/local/lib/clang/<version>/include/../../../../lib/swift/swiftToCxx'.\n";
out << "#include <../../../../lib/swift/swiftToCxx/_SwiftCxxInteroperability.h>\n";
out << "// Alternatively, allow user to find the header using additional include path into '<toolchain>/lib/swift'.\n";
out << "#elif __has_include(<swiftToCxx/_SwiftCxxInteroperability.h>)\n";
out << "#include <swiftToCxx/_SwiftCxxInteroperability.h>\n";
out << "#endif\n";
},
[&] {
Expand Down
1 change: 0 additions & 1 deletion stdlib/public/SwiftShims/swift/shims/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ set(sources
UnicodeData.h
Visibility.h
_SwiftConcurrency.h
_SwiftCxxInteroperability.h
_SwiftDistributed.h

module.modulemap
Expand Down
5 changes: 0 additions & 5 deletions stdlib/public/SwiftShims/swift/shims/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,3 @@ module SwiftOverlayShims {
header "LibcOverlayShims.h"
export *
}

module _SwiftCxxInteropShims {
header "_SwiftCxxInteroperability.h"
export *
}
15 changes: 9 additions & 6 deletions test/PrintAsCxx/empty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
// CHECK-NEXT: #include <new>
// CHECK-NEXT: #include <type_traits>
// CHECK-NEXT: // Look for the C++ interop support header relative to clang's resource dir:
// CHECK-NEXT: // '<toolchain>/usr/lib/clang/<version>/include/../../../swift/shims'.
// CHECK-NEXT: #if __has_include(<../../../swift/shims/_SwiftCxxInteroperability.h>)
// CHECK-NEXT: #include <../../../swift/shims/_SwiftCxxInteroperability.h>
// CHECK-NEXT: // Alternatively, allow user to find the header using additional include path into 'swift'.
// CHECK-NEXT: #elif __has_include(<shims/_SwiftCxxInteroperability.h>)
// CHECK-NEXT: #include <shims/_SwiftCxxInteroperability.h>
// CHECK-NEXT: // '<toolchain>/usr/lib/clang/<version>/include/../../../swift/swiftToCxx'.
// CHECK-NEXT: #if __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: #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: #else
// CHECK-NEXT: #include <stdint.h>
Expand Down