Skip to content

Commit b23193d

Browse files
committed
[RFC][libc++] Install modules.
The patch is based on the discussion in SG-15 on 12.12.2023. Fixes: #73089
1 parent a418be9 commit b23193d

16 files changed

+98
-1
lines changed

libcxx/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
177177
"Define suffix of library directory name (32/64)")
178178
option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
179179
option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
180+
option(LIBCXX_INSTALL_MODULES "Install the libc++ C++20 modules (experimental)." OFF)
180181
cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
181182
"Install the static libc++ library." ON
182183
"LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)
@@ -424,6 +425,8 @@ set(LIBCXX_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE STRING
424425
"Path where target-agnostic libc++ headers should be installed.")
425426
set(LIBCXX_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
426427
"Path where built libc++ runtime libraries should be installed.")
428+
set(LIBCXX_INSTALL_MODULE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/../modules/c++/v1" CACHE STRING
429+
"Path where target-agnostic libc++ modules should be installed.")
427430

428431
set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.")
429432
set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library.")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
set(LIBCXX_ENABLE_STD_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
2+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
23
set(LIBCXX_TEST_PARAMS "std=c++26" CACHE STRING "")
34
set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
set(LIBCXX_ENABLE_STD_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
2+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
23
set(LIBCXX_HARDENING_MODE "extensive" CACHE STRING "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
set(LIBCXX_ENABLE_STD_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
2+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
23
set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
34
set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
set(LIBCXX_ENABLE_STD_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
2+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
23
set(LIBCXX_TEST_PARAMS "enable_experimental=False" CACHE STRING "")
34
set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
set(LIBCXX_ENABLE_STD_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
2+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
23
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
set(LIBCXX_ENABLE_STD_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
2+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
23
set(LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
set(LIBCXX_ENABLE_STD_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
2+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
23
set(LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(LIBCXX_ENABLE_STD_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
2+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
23
set(LIBCXX_ENABLE_THREADS OFF CACHE BOOL "")
34
set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
45
set(LIBCXX_ENABLE_MONOTONIC_CLOCK OFF CACHE BOOL "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
set(LIBCXX_ENABLE_STD_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
2+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
23
set(LIBCXX_ENABLE_UNICODE OFF CACHE BOOL "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
set(LIBCXX_ENABLE_STD_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
2+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
23
set(LIBCXX_ENABLE_WIDE_CHARACTERS OFF CACHE BOOL "")

libcxx/docs/Modules.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ Some of the current limitations
6969
* The path to the compiler may not be a symlink, ``clang-scan-deps`` does
7070
not handle that case properly
7171
* Libc++ is not tested with modules instead of headers
72-
* The module ``.cppm`` files are not installed
7372
* Clang supports modules using GNU extensions, but libc++ does not work using
7473
GNU extensions.
7574
* Clang:

libcxx/docs/ReleaseNotes/18.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ Improvements and New Features
8181
- The ``_LIBCPP_ENABLE_CXX26_REMOVED_STRING_RESERVE`` macro has been added to make
8282
the function ``std::basic_string<...>::reserve()`` available.
8383

84+
- The experimental standard library modules can now be installed. By default,
85+
they are not installed. This can be enabled by configuring CMake with
86+
``-DLIBCXX_INSTALL_MODULES=ON``. The installation directory can be configured
87+
with the CMake option ``-DLIBCXX_INSTALL_MODULE_DIR=<path>``. The default
88+
location is ``modules/c++/v1`` in the same prefix as the ``include``
89+
directory.
90+
8491

8592
Deprecations and Removals
8693
-------------------------

libcxx/modules/CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,57 @@ add_custom_target(generate-cxx-modules
210210
ALL DEPENDS
211211
${_all_modules}
212212
)
213+
214+
# Use the relative path between the installation and the module in the json
215+
# file. This allows moving the entire installation to a different to a
216+
# different location.
217+
file(RELATIVE_PATH LIBCXX_MODULE_RELATIVE_PATH
218+
${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_LIBRARY_DIR}
219+
${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_MODULE_DIR})
220+
configure_file(
221+
"modules.json.in"
222+
"${LIBCXX_LIBRARY_DIR}/modules.json"
223+
@ONLY
224+
)
225+
226+
# Dummy library to make modules an installation component.
227+
add_library(cxx-modules INTERFACE)
228+
add_dependencies(cxx-modules generate-cxx-modules)
229+
230+
if (LIBCXX_INSTALL_MODULES)
231+
foreach(file ${LIBCXX_MODULE_STD_SOURCES} ${LIBCXX_MODULE_STD_COMPAT_SOURCES})
232+
get_filename_component(dir ${file} DIRECTORY)
233+
install(FILES ${file}
234+
DESTINATION "${LIBCXX_INSTALL_MODULE_DIR}/${dir}"
235+
COMPONENT cxx-modules
236+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
237+
)
238+
endforeach()
239+
240+
# Install the generated module files.
241+
install(FILES
242+
"${LIBCXX_GENERATED_MODULE_DIR}/std.cppm"
243+
"${LIBCXX_GENERATED_MODULE_DIR}/std.compat.cppm"
244+
DESTINATION "${LIBCXX_INSTALL_MODULE_DIR}"
245+
COMPONENT cxx-modules
246+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
247+
)
248+
249+
# Install the module manifest.
250+
install(FILES
251+
"${LIBCXX_LIBRARY_DIR}/modules.json"
252+
DESTINATION "${LIBCXX_INSTALL_LIBRARY_DIR}"
253+
COMPONENT cxx-modules
254+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
255+
)
256+
257+
if (NOT CMAKE_CONFIGURATION_TYPES)
258+
add_custom_target(install-cxx-modules
259+
DEPENDS cxx-modules
260+
COMMAND "${CMAKE_COMMAND}"
261+
-DCMAKE_INSTALL_COMPONENT=cxx-modules
262+
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
263+
# Stripping is a no-op for modules
264+
add_custom_target(install-cxx-modules-stripped DEPENDS install-cxx-headers)
265+
endif()
266+
endif()

libcxx/modules/modules.json.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": 1,
3+
"revision": 1,
4+
"modules": [
5+
{
6+
"logical-name": "std",
7+
"source-path": "@LIBCXX_MODULE_RELATIVE_PATH@/std.cppm",
8+
"system-include-directories": "@LIBCXX_MODULE_RELATIVE_PATH@/std",
9+
"is-standard-library": true
10+
},
11+
{
12+
"logical-name": "std.compat",
13+
"source-path": "@LIBCXX_MODULE_RELATIVE_PATH@/std.compat.cppm",
14+
"system-include-directories": [
15+
"@LIBCXX_MODULE_RELATIVE_PATH@/std",
16+
"@LIBCXX_MODULE_RELATIVE_PATH@/std.compat"
17+
],
18+
"is-std-library": true
19+
}
20+
]
21+
}

libcxx/src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ if (NOT CMAKE_CONFIGURATION_TYPES)
396396
endif()
397397
if(LIBCXX_INSTALL_HEADERS)
398398
set(header_install_target install-cxx-headers)
399+
endif()
400+
if(LIBCXX_INSTALL_MODULES)
401+
set(header_install_target install-cxx-modules)
399402
endif()
400403
add_custom_target(install-cxx
401404
DEPENDS ${lib_install_target}

0 commit comments

Comments
 (0)