Skip to content

[cxx-interop] Introduce APINotes file for C++ stdlib #68118

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 30, 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
2 changes: 0 additions & 2 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
21 changes: 20 additions & 1 deletion stdlib/public/Cxx/std/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
8 changes: 8 additions & 0 deletions stdlib/public/Cxx/std/std.apinotes
Original file line number Diff line number Diff line change
@@ -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