Skip to content

Commit 860e884

Browse files
ldionnevar-const
andauthored
[libc++] Make __config_site modular (#134699)
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. --------- Co-authored-by: Konstantin Varlamov <varconst@apple.com>
1 parent 622765f commit 860e884

7 files changed

+41
-6
lines changed

libcxx/docs/Contributing.rst

+1-1
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

+15-2
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,6 @@ set(files
10271027
mdspan
10281028
memory
10291029
memory_resource
1030-
module.modulemap
10311030
mutex
10321031
new
10331032
numbers
@@ -1667,8 +1666,16 @@ set(files
16671666
configure_file("__config_site.in" "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site" @ONLY)
16681667
configure_file("${LIBCXX_ASSERTION_HANDLER_FILE}" "${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler" COPYONLY)
16691668

1669+
# We generate the modulemap file so that we can include __config_site in it. For now, we don't know how to
1670+
# make __config_site modular when per-target runtime directories are used.
1671+
if (NOT LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
1672+
set(LIBCXX_CONFIG_SITE_MODULE_ENTRY "textual header \"__config_site\"")
1673+
endif()
1674+
configure_file("module.modulemap.in" "${LIBCXX_GENERATED_INCLUDE_DIR}/module.modulemap" @ONLY)
1675+
16701676
set(_all_includes "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site"
1671-
"${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler")
1677+
"${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler"
1678+
"${LIBCXX_GENERATED_INCLUDE_DIR}/module.modulemap")
16721679
foreach(f ${files})
16731680
set(src "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
16741681
set(dst "${LIBCXX_GENERATED_INCLUDE_DIR}/${f}")
@@ -1726,6 +1733,12 @@ if (LIBCXX_INSTALL_HEADERS)
17261733
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
17271734
COMPONENT cxx-headers)
17281735

1736+
# Install the generated modulemap file to the generic include dir.
1737+
install(FILES "${LIBCXX_GENERATED_INCLUDE_DIR}/module.modulemap"
1738+
DESTINATION "${LIBCXX_INSTALL_INCLUDE_DIR}"
1739+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
1740+
COMPONENT cxx-headers)
1741+
17291742
if (NOT CMAKE_CONFIGURATION_TYPES)
17301743
add_custom_target(install-cxx-headers
17311744
DEPENDS cxx-headers

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

+1
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"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// UNSUPPORTED: c++03
11+
12+
// This test ensures that libc++ supports being compiled with modules enabled and with
13+
// -Wnon-modular-include-in-module. This effectively checks that we don't include any
14+
// non-modular header from the library.
15+
//
16+
// Since most underlying platforms are not modularized properly, this test currently only
17+
// works on Apple platforms.
18+
19+
// ADDITIONAL_COMPILE_FLAGS: -Wnon-modular-include-in-module -Wsystem-headers-in-module=std -fmodules -fcxx-modules
20+
21+
#include <vector>

libcxx/test/libcxx/headers_in_modulemap.sh.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
sys.path.append(sys.argv[1])
55
from libcxx.header_information import all_headers, libcxx_include
66

7-
with open(libcxx_include / "module.modulemap") as f:
7+
with open(libcxx_include / "module.modulemap.in") as f:
88
modulemap = f.read()
99

1010
isHeaderMissing = False

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

+1-1
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

+1-1
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)