Skip to content

Commit

Permalink
[libc++] Always build c++experimental.a
Browse files Browse the repository at this point in the history
This is the first part of a plan to ship experimental features
by default while guarding them behind a compiler flag to avoid
users accidentally depending on them. Subsequent patches will
also encompass incomplete features (such as <format> and <ranges>)
in that categorization. Basically, the idea is that we always
build and ship the c++experimental library, however users can't
use what's in it unless they pass the `-funstable` flag to Clang.

Note that this patch intentionally does not start guarding
existing <experimental/FOO> content behind the flag, because
that would merely break users that might be relying on such
content being in the headers unconditionally. Instead, we
should start guarding new TSes behind the flag, and get rid
of the existing TSes we have by shipping their Standard
counterpart.

Also, this patch must jump through a few hoops like defining
_LIBCPP_ENABLE_EXPERIMENTAL because we still support compilers
that do not implement -funstable yet.

Differential Revision: https://reviews.llvm.org/D128927
  • Loading branch information
ldionne committed Jul 8, 2022
1 parent c945bd0 commit bb93993
Show file tree
Hide file tree
Showing 44 changed files with 198 additions and 86 deletions.
1 change: 0 additions & 1 deletion clang/cmake/caches/Fuchsia-stage2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ if(WIN32)
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
Expand Down
1 change: 0 additions & 1 deletion clang/cmake/caches/Fuchsia.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ endif()

if(WIN32)
set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
set(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY OFF CACHE BOOL "")
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
Expand Down
1 change: 0 additions & 1 deletion compiler-rt/cmake/Modules/AddCompilerRT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@ macro(add_custom_libcxx name prefix)
-DLIBCXXABI_HERMETIC_STATIC_LIBRARY=ON
-DLIBCXXABI_INCLUDE_TESTS=OFF
-DLIBCXX_CXX_ABI=libcxxabi
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF
-DLIBCXX_ENABLE_SHARED=OFF
-DLIBCXX_HERMETIC_STATIC_LIBRARY=ON
-DLIBCXX_INCLUDE_BENCHMARKS=OFF
Expand Down
10 changes: 1 addition & 9 deletions libcxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ option(LIBCXX_ENABLE_ASSERTIONS
by users in their own code regardless of this option." 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)
set(ENABLE_FILESYSTEM_DEFAULT ON)
if (WIN32 AND NOT MINGW)
# Filesystem is buildable for windows, but it requires __int128 helper
Expand Down Expand Up @@ -167,9 +166,6 @@ cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY
"Install the shared libc++ library." ON
"LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF)
cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY
"Install libc++experimental.a" ON
"LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY;LIBCXX_INSTALL_LIBRARY" OFF)

option(LIBCXX_ABI_UNSTABLE "Use the unstable ABI of libc++. This is equivalent to specifying LIBCXX_ABI_VERSION=n, where n is the not-yet-stable version." OFF)
if (LIBCXX_ABI_UNSTABLE)
Expand Down Expand Up @@ -930,11 +926,7 @@ add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(utils)

set(LIBCXX_TEST_DEPS "")

if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
list(APPEND LIBCXX_TEST_DEPS cxx_experimental)
endif()
set(LIBCXX_TEST_DEPS "cxx_experimental")

if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
list(APPEND LIBCXX_TEST_DEPS cxx_external_threads)
Expand Down
2 changes: 1 addition & 1 deletion libcxx/appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ build_script:
#############################################################################
- cmake -G "%GENERATOR%" %CMAKE_OPTIONS%
"-DCMAKE_BUILD_TYPE=%configuration%"
"-DLLVM_PATH=C:\projects\deps\llvm" -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF
"-DLLVM_PATH=C:\projects\deps\llvm"
-DLLVM_LIT_ARGS="-sv --show-xfail --show-unsupported"
%APPVEYOR_BUILD_FOLDER%

Expand Down
1 change: 0 additions & 1 deletion libcxx/cmake/caches/AIX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBCXX_ENABLE_ASSERTIONS OFF CACHE BOOL "")
set(LIBCXX_ABI_VERSION "1" CACHE STRING "")
set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
set(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY OFF CACHE BOOL "")
set(LIBCXX_ENABLE_SHARED ON CACHE BOOL "")
set(LIBCXX_ENABLE_STATIC OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_SHARED ON CACHE BOOL "")
Expand Down
1 change: 0 additions & 1 deletion libcxx/cmake/caches/Apple.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ set(CMAKE_POSITION_INDEPENDENT_CODE OFF CACHE BOOL "")
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBCXX_ENABLE_ASSERTIONS OFF CACHE BOOL "")
set(LIBCXX_ABI_VERSION "1" CACHE STRING "")
set(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY OFF CACHE BOOL "")
set(LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
set(LIBCXX_ENABLE_SHARED ON CACHE BOOL "")
set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
Expand Down
3 changes: 2 additions & 1 deletion libcxx/cmake/caches/Generic-no-experimental.cmake
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
set(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY OFF CACHE BOOL "")
set(LIBCXX_TEST_PARAMS "enable_experimental=False" CACHE STRING "")
set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
set(LIBCXX_ENABLE_INCOMPLETE_FEATURES OFF CACHE BOOL "")
23 changes: 2 additions & 21 deletions libcxx/docs/BuildingLibcxx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ it is the simplest way to build.
-T "ClangCL" ^
-DLLVM_ENABLE_RUNTIMES=libcxx ^
-DLIBCXX_ENABLE_SHARED=YES ^
-DLIBCXX_ENABLE_STATIC=NO ^
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO
-DLIBCXX_ENABLE_STATIC=NO
> cmake --build build
CMake + ninja (MSVC)
Expand Down Expand Up @@ -131,8 +130,7 @@ In either case, then run:
> cmake -G Ninja -S runtimes -B build ^
-DCMAKE_C_COMPILER=clang-cl ^
-DCMAKE_CXX_COMPILER=clang-cl ^
-DLLVM_ENABLE_RUNTIMES=libcxx ^
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO
-DLLVM_ENABLE_RUNTIMES=libcxx
> ninja -C build cxx
> ninja -C build check-cxx
Expand Down Expand Up @@ -298,23 +296,6 @@ libc++ specific options
Path where target-specific libc++ headers should be installed. If a relative
path, relative to ``CMAKE_INSTALL_PREFIX``.

.. _libc++experimental options:

libc++experimental Specific Options
------------------------------------

.. option:: LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY:BOOL

**Default**: ``ON``

Build and test libc++experimental.a.

.. option:: LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY:BOOL

**Default**: ``LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY AND LIBCXX_INSTALL_LIBRARY``

Install libc++experimental.a alongside libc++.


.. _ABI Library Specific Options:

Expand Down
22 changes: 10 additions & 12 deletions libcxx/docs/UsingLibcxx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,20 @@ matches that Standard in the library.
library until the standard has been ratified.


Using libc++experimental and ``<experimental/...>``
===================================================
Enabling experimental C++ Library features
==========================================

Libc++ provides implementations of experimental technical specifications
in a separate library, ``libc++experimental.a``. Users of ``<experimental/...>``
headers may be required to link ``-lc++experimental``. Note that not all
vendors ship ``libc++experimental.a``, and as a result, you may not be
able to use those experimental features.

.. code-block:: bash
$ clang++ test.cpp -lc++experimental
Libc++ provides implementations of some experimental features. Experimental features
are either Technical Specifications (TSes) or official features that were voted to
the Standard but whose implementation is not complete or stable yet in libc++. Those
are disabled by default because they are neither API nor ABI stable. However, the
``_LIBCPP_ENABLE_EXPERIMENTAL`` macro can be defined to turn those features on. Note
that you will also need to link to the appropriate ``libc++experimental.a`` static
archive.

.. warning::
Experimental libraries are Experimental.
* The contents of the ``<experimental/...>`` headers and ``libc++experimental.a``
* The contents of the ``<experimental/...>`` headers and the associated static
library will not remain compatible between versions.
* No guarantees of API or ABI stability are provided.
* When the standardized version of an experimental feature is implemented,
Expand Down
52 changes: 24 additions & 28 deletions libcxx/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,31 +315,30 @@ endif()
# Add a meta-target for both libraries.
add_custom_target(cxx DEPENDS ${LIBCXX_BUILD_TARGETS})

if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
set(LIBCXX_EXPERIMENTAL_SOURCES
experimental/memory_resource.cpp
)
add_library(cxx_experimental STATIC ${LIBCXX_EXPERIMENTAL_SOURCES})
if (LIBCXX_ENABLE_SHARED)
target_link_libraries(cxx_experimental PRIVATE cxx_shared)
else()
target_link_libraries(cxx_experimental PRIVATE cxx_static)
endif()

set_target_properties(cxx_experimental
PROPERTIES
COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
OUTPUT_NAME "c++experimental"
set(LIBCXX_EXPERIMENTAL_SOURCES
experimental/memory_resource.cpp
)
cxx_add_common_build_flags(cxx_experimental)

if (LIBCXX_HERMETIC_STATIC_LIBRARY)
# _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS can be defined in __config_site
# too. Define it in the same way here, to avoid redefinition conflicts.
target_compile_definitions(cxx_experimental PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
endif()
add_library(cxx_experimental STATIC ${LIBCXX_EXPERIMENTAL_SOURCES})
if (LIBCXX_ENABLE_SHARED)
target_link_libraries(cxx_experimental PRIVATE cxx_shared)
else()
target_link_libraries(cxx_experimental PRIVATE cxx_static)
endif()

if (LIBCXX_HERMETIC_STATIC_LIBRARY)
# _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS can be defined in __config_site
# too. Define it in the same way here, to avoid redefinition conflicts.
target_compile_definitions(cxx_experimental PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
endif()

set_target_properties(cxx_experimental
PROPERTIES
COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
OUTPUT_NAME "c++experimental"
)
cxx_add_common_build_flags(cxx_experimental)


if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
set(LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES
Expand Down Expand Up @@ -375,7 +374,7 @@ if (LIBCXX_INSTALL_STATIC_LIBRARY)
RUNTIME DESTINATION ${LIBCXX_INSTALL_RUNTIME_DIR} COMPONENT cxx)
endif()

if(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY)
if (LIBCXX_INSTALL_LIBRARY)
install(TARGETS cxx_experimental
LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx
ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx
Expand All @@ -392,10 +391,7 @@ endif()

if (NOT CMAKE_CONFIGURATION_TYPES)
if(LIBCXX_INSTALL_LIBRARY)
set(lib_install_target cxx)
endif()
if (LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY)
set(experimental_lib_install_target cxx_experimental)
set(lib_install_target "cxx;cxx_experimental")
endif()
if(LIBCXX_INSTALL_HEADERS)
set(header_install_target install-cxx-headers)
Expand All @@ -405,15 +401,15 @@ if (NOT CMAKE_CONFIGURATION_TYPES)
endif()
add_custom_target(install-cxx
DEPENDS ${lib_install_target}
${experimental_lib_install_target}
cxx_experimental
${header_install_target}
${pstl_install_target}
COMMAND "${CMAKE_COMMAND}"
-DCMAKE_INSTALL_COMPONENT=cxx
-P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
add_custom_target(install-cxx-stripped
DEPENDS ${lib_install_target}
${experimental_lib_install_target}
cxx_experimental
${header_install_target}
${pstl_install_target}
COMMAND "${CMAKE_COMMAND}"
Expand Down
4 changes: 0 additions & 4 deletions libcxx/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ if (NOT LIBCXX_ENABLE_EXCEPTIONS)
serialize_lit_param(enable_exceptions False)
endif()

if (NOT LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
serialize_lit_param(enable_experimental False)
endif()

if (NOT LIBCXX_ENABLE_RTTI)
serialize_lit_param(enable_rtti False)
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

// UNSUPPORTED: c++03

// Aligned allocation is required by std::experimental::pmr, but it was not provided
// before macosx10.13 and as a result we get linker errors when deploying to older than
// macosx10.13.
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}

// <experimental/memory_resource>

// memory_resource * new_delete_resource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

// UNSUPPORTED: c++03

// Aligned allocation is required by std::experimental::pmr, but it was not provided
// before macosx10.13 and as a result we get linker errors when deploying to older than
// macosx10.13.
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}

// <experimental/memory_resource>

// memory_resource * new_delete_resource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

// UNSUPPORTED: c++03

// Aligned allocation is required by std::experimental::pmr, but it was not provided
// before macosx10.13 and as a result we get linker errors when deploying to older than
// macosx10.13.
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}

// <experimental/memory_resource>

// template <class T> class polymorphic_allocator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

// UNSUPPORTED: c++03

// Aligned allocation is required by std::experimental::pmr, but it was not provided
// before macosx10.13 and as a result we get linker errors when deploying to older than
// macosx10.13.
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}

// <experimental/memory_resource>

// template <class T> class polymorphic_allocator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

// UNSUPPORTED: c++03

// Aligned allocation is required by std::experimental::pmr, but it was not provided
// before macosx10.13 and as a result we get linker errors when deploying to older than
// macosx10.13.
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}

// <experimental/memory_resource>

// template <class T> class polymorphic_allocator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

// UNSUPPORTED: c++03

// Aligned allocation is required by std::experimental::pmr, but it was not provided
// before macosx10.13 and as a result we get linker errors when deploying to older than
// macosx10.13.
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}

// <experimental/memory_resource>

// template <class T> class polymorphic_allocator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

// UNSUPPORTED: c++03

// Aligned allocation is required by std::experimental::pmr, but it was not provided
// before macosx10.13 and as a result we get linker errors when deploying to older than
// macosx10.13.
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}

// <experimental/memory_resource>

// template <class T> class polymorphic_allocator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

// UNSUPPORTED: c++03

// Aligned allocation is required by std::experimental::pmr, but it was not provided
// before macosx10.13 and as a result we get linker errors when deploying to older than
// macosx10.13.
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}

// <experimental/memory_resource>

// template <class T> class polymorphic_allocator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

// UNSUPPORTED: c++03

// Aligned allocation is required by std::experimental::pmr, but it was not provided
// before macosx10.13 and as a result we get linker errors when deploying to older than
// macosx10.13.
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}

// <experimental/memory_resource>

// template <class T> class polymorphic_allocator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

// UNSUPPORTED: c++03

// Aligned allocation is required by std::experimental::pmr, but it was not provided
// before macosx10.13 and as a result we get linker errors when deploying to older than
// macosx10.13.
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}

// <experimental/memory_resource>

// template <class T> class polymorphic_allocator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

// UNSUPPORTED: c++03

// Aligned allocation is required by std::experimental::pmr, but it was not provided
// before macosx10.13 and as a result we get linker errors when deploying to older than
// macosx10.13.
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}

// <experimental/memory_resource>

// template <class T> class polymorphic_allocator
Expand Down

0 comments on commit bb93993

Please sign in to comment.