Skip to content

[libc++] Make __config_site modular #134699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libcxx/docs/Contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ sure you don't forget anything:
- Did you add all new named declarations to the ``std`` module?
- If you added a header:

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

Expand Down
17 changes: 15 additions & 2 deletions libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,6 @@ set(files
mdspan
memory
memory_resource
module.modulemap
mutex
new
numbers
Expand Down Expand Up @@ -1667,8 +1666,16 @@ set(files
configure_file("__config_site.in" "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site" @ONLY)
configure_file("${LIBCXX_ASSERTION_HANDLER_FILE}" "${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler" COPYONLY)

# We generate the modulemap file so that we can include __config_site in it. For now, we don't know how to
# make __config_site modular when per-target runtime directories are used.
if (NOT LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
set(LIBCXX_CONFIG_SITE_MODULE_ENTRY "textual header \"__config_site\"")
endif()
configure_file("module.modulemap.in" "${LIBCXX_GENERATED_INCLUDE_DIR}/module.modulemap" @ONLY)

set(_all_includes "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site"
"${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler")
"${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler"
"${LIBCXX_GENERATED_INCLUDE_DIR}/module.modulemap")
foreach(f ${files})
set(src "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
set(dst "${LIBCXX_GENERATED_INCLUDE_DIR}/${f}")
Expand Down Expand Up @@ -1726,6 +1733,12 @@ if (LIBCXX_INSTALL_HEADERS)
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
COMPONENT cxx-headers)

# Install the generated modulemap file to the generic include dir.
install(FILES "${LIBCXX_GENERATED_INCLUDE_DIR}/module.modulemap"
DESTINATION "${LIBCXX_INSTALL_INCLUDE_DIR}"
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
COMPONENT cxx-headers)

if (NOT CMAKE_CONFIGURATION_TYPES)
add_custom_target(install-cxx-headers
DEPENDS cxx-headers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This module contains headers related to the configuration of the library. These headers
// are free of any dependency on the rest of libc++.
module std_config [system] {
@LIBCXX_CONFIG_SITE_MODULE_ENTRY@ // generated via CMake
textual header "__config"
textual header "__configuration/abi.h"
textual header "__configuration/availability.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// REQUIRES: target={{.*}}-apple-{{.*}}
// UNSUPPORTED: c++03

// This test ensures that libc++ supports being compiled with modules enabled and with
// -Wnon-modular-include-in-module. This effectively checks that we don't include any
// non-modular header from the library.
//
// Since most underlying platforms are not modularized properly, this test currently only
// works on Apple platforms.

// ADDITIONAL_COMPILE_FLAGS: -Wnon-modular-include-in-module -Wsystem-headers-in-module=std -fmodules -fcxx-modules

#include <vector>
2 changes: 1 addition & 1 deletion libcxx/test/libcxx/headers_in_modulemap.sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
sys.path.append(sys.argv[1])
from libcxx.header_information import all_headers, libcxx_include

with open(libcxx_include / "module.modulemap") as f:
with open(libcxx_include / "module.modulemap.in") as f:
modulemap = f.read()

isHeaderMissing = False
Expand Down
2 changes: 1 addition & 1 deletion libcxx/test/libcxx/lint/lint_headers.sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def exclude_from_consideration(path):
return (
path.endswith(".txt")
or path.endswith(".modulemap")
or path.endswith(".modulemap.in")
or os.path.basename(path) == "__config"
or os.path.basename(path) == "__config_site.in"
or os.path.basename(path) == "libcxx.imp"
Expand Down
2 changes: 1 addition & 1 deletion libcxx/utils/libcxx/header_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def _is_header_file(file):
"""Returns whether the given file is a header file, i.e. not a directory or the modulemap file."""
return not file.is_dir() and not file.name in [
"module.modulemap",
"module.modulemap.in",
"CMakeLists.txt",
"libcxx.imp",
"__config_site.in",
Expand Down
Loading