[libcxx-commits] [PATCH] D78154: [WIP][libc++] Link c++experimental.a into libc++.dylib when enabled

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 14 14:05:20 PDT 2020


ldionne created this revision.
Herald added subscribers: libcxx-commits, dexonsmith, jkorous, mgorny.
Herald added a project: libc++.
Herald added a reviewer: libc++.
ldionne added a subscriber: jwakely.
ldionne added a comment.

This isn't a complete patch, but mostly a RFC to see what folks would think about including `libc++experimental.a` into the static/shared library when it is enabled. My view of things is that `-lc++` should always be sufficient to link against libc++, and on Darwin it is (libc++abi symbols are re-exported, so `-lc++abi` isn't required). With that view of things, it makes sense to include `c++experimental.a` in the dylib when it is enabled.

Note that vendors are free not to enable `c++experimental.a` in the dylib they ship because they need to ensure ABI compatibility and some amount of stability.

@jwakely , how does libstdc++ ship experimental features? Does it ship them in its shared library?


When libc++ is built with experimental features enabled, we link the
c++experimental.a static library directly into libc++.dylib, which
allows users to avoid using `-lc++experimental` in order to use
experimental features.

It makes sense to me that when libc++ is configured with experimental
features enabled, it should just work. Of course, vendors are free to
follow a different course of action, since they may not want to ship
experimental features in their dylib (in which case they can simply
turn off the experimental library in their build).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78154

Files:
  libcxx/CMakeLists.txt
  libcxx/src/CMakeLists.txt


Index: libcxx/src/CMakeLists.txt
===================================================================
--- libcxx/src/CMakeLists.txt
+++ libcxx/src/CMakeLists.txt
@@ -163,6 +163,9 @@
     llvm_setup_rpath(cxx_shared)
   endif()
   target_link_libraries(cxx_shared PRIVATE ${LIBCXX_LIBRARIES})
+  if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
+    target_link_libraries(cxx_shared PRIVATE cxx_experimental)
+  endif()
   set_target_properties(cxx_shared
     PROPERTIES
       COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
@@ -241,6 +244,9 @@
 if (LIBCXX_ENABLE_STATIC)
   add_library(cxx_static STATIC ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
   target_link_libraries(cxx_static PRIVATE ${LIBCXX_LIBRARIES})
+  if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
+    target_link_libraries(cxx_static PRIVATE cxx_experimental)
+  endif()
   set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
   set_target_properties(cxx_static
     PROPERTIES
@@ -302,9 +308,9 @@
     )
   add_library(cxx_experimental STATIC ${LIBCXX_EXPERIMENTAL_SOURCES})
   if (LIBCXX_ENABLE_SHARED)
-    target_link_libraries(cxx_experimental PRIVATE cxx_shared)
+    target_link_libraries(cxx_experimental INTERFACE cxx_shared)
   else()
-    target_link_libraries(cxx_experimental PRIVATE cxx_static)
+    target_link_libraries(cxx_experimental INTERFACE cxx_static)
   endif()
 
   set_target_properties(cxx_experimental
Index: libcxx/CMakeLists.txt
===================================================================
--- libcxx/CMakeLists.txt
+++ libcxx/CMakeLists.txt
@@ -77,7 +77,7 @@
 option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." OFF)
 option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
 option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON)
-option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON)
+option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a, and link it into libc++" ON)
 set(ENABLE_FILESYSTEM_DEFAULT ON)
 if (WIN32)
   set(ENABLE_FILESYSTEM_DEFAULT OFF)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78154.257489.patch
Type: text/x-patch
Size: 2026 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200414/f30325f9/attachment.bin>


More information about the libcxx-commits mailing list