Skip to content

Commit f4b14ed

Browse files
committed
[libc++] Make __config_site modular
This patch makes the __config_site header modular, which solves various problems with non-modular headers. This requires going back to generating the modulemap file, since we only know how to make __config_site modular when we're not using the per-target runtime dir. The patch also adds a test that we support -Wnon-modular-include-in-module, which warns about non-modular includes from modules.
1 parent c22586a commit f4b14ed

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

libcxx/docs/Contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ sure you don't forget anything:
116116
- Did you add all new named declarations to the ``std`` module?
117117
- If you added a header:
118118

119-
- Did you add it to ``include/module.modulemap``?
119+
- Did you add it to ``include/module.modulemap.in``?
120120
- Did you add it to ``include/CMakeLists.txt``?
121121
- If it's a public header, did you update ``utils/libcxx/header_information.py``?
122122

libcxx/include/CMakeLists.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,6 @@ set(files
10211021
mdspan
10221022
memory
10231023
memory_resource
1024-
module.modulemap
10251024
mutex
10261025
new
10271026
numbers
@@ -2097,8 +2096,16 @@ set(files
20972096
configure_file("__config_site.in" "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site" @ONLY)
20982097
configure_file("${LIBCXX_ASSERTION_HANDLER_FILE}" "${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler" COPYONLY)
20992098

2099+
# We generate the modulemap file so that we can include __config_site in it. For now, we don't know how to
2100+
# make __config_site modular when per-target runtime directories are used.
2101+
if (NOT LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
2102+
set(LIBCXX_CONFIG_SITE_MODULE_ENTRY "textual header \"__config_site\"")
2103+
endif()
2104+
configure_file("module.modulemap.in" "${LIBCXX_GENERATED_INCLUDE_DIR}/module.modulemap" @ONLY)
2105+
21002106
set(_all_includes "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site"
2101-
"${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler")
2107+
"${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler"
2108+
"${LIBCXX_GENERATED_INCLUDE_DIR}/module.modulemap")
21022109
foreach(f ${files})
21032110
set(src "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
21042111
set(dst "${LIBCXX_GENERATED_INCLUDE_DIR}/${f}")
@@ -2156,6 +2163,12 @@ if (LIBCXX_INSTALL_HEADERS)
21562163
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
21572164
COMPONENT cxx-headers)
21582165

2166+
# Install the generated modulemap file to the generic include dir.
2167+
install(FILES "${LIBCXX_GENERATED_INCLUDE_DIR}/module.modulemap"
2168+
DESTINATION "${LIBCXX_INSTALL_INCLUDE_DIR}"
2169+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
2170+
COMPONENT cxx-headers)
2171+
21592172
if (NOT CMAKE_CONFIGURATION_TYPES)
21602173
add_custom_target(install-cxx-headers
21612174
DEPENDS cxx-headers

libcxx/include/module.modulemap renamed to libcxx/include/module.modulemap.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// This module contains headers related to the configuration of the library. These headers
22
// are free of any dependency on the rest of libc++.
33
module std_config [system] {
4+
@LIBCXX_CONFIG_SITE_MODULE_ENTRY@ // generated via CMake
45
textual header "__config"
56
textual header "__configuration/abi.h"
67
textual header "__configuration/availability.h"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: target={{.*}}-apple-{{.*}}
10+
11+
// This test ensures that libc++ supports being compiled with modules enabled and with
12+
// -Wnon-modular-include-in-module. This effectively checks that we don't include any
13+
// non-modular header from the library.
14+
//
15+
// Since most underlying platforms are not modularized properly, this test currently only
16+
// works on Apple platforms.
17+
18+
// ADDITIONAL_COMPILE_FLAGS: -Wnon-modular-include-in-module -Wsystem-headers-in-module=std -fmodules -fcxx-modules
19+
20+
#include <vector>

libcxx/test/libcxx/lint/lint_headers.sh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def exclude_from_consideration(path):
1212
return (
1313
path.endswith(".txt")
14-
or path.endswith(".modulemap")
14+
or path.endswith(".modulemap.in")
1515
or os.path.basename(path) == "__config"
1616
or os.path.basename(path) == "__config_site.in"
1717
or os.path.basename(path) == "libcxx.imp"

libcxx/utils/libcxx/header_information.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def _is_header_file(file):
1616
"""Returns whether the given file is a header file, i.e. not a directory or the modulemap file."""
1717
return not file.is_dir() and not file.name in [
18-
"module.modulemap",
18+
"module.modulemap.in",
1919
"CMakeLists.txt",
2020
"libcxx.imp",
2121
"__config_site.in",

0 commit comments

Comments
 (0)