Skip to content

Commit 2b49c8a

Browse files
mordantecopybara-github
authored andcommitted
[libc++][doc] Updates module information. (#75003)
Adds the std.compat module and add support for CMake 3.28. NOKEYCHECK=True GitOrigin-RevId: 0e05904664d8b9191a0aecab683bb92609b6b57b
1 parent f5da410 commit 2b49c8a

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

docs/Modules.rst

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ What works
3838
~~~~~~~~~~
3939

4040
* Building BMIs
41-
* Running tests using the ``std`` module
42-
* Using the ``std`` module in external projects
41+
* Running tests using the ``std`` and ``std.compat`` module
42+
* Using the ``std`` and ``std.compat`` module in external projects
4343
* The following "parts disabled" configuration options are supported
4444

4545
* ``LIBCXX_ENABLE_LOCALIZATION``
@@ -65,10 +65,9 @@ Some of the current limitations
6565
* Requires CMake 3.26 for C++23 support
6666
* Requires CMake 3.27 for C++26 support
6767
* Requires Ninja 1.11
68-
* Requires a recent Clang 17
68+
* Requires Clang 17
6969
* The path to the compiler may not be a symlink, ``clang-scan-deps`` does
7070
not handle that case properly
71-
* Only C++23 and C++26 are tested
7271
* Libc++ is not tested with modules instead of headers
7372
* The module ``.cppm`` files are not installed
7473
* Clang supports modules using GNU extensions, but libc++ does not work using
@@ -127,9 +126,13 @@ This is a small sample program that uses the module ``std``. It consists of a
127126

128127
.. code-block:: cpp
129128
130-
import std;
129+
import std; // When importing std.compat it's not needed to import std.
130+
import std.compat;
131131
132-
int main() { std::cout << "Hello modular world\n"; }
132+
int main() {
133+
std::cout << "Hello modular world\n";
134+
::printf("Hello compat modular world\n");
135+
}
133136
134137
.. code-block:: cmake
135138
@@ -142,7 +145,6 @@ This is a small sample program that uses the module ``std``. It consists of a
142145
# Set language version used
143146
#
144147
145-
# At the moment only C++23 is tested.
146148
set(CMAKE_CXX_STANDARD 23)
147149
set(CMAKE_CXX_STANDARD_REQUIRED YES)
148150
# Libc++ doesn't support compiler extensions for modules.
@@ -153,12 +155,16 @@ This is a small sample program that uses the module ``std``. It consists of a
153155
#
154156
155157
# This is required to write your own modules in your project.
156-
if(CMAKE_VERSION VERSION_LESS "3.27.0")
157-
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
158+
if(CMAKE_VERSION VERSION_LESS "3.28.0")
159+
if(CMAKE_VERSION VERSION_LESS "3.27.0")
160+
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
161+
else()
162+
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "aa1f7df0-828a-4fcd-9afc-2dc80491aca7")
163+
endif()
164+
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
158165
else()
159-
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "aa1f7df0-828a-4fcd-9afc-2dc80491aca7")
166+
cmake_policy(VERSION 3.28)
160167
endif()
161-
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
162168
163169
#
164170
# Import the modules from libc++
@@ -169,18 +175,16 @@ This is a small sample program that uses the module ``std``. It consists of a
169175
std
170176
URL "file://${LIBCXX_BUILD}/modules/c++/v1/"
171177
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
178+
SYSTEM
172179
)
173-
FetchContent_GetProperties(std)
174-
if(NOT std_POPULATED)
175-
FetchContent_Populate(std)
176-
add_subdirectory(${std_SOURCE_DIR} ${std_BINARY_DIR} EXCLUDE_FROM_ALL)
177-
endif()
180+
FetchContent_MakeAvailable(std)
178181
179182
#
180183
# Adjust project compiler flags
181184
#
182185
183186
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fprebuilt-module-path=${CMAKE_BINARY_DIR}/_deps/std-build/CMakeFiles/std.dir/>)
187+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fprebuilt-module-path=${CMAKE_BINARY_DIR}/_deps/std-build/CMakeFiles/std.compat.dir/>)
184188
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-nostdinc++>)
185189
# The include path needs to be set to be able to use macros from headers.
186190
# For example from, the headers <cassert> and <version>.
@@ -194,8 +198,9 @@ This is a small sample program that uses the module ``std``. It consists of a
194198
add_link_options($<$<COMPILE_LANGUAGE:CXX>:-nostdlib++>)
195199
add_link_options($<$<COMPILE_LANGUAGE:CXX>:-L${LIBCXX_BUILD}/lib>)
196200
add_link_options($<$<COMPILE_LANGUAGE:CXX>:-Wl,-rpath,${LIBCXX_BUILD}/lib>)
197-
# Linking against std is required for CMake to get the proper dependencies
201+
# Linking against the standard c++ library is required for CMake to get the proper dependencies.
198202
link_libraries(std c++)
203+
link_libraries(std.compat c++)
199204
200205
#
201206
# Add the project

0 commit comments

Comments
 (0)