Skip to content

Commit e020e08

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 b689e16 commit e020e08

16 files changed

+105
-1
lines changed

libcxx/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ 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+
cmake_dependent_option(LIBCXX_INSTALL_MODULE_INTERFACE_UNIT_SOURCES
182+
"Install the libc++ C++20 module interface unit source files (experimental)." OFF
183+
"LIBCXX_ENABLE_STD_MODULES" OFF
184+
)
181185
cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
182186
"Install the static libc++ library." ON
183187
"LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF)
@@ -425,6 +429,8 @@ set(LIBCXX_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE STRING
425429
"Path where target-agnostic libc++ headers should be installed.")
426430
set(LIBCXX_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
427431
"Path where built libc++ runtime libraries should be installed.")
432+
set(LIBCXX_INSTALL_MODULE_INTERFACE_UNIT_SOURCE_DIR "share/libc++/v1" CACHE STRING
433+
"Path where target-agnostic libc++ module interface unit source should be installed.")
428434

429435
set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.")
430436
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++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
@@ -93,6 +93,13 @@ Improvements and New Features
9393
infrastructure no longer depends on a modern CMake, it works with the minimal
9494
required LLVM version (3.20.0).
9595

96+
- The ``.cppm`` files of experimental standard library modules can now be
97+
installed. By default, they are not installed. This can be enabled by
98+
configuring CMake with ``-DLIBCXX_INSTALL_MODULES=ON``. The installation
99+
directory can be configured with the CMake option
100+
``-DLIBCXX_INSTALL_MODULE_DIR=<path>``. The default location is
101+
``share/libc++/v1`` in the same prefix as the ``include`` directory.
102+
96103

97104
Deprecations and Removals
98105
-------------------------

libcxx/modules/CMakeLists.txt

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

0 commit comments

Comments
 (0)