Skip to content

Commit 71909de

Browse files
committed
[libc++] Disable incomplete library features.
Adds a new CMake option to disable the usage of incomplete headers. These incomplete headers are not guaranteed to be ABI stable. This option is intended to be used by vendors so they can avoid their users from code that's not ready for production usage. The option is enabled by default. Differential Revision: https://reviews.llvm.org/D106763
1 parent d1c7a57 commit 71909de

File tree

155 files changed

+213
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+213
-7
lines changed

libcxx/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
123123
to provide compile-time errors when using features unavailable on some version of
124124
the shared library they shipped should turn this on and see `include/__availability`
125125
for more details." OFF)
126+
option(LIBCXX_ENABLE_INCOMPLETE_FEATURES
127+
"Whether to enable support for incomplete library features. Incomplete features
128+
are new library features under development. These features don't guarantee
129+
ABI stability nor the quality of completed library features. Vendors
130+
shipping the library may want to disable this option." ON)
126131
set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/legacy.cfg.in" CACHE STRING
127132
"The Lit testing configuration to use when running the tests.")
128133
set(LIBCXX_TEST_PARAMS "" CACHE STRING
@@ -883,6 +888,10 @@ config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
883888
config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE)
884889
config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION)
885890
config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
891+
# Incomplete features get their own specific disabling flags. This makes it
892+
# easier to grep for target specific flags once the feature is complete.
893+
config_define_if_not(LIBCXX_ENABLE_INCOMPLETE_FEATURES _LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
894+
config_define_if_not(LIBCXX_ENABLE_INCOMPLETE_FEATURES _LIBCPP_HAS_NO_INCOMPLETE_RANGES)
886895

887896
if (LIBCXX_ABI_DEFINES)
888897
set(abi_defines)

libcxx/cmake/caches/Apple.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
1111
set(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT ON CACHE BOOL "")
1212
set(LIBCXX_ENABLE_DEBUG_MODE_SUPPORT OFF CACHE BOOL "")
1313
set(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS ON CACHE BOOL "")
14+
set(LIBCXX_ENABLE_INCOMPLETE_FEATURES OFF CACHE BOOL "")
1415

1516
set(LIBCXX_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
1617
set(LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")

libcxx/docs/BuildingLibcxx.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ libc++ specific options
251251
This option can be used to enable or disable the filesystem components on
252252
platforms that may not support them. For example on Windows.
253253

254+
.. option:: LIBCXX_ENABLE_INCOMPLETE_FEATURES:BOOL
255+
256+
**Default**: ``ON``
257+
258+
Whether to enable support for incomplete library features. Incomplete features
259+
are new library features under development. These features don't guarantee
260+
ABI stability nor the quality of completed library features. Vendors
261+
shipping the library may want to disable this option.
262+
254263
.. option:: LIBCXX_INSTALL_LIBRARY_DIR:PATH
255264

256265
**Default**: ``lib${LIBCXX_LIBDIR_SUFFIX}``

libcxx/include/__config_site.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#cmakedefine _LIBCPP_HAS_PARALLEL_ALGORITHMS
3535
#cmakedefine _LIBCPP_HAS_NO_RANDOM_DEVICE
3636
#cmakedefine _LIBCPP_HAS_NO_LOCALIZATION
37+
#cmakedefine _LIBCPP_HAS_NO_INCOMPLETE_FORMAT
38+
#cmakedefine _LIBCPP_HAS_NO_INCOMPLETE_RANGES
3739

3840
@_LIBCPP_ABI_DEFINES@
3941

libcxx/include/format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ namespace std {
6060
#include <__format/format_parse_context.h>
6161
#include <version>
6262

63+
#if defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
64+
# error "The Format library is not supported since libc++ has been configured with LIBCXX_ENABLE_INCOMPLETE_FEATURES disabled"
65+
#endif
66+
6367
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
6468
# pragma GCC system_header
6569
#endif

libcxx/include/ranges

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ namespace std::ranges {
183183
#include <type_traits>
184184
#include <version>
185185

186+
#if defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
187+
# error "The Ranges library is not supported since libc++ has been configured with LIBCXX_ENABLE_INCOMPLETE_FEATURES disabled"
188+
#endif
189+
186190
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
187191
#pragma GCC system_header
188192
#endif

libcxx/src/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ set(LIBCXX_SOURCES
1212
condition_variable.cpp
1313
condition_variable_destructor.cpp
1414
exception.cpp
15-
format.cpp
1615
functional.cpp
1716
future.cpp
1817
hash.cpp
@@ -74,6 +73,12 @@ if (LIBCXX_ENABLE_LOCALIZATION)
7473
)
7574
endif()
7675

76+
if(LIBCXX_ENABLE_INCOMPLETE_FEATURES)
77+
list(APPEND LIBCXX_SOURCES
78+
format.cpp
79+
)
80+
endif()
81+
7782
if(WIN32)
7883
list(APPEND LIBCXX_SOURCES
7984
support/win32/locale_win32.cpp

libcxx/test/libcxx/double_include.sh.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@
9191
# include <filesystem>
9292
#endif
9393
#include <float.h>
94-
#include <format>
94+
#ifndef _LIBCPP_HAS_NO_INCOMPLETE_FORMAT
95+
# include <format>
96+
#endif
9597
#include <forward_list>
9698
#ifndef _LIBCPP_HAS_NO_LOCALIZATION
9799
# include <fstream>
@@ -143,7 +145,9 @@
143145
#endif
144146
#include <queue>
145147
#include <random>
146-
#include <ranges>
148+
#ifndef _LIBCPP_HAS_NO_INCOMPLETE_RANGES
149+
# include <ranges>
150+
#endif
147151
#include <ratio>
148152
#ifndef _LIBCPP_HAS_NO_LOCALIZATION
149153
# include <regex>

libcxx/test/libcxx/inclusions/ranges.inclusions.compile.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// clang-format off
1313

1414
// UNSUPPORTED: c++03, c++11, c++14, c++17
15+
// UNSUPPORTED: libcpp-has-no-incomplete-ranges
1516

1617
// <ranges>
1718

libcxx/test/libcxx/min_max_macros.compile.pass.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ TEST_MACROS();
136136
#endif
137137
#include <float.h>
138138
TEST_MACROS();
139-
#include <format>
139+
#ifndef _LIBCPP_HAS_NO_INCOMPLETE_FORMAT
140+
# include <format>
140141
TEST_MACROS();
142+
#endif
141143
#include <forward_list>
142144
TEST_MACROS();
143145
#ifndef _LIBCPP_HAS_NO_LOCALIZATION
@@ -218,8 +220,10 @@ TEST_MACROS();
218220
TEST_MACROS();
219221
#include <random>
220222
TEST_MACROS();
221-
#include <ranges>
223+
#ifndef _LIBCPP_HAS_NO_INCOMPLETE_RANGES
224+
# include <ranges>
222225
TEST_MACROS();
226+
#endif
223227
#include <ratio>
224228
TEST_MACROS();
225229
#ifndef _LIBCPP_HAS_NO_LOCALIZATION

0 commit comments

Comments
 (0)