Skip to content

Commit 5c150e7

Browse files
committed
Revert #76246 and #76083
These cause test build failures on Windows. This reverts the following commits: 57ca748 d06ae33
1 parent 8434e5d commit 5c150e7

36 files changed

+298
-200
lines changed

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ concurrency:
3535

3636

3737
env:
38+
CMAKE: "/opt/bin/cmake"
3839
# LLVM POST-BRANCH bump version
3940
# LLVM POST-BRANCH add compiler test for ToT - 1, e.g. "Clang 17"
4041
# LLVM RELEASE bump remove compiler ToT - 3, e.g. "Clang 15"
@@ -168,18 +169,24 @@ jobs:
168169
'bootstrapping-build'
169170
]
170171
machine: [ 'libcxx-runners-8-set' ]
172+
std_modules: [ 'OFF' ]
171173
include:
172174
- config: 'generic-cxx26'
173175
machine: libcxx-runners-8-set
176+
std_modules: 'ON'
174177
- config: 'generic-asan'
175178
machine: libcxx-runners-8-set
179+
std_modules: 'OFF'
176180
- config: 'generic-tsan'
177181
machine: libcxx-runners-8-set
182+
std_modules: 'OFF'
178183
- config: 'generic-ubsan'
179184
machine: libcxx-runners-8-set
185+
std_modules: 'OFF'
180186
# Use a larger machine for MSAN to avoid timeout and memory allocation issues.
181187
- config: 'generic-msan'
182188
machine: libcxx-runners-8-set
189+
std_modules: 'OFF'
183190
runs-on: ${{ matrix.machine }}
184191
steps:
185192
- uses: actions/checkout@v4
@@ -189,6 +196,7 @@ jobs:
189196
CC: clang-18
190197
CXX: clang++-18
191198
ENABLE_CLANG_TIDY: "OFF"
199+
ENABLE_STD_MODULES: ${{ matrix.std_modules }}
192200
- uses: actions/upload-artifact@v3
193201
if: always()
194202
with:

libcxx/CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
124124
the shared library they shipped should turn this on and see `include/__availability`
125125
for more details." OFF)
126126
option(LIBCXX_ENABLE_CLANG_TIDY "Whether to compile and run clang-tidy checks" OFF)
127+
# TODO MODULES Remove this option and test for the requirements (CMake/Clang) instead.
128+
option(LIBCXX_ENABLE_STD_MODULES
129+
"Whether to enable the building the C++23 `std` module. This feature is
130+
experimental and has additional dependencies. Only enable this when
131+
interested in testing or developing this module. See
132+
https://libcxx.llvm.org/Modules.html for more information." OFF)
127133

128134
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
129135
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")
@@ -773,6 +779,7 @@ config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE)
773779
config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION)
774780
config_define_if_not(LIBCXX_ENABLE_UNICODE _LIBCPP_HAS_NO_UNICODE)
775781
config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTERS)
782+
config_define_if_not(LIBCXX_ENABLE_STD_MODULES _LIBCPP_HAS_NO_STD_MODULES)
776783
config_define_if_not(LIBCXX_ENABLE_TIME_ZONE_DATABASE _LIBCPP_HAS_NO_TIME_ZONE_DATABASE)
777784
config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
778785

@@ -856,15 +863,19 @@ endfunction()
856863
add_subdirectory(include)
857864
add_subdirectory(src)
858865
add_subdirectory(utils)
859-
add_subdirectory(modules)
866+
if (LIBCXX_ENABLE_STD_MODULES)
867+
add_subdirectory(modules)
868+
endif()
860869

861870
set(LIBCXX_TEST_DEPS "cxx_experimental")
862871

863872
if (LIBCXX_ENABLE_CLANG_TIDY)
864873
list(APPEND LIBCXX_TEST_DEPS cxx-tidy)
865874
endif()
866875

867-
list(APPEND LIBCXX_TEST_DEPS generate-cxx-modules)
876+
if (LIBCXX_ENABLE_STD_MODULES)
877+
list(APPEND LIBCXX_TEST_DEPS generate-cxx-modules generate-test-module-std)
878+
endif()
868879

869880
if (LIBCXX_INCLUDE_BENCHMARKS)
870881
add_subdirectory(benchmarks)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
set(LIBCXX_ENABLE_STD_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_ENABLE_STD_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_ENABLE_STD_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_ENABLE_STD_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_ENABLE_STD_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_ENABLE_STD_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_ENABLE_STD_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_ENABLE_STD_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_ENABLE_STD_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
12
set(LIBCXX_ENABLE_TIME_ZONE_DATABASE OFF CACHE BOOL "")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
set(LIBCXX_ENABLE_STD_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_ENABLE_STD_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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ directory. First libc++ needs to be build with module support enabled.
115115
$ git clone https://github.com/llvm/llvm-project.git
116116
$ cd llvm-project
117117
$ mkdir build
118-
$ cmake -G Ninja -S runtimes -B build -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind"
118+
$ cmake -G Ninja -S runtimes -B build -DLIBCXX_ENABLE_STD_MODULES=ON -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind"
119119
$ ninja -C build
120120
121121
The above ``build`` directory will be referred to as ``<build>`` in the

libcxx/docs/ReleaseNotes/18.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ Improvements and New Features
8989
- The ``_LIBCPP_ENABLE_CXX20_REMOVED_SHARED_PTR_UNIQUE`` macro has been added to make
9090
the function ``std::shared_ptr<...>::unique()`` available.
9191

92-
- The cmake option ``LIBCXX_ENABLE_STD_MODULES`` has been removed. The test
93-
infrastructure no longer depends on a modern CMake, it works with the minimal
94-
required LLVM version (3.20.0).
95-
9692

9793
Deprecations and Removals
9894
-------------------------

libcxx/docs/TestingLibcxx.rst

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ Custom Directives
394394
~~~~~~~~~~~~~~~~~
395395

396396
Lit has many directives built in (e.g., ``DEFINE``, ``UNSUPPORTED``). In addition to those directives, libc++ adds two additional libc++-specific directives that makes
397-
writing tests easier. See `libc++-specific Lit Directives`_ for more information about the ``FILE_DEPENDENCIES``, ``ADDITIONAL_COMPILE_FLAGS``, and ``MODULE_DEPENDENCIES`` libc++-specific directives.
397+
writing tests easier. See `libc++-specific Lit Directives`_ for more information about the ``FILE_DEPENDENCIES`` and ``ADDITIONAL_COMPILE_FLAGS`` libc++-specific directives.
398398

399399
.. _libc++-specific Lit Directives:
400400
.. list-table:: libc++-specific Lit Directives
@@ -417,13 +417,6 @@ writing tests easier. See `libc++-specific Lit Directives`_ for more information
417417
- The additional compiler flags specified by a space-separated list to the ``ADDITIONAL_COMPILE_FLAGS`` libc++-specific Lit directive will be added to the end of the ``%{compile_flags}``
418418
substitution for the test that contains it. This libc++-specific Lit directive makes it possible to add special compilation flags without having to resort to writing a ``.sh.cpp`` test (see
419419
`Lit Meaning of libc++ Test Filenames`_), more powerful but perhaps overkill.
420-
* - ``MODULE_DEPENDENCIES``
421-
- ``// MODULE_DEPENDENCIES: std std.compat``
422-
- This directive will build the required C++23 standard library
423-
modules and add the additional compiler flags in
424-
%{compile_flags}. (Libc++ offers these modules in C++20 as an
425-
extension.)
426-
427420

428421
Benchmarks
429422
==========

libcxx/modules/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
if (CMAKE_VERSION VERSION_LESS 3.26)
2+
message(WARNING "The libc++ modules won't be available because the CMake version is too old. Update to CMake 3.26 or later.")
3+
return()
4+
endif()
5+
16
# The headers of Table 24: C++ library headers [tab:headers.cpp]
27
# and the headers of Table 25: C++ headers for C library facilities [tab:headers.cpp.c]
38
set(LIBCXX_MODULE_STD_SOURCES
@@ -137,6 +142,28 @@ set(LIBCXX_MODULE_STD_COMPAT_SOURCES
137142
std.compat/cwctype.inc
138143
)
139144

145+
# TODO MODULES the CMakeLists.txt in the install directory is only temporary
146+
# When that is removed the configured file can use the substitution
147+
# LIBCXX_GENERATED_INCLUDE_TARGET_DIR avoiding this set.
148+
# Also clean up the parts needed to generate the install version.
149+
# - LIBCXX_GENERATED_INCLUDE_DIR contains the libc++ headers
150+
# - LIBCXX_GENERATED_INCLUDE_TARGET_DIR contains the libc++ site config
151+
if ("${LIBCXX_GENERATED_INCLUDE_DIR}" STREQUAL "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}")
152+
# This typically happens when the target is not installed.
153+
set(LIBCXX_CONFIGURED_INCLUDE_DIRS "${LIBCXX_GENERATED_INCLUDE_DIR}")
154+
else()
155+
# It's important that the arch directory be included first so that its header files
156+
# which interpose on the default include dir be included instead of the default ones.
157+
set(LIBCXX_CONFIGURED_INCLUDE_DIRS
158+
"${LIBCXX_GENERATED_INCLUDE_TARGET_DIR};${LIBCXX_GENERATED_INCLUDE_DIR}"
159+
)
160+
endif()
161+
configure_file(
162+
"CMakeLists.txt.in"
163+
"${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt"
164+
@ONLY
165+
)
166+
140167
set(LIBCXX_MODULE_STD_INCLUDE_SOURCES)
141168
foreach(file ${LIBCXX_MODULE_STD_SOURCES})
142169
set(
@@ -166,6 +193,7 @@ configure_file(
166193
)
167194

168195
set(_all_modules)
196+
list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt")
169197
list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.cppm")
170198
list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.compat.cppm")
171199
foreach(file ${LIBCXX_MODULE_STD_SOURCES} ${LIBCXX_MODULE_STD_COMPAT_SOURCES})

libcxx/modules/CMakeLists.txt.in

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
cmake_minimum_required(VERSION 3.26)
2+
3+
project(libc++-modules LANGUAGES CXX)
4+
5+
# Enable CMake's module support
6+
if(CMAKE_VERSION VERSION_LESS "3.28.0")
7+
if(CMAKE_VERSION VERSION_LESS "3.27.0")
8+
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
9+
else()
10+
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "aa1f7df0-828a-4fcd-9afc-2dc80491aca7")
11+
endif()
12+
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
13+
else()
14+
cmake_policy(VERSION 3.28)
15+
endif()
16+
17+
# Default to C++ extensions being off. Libc++'s modules support have trouble
18+
# with extensions right now.
19+
set(CMAKE_CXX_EXTENSIONS OFF)
20+
21+
# Propagates the CMake options to the modules.
22+
#
23+
# This uses the std module hard-coded since the std.compat module does not
24+
# depend on these flags.
25+
macro(compile_define_if_not condition def)
26+
if (NOT ${condition})
27+
target_compile_definitions(std PRIVATE ${def})
28+
endif()
29+
endmacro()
30+
macro(compile_define_if condition def)
31+
if (${condition})
32+
target_compile_definitions(std PRIVATE ${def})
33+
endif()
34+
endmacro()
35+
36+
### STD
37+
38+
add_library(std)
39+
target_sources(std
40+
PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
41+
std.cppm
42+
)
43+
44+
target_include_directories(std SYSTEM PRIVATE @LIBCXX_CONFIGURED_INCLUDE_DIRS@)
45+
46+
if (NOT @LIBCXX_ENABLE_EXCEPTIONS@)
47+
target_compile_options(std PUBLIC -fno-exceptions)
48+
endif()
49+
50+
target_compile_options(std
51+
PUBLIC
52+
-nostdinc++
53+
-Wno-reserved-module-identifier
54+
-Wno-reserved-user-defined-literal
55+
@LIBCXX_COMPILE_FLAGS@
56+
)
57+
set_target_properties(std
58+
PROPERTIES
59+
OUTPUT_NAME "c++std"
60+
)
61+
62+
### STD.COMPAT
63+
64+
add_library(std.compat)
65+
target_sources(std.compat
66+
PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
67+
std.compat.cppm
68+
)
69+
70+
target_include_directories(std.compat SYSTEM PRIVATE @LIBCXX_CONFIGURED_INCLUDE_DIRS@)
71+
72+
if (NOT @LIBCXX_ENABLE_EXCEPTIONS@)
73+
target_compile_options(std.compat PUBLIC -fno-exceptions)
74+
endif()
75+
76+
target_compile_options(std.compat
77+
PUBLIC
78+
-nostdinc++
79+
-Wno-reserved-module-identifier
80+
-Wno-reserved-user-defined-literal
81+
@LIBCXX_COMPILE_FLAGS@
82+
)
83+
set_target_properties(std.compat
84+
PROPERTIES
85+
OUTPUT_NAME "c++std.compat"
86+
)

libcxx/test/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,31 @@ if (LIBCXX_INCLUDE_TESTS)
8787
${CMAKE_CURRENT_BINARY_DIR}
8888
DEPENDS cxx-test-depends)
8989

90+
if(LIBCXX_ENABLE_STD_MODULES)
91+
# Generates the modules used in the test.
92+
# Note the test will regenerate this with the proper setting
93+
# - the right DCMAKE_CXX_STANDARD
94+
# - the right test compilation flags
95+
# Since modules depend on these flags there currently is no way to
96+
# avoid generating these for the tests. The advantage of the
97+
# pre generation is that less build information needs to be shared
98+
# in the bridge.
99+
add_custom_command(
100+
OUTPUT "${CMAKE_BINARY_DIR}/test/__config_module__/CMakeCache.txt"
101+
COMMAND
102+
${CMAKE_COMMAND}
103+
"-G${CMAKE_GENERATOR}"
104+
"-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}"
105+
"-B${CMAKE_BINARY_DIR}/test/__config_module__"
106+
"-H${LIBCXX_GENERATED_MODULE_DIR}"
107+
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
108+
"-DCMAKE_CXX_STANDARD=23"
109+
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
110+
)
111+
add_custom_target(generate-test-module-std
112+
DEPENDS "${CMAKE_BINARY_DIR}/test/__config_module__/CMakeCache.txt"
113+
COMMENT "Builds generic module std.")
114+
endif()
90115
endif()
91116

92117
if (LIBCXX_GENERATE_COVERAGE)

libcxx/test/configs/cmake-bridge.cfg.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ config.substitutions.append(('%{target-include}', '@LIBCXX_GENERATED_INCLUDE_TAR
3131
config.substitutions.append(('%{lib}', '@LIBCXX_LIBRARY_DIR@'))
3232
config.substitutions.append(('%{module}', '@LIBCXX_GENERATED_MODULE_DIR@'))
3333
config.substitutions.append(('%{test-tools}', '@LIBCXX_TEST_TOOLS_PATH@'))
34+
35+
# The test needs to manually rebuild the module. The compiler flags used in the
36+
# test need to be the same as the compiler flags used to generate the module.
37+
# In the future, when CMake can generated modules this may no longer be
38+
# necessary.
39+
# TODO MODULES whether it's possible to remove this substitution.
40+
config.substitutions.append(('%{cmake}', '@CMAKE_COMMAND@'))

libcxx/test/libcxx/module_std.gen.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
3131
"%{cxx}",
3232
"%{flags} %{compile_flags}",
33-
"std",
3433
)
3534

3635

libcxx/test/libcxx/module_std_compat.gen.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
3131
"%{cxx}",
3232
"%{flags} %{compile_flags}",
33-
"std.compat",
3433
)
3534

3635

libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)