Skip to content

Commit 8b47bb6

Browse files
authored
[libc++] Install modules. (#75741)
Installs the source files of the experimental libc++ modules. These source files (.cppm) are used by the Clang to build the std and std.compat modules. The design of this patch is based on a discussing in SG-15 on 12.12.2023. (SG-15 is the ISO C++ Tooling study group): - The modules are installed at a location, that is not known to build systems and compilers. - Next to the library there will be a module manifest json file. This json file contains the information to build the module from the libraries sources. This information includes the location where the sources are installed. @ruoso supplied the specification of this json file. - If possible, the compiler has an option to give the location of the module manifest file (#76451). Currently there is no build system support, but it expected to be added in the future. Fixes: #73089
1 parent 0475733 commit 8b47bb6

18 files changed

+109
-1
lines changed

libcxx/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
178178
"Define suffix of library directory name (32/64)")
179179
option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
180180
option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON)
181+
option(LIBCXX_INSTALL_MODULES
182+
"Install the libc++ C++20 module source files (experimental)." OFF
183+
)
181184
cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
182185
"Install the static libc++ library." ON
183186
"LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)
@@ -425,6 +428,8 @@ set(LIBCXX_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE STRING
425428
"Path where target-agnostic libc++ headers should be installed.")
426429
set(LIBCXX_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
427430
"Path where built libc++ runtime libraries should be installed.")
431+
set(LIBCXX_INSTALL_MODULES_DIR "share/libc++/v1" CACHE STRING
432+
"Path where target-agnostic libc++ module source files should be installed.")
428433

429434
set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.")
430435
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,2 +1,3 @@
1+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
12
set(LIBCXX_TEST_PARAMS "std=c++20" CACHE STRING "")
23
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 @@
1+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
12
set(LIBCXX_TEST_PARAMS "std=c++23" CACHE STRING "")
23
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 @@
1+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
12
set(LIBCXX_TEST_PARAMS "std=c++26" CACHE STRING "")
23
set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
12
set(LIBCXX_HARDENING_MODE "extensive" CACHE STRING "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
12
set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
23
set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
12
set(LIBCXX_TEST_PARAMS "enable_experimental=False" CACHE STRING "")
23
set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
12
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
12
set(LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
12
set(LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
12
set(LIBCXX_ENABLE_THREADS OFF CACHE BOOL "")
23
set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
34
set(LIBCXX_ENABLE_MONOTONIC_CLOCK OFF CACHE BOOL "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
12
set(LIBCXX_ENABLE_UNICODE OFF CACHE BOOL "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
set(LIBCXX_INSTALL_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
12
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
@@ -99,6 +99,13 @@ Improvements and New Features
9999
infrastructure no longer depends on a modern CMake, it works with the minimal
100100
required LLVM version (3.20.0).
101101

102+
- The ``.cppm`` files of experimental standard library modules can now be
103+
installed. By default, they are not installed. This can be enabled by
104+
configuring CMake with ``-DLIBCXX_INSTALL_MODULES=ON``. The installation
105+
directory can be configured with the CMake option
106+
``-DLIBCXX_INSTALL_MODULE_DIR=<path>``. The default location is
107+
``${PREFIX}/share/libc++/v1``.
108+
102109

103110
Deprecations and Removals
104111
-------------------------

libcxx/modules/CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,57 @@ add_custom_target(generate-cxx-modules
182182
ALL DEPENDS
183183
${_all_modules}
184184
)
185+
186+
# Configure the modules manifest.
187+
# Use the relative path between the installation and the module in the json
188+
# file. This allows moving the entire installation to a different location.
189+
file(RELATIVE_PATH LIBCXX_MODULE_RELATIVE_PATH
190+
${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_LIBRARY_DIR}
191+
${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_MODULES_DIR})
192+
configure_file(
193+
"modules.json.in"
194+
"${LIBCXX_LIBRARY_DIR}/libc++.modules.json"
195+
@ONLY
196+
)
197+
198+
# Dummy library to make modules an installation component.
199+
add_library(cxx-modules INTERFACE)
200+
add_dependencies(cxx-modules generate-cxx-modules)
201+
202+
if (LIBCXX_INSTALL_MODULES)
203+
foreach(file ${LIBCXX_MODULE_STD_SOURCES} ${LIBCXX_MODULE_STD_COMPAT_SOURCES})
204+
get_filename_component(dir ${file} DIRECTORY)
205+
install(FILES ${file}
206+
DESTINATION "${LIBCXX_INSTALL_MODULES_DIR}/${dir}"
207+
COMPONENT cxx-modules
208+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
209+
)
210+
endforeach()
211+
212+
# Install the generated module files.
213+
install(FILES
214+
"${LIBCXX_GENERATED_MODULE_DIR}/std.cppm"
215+
"${LIBCXX_GENERATED_MODULE_DIR}/std.compat.cppm"
216+
DESTINATION "${LIBCXX_INSTALL_MODULES_DIR}"
217+
COMPONENT cxx-modules
218+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
219+
)
220+
221+
# Install the module manifest.
222+
install(FILES
223+
"${LIBCXX_LIBRARY_DIR}/libc++.modules.json"
224+
DESTINATION "${LIBCXX_INSTALL_LIBRARY_DIR}"
225+
COMPONENT cxx-modules
226+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
227+
)
228+
229+
if (NOT CMAKE_CONFIGURATION_TYPES)
230+
add_custom_target(install-cxx-modules
231+
DEPENDS cxx-modules
232+
COMMAND "${CMAKE_COMMAND}"
233+
-DCMAKE_INSTALL_COMPONENT=cxx-modules
234+
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
235+
# Stripping is a no-op for modules
236+
add_custom_target(install-cxx-modules-stripped DEPENDS install-cxx-modules)
237+
endif()
238+
endif()

libcxx/modules/modules.json.in

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

libcxx/src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,18 +398,23 @@ if (NOT CMAKE_CONFIGURATION_TYPES)
398398
endif()
399399
if(LIBCXX_INSTALL_HEADERS)
400400
set(header_install_target install-cxx-headers)
401+
endif()
402+
if(LIBCXX_INSTALL_MODULES)
403+
set(module_install_target install-cxx-modules)
401404
endif()
402405
add_custom_target(install-cxx
403406
DEPENDS ${lib_install_target}
404407
cxx_experimental
405408
${header_install_target}
409+
${module_install_target}
406410
COMMAND "${CMAKE_COMMAND}"
407411
-DCMAKE_INSTALL_COMPONENT=cxx
408412
-P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
409413
add_custom_target(install-cxx-stripped
410414
DEPENDS ${lib_install_target}
411415
cxx_experimental
412416
${header_install_target}
417+
${module_install_target}
413418
COMMAND "${CMAKE_COMMAND}"
414419
-DCMAKE_INSTALL_COMPONENT=cxx
415420
-DCMAKE_INSTALL_DO_STRIP=1

0 commit comments

Comments
 (0)