From 9b7dbf2599df9bac2166573c31368aadf51d8090 Mon Sep 17 00:00:00 2001 From: Egor Zhdan Date: Thu, 24 Aug 2023 16:21:05 +0100 Subject: [PATCH] [cxx-interop] Introduce APINotes file for C++ stdlib This adds an `std.apinotes` file that is installed into `lib/swift/apinotes` along with existing Darwin apinotes. This new file is installed on all platforms. It replaces a few special cases in the compiler for `cmath` and `cstring` functions. This does not require the upcoming APINotes support for namespaces, however, this does require https://github.com/apple/llvm-project/pull/7309. rdar://107572302 --- lib/ClangImporter/ImportDecl.cpp | 2 -- stdlib/public/Cxx/std/CMakeLists.txt | 21 ++++++++++++++++++++- stdlib/public/Cxx/std/std.apinotes | 8 ++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 stdlib/public/Cxx/std/std.apinotes diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index 0aae7b71c8a8a..909024909a1c1 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -3226,8 +3226,6 @@ namespace { // instead of checking if they come from the `std` module. if (!d->getDeclName().isIdentifier()) return false; - if (d->getName() == "abs" || d->getName() == "div") - return true; if (Impl.SwiftContext.LangOpts.Target.isOSDarwin()) return d->getName() == "strstr" || d->getName() == "sin" || d->getName() == "cos" || d->getName() == "exit"; diff --git a/stdlib/public/Cxx/std/CMakeLists.txt b/stdlib/public/Cxx/std/CMakeLists.txt index b616b471b2973..9731391bc6ca7 100644 --- a/stdlib/public/Cxx/std/CMakeLists.txt +++ b/stdlib/public/Cxx/std/CMakeLists.txt @@ -1,3 +1,22 @@ +# +# API Notes for the C++ Standard Library +# +set(output_dir "${SWIFTLIB_DIR}/apinotes") +add_custom_target(CxxStdlib-apinotes + COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${output_dir}" + COMMAND ${CMAKE_COMMAND} "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/std.apinotes" "${output_dir}" + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/std.apinotes + COMMENT "Copying CxxStdlib API Notes to ${output_dir}") + +swift_install_in_component(FILES std.apinotes + DESTINATION "lib/swift/apinotes" + COMPONENT compiler) + +set_property(TARGET CxxStdlib-apinotes PROPERTY FOLDER "Miscellaneous") +add_dependencies(sdk-overlay CxxStdlib-apinotes) +add_dependencies(compiler CxxStdlib-apinotes) + + # Swift compiler currently assumes that the Darwin overlay is a dependency of # CxxStdlib, and fails to build CxxStdlib if Darwin.swiftmodule in build dir # is built with a different (older) version of the compiler. To workaround this, @@ -34,4 +53,4 @@ add_swift_target_library(swiftCxxStdlib STATIC NO_LINK_NAME IS_STDLIB IS_SWIFT_O TARGET_SDKS ALL_APPLE_PLATFORMS LINUX WINDOWS INSTALL_IN_COMPONENT compiler INSTALL_WITH_SHARED - DEPENDS libstdcxx-modulemap libcxxshim_modulemap) + DEPENDS libstdcxx-modulemap libcxxshim_modulemap CxxStdlib-apinotes) diff --git a/stdlib/public/Cxx/std/std.apinotes b/stdlib/public/Cxx/std/std.apinotes new file mode 100644 index 0000000000000..16f70d6ab4cf8 --- /dev/null +++ b/stdlib/public/Cxx/std/std.apinotes @@ -0,0 +1,8 @@ +Name: std +Functions: +- Name: abs + Availability: nonswift + AvailabilityMsg: Use the C standard library function +- Name: div + Availability: nonswift + AvailabilityMsg: Use the C standard library function