Skip to content

Commit 755d04c

Browse files
committed
[DRAFT][libc++][modules] Improves std.compat module.
Based on @ChuanqiXu9's suggestion in llvm#71438.
1 parent b5a6e8a commit 755d04c

File tree

4 files changed

+46
-129
lines changed

4 files changed

+46
-129
lines changed

libcxx/modules/CMakeLists.txt.in

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ cmake_minimum_required(VERSION 3.26)
33
project(libc++-modules LANGUAGES CXX)
44

55
# Enable CMake's module support
6-
if(CMAKE_VERSION VERSION_LESS "3.27.0")
7-
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
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)
813
else()
9-
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "aa1f7df0-828a-4fcd-9afc-2dc80491aca7")
14+
cmake_policy(VERSION 3.28)
1015
endif()
11-
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
1216

1317
# Default to C++ extensions being off. Libc++'s modules support have trouble
1418
# with extensions right now.
@@ -74,9 +78,12 @@ target_compile_options(std.compat
7478
-nostdinc++
7579
-Wno-reserved-module-identifier
7680
-Wno-reserved-user-defined-literal
81+
-fprebuilt-module-path=${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/std.dir/
7782
@LIBCXX_COMPILE_FLAGS@
7883
)
7984
set_target_properties(std.compat
8085
PROPERTIES
8186
OUTPUT_NAME "c++std.compat"
8287
)
88+
link_libraries(std.compat std)
89+
add_dependencies(std.compat std)

libcxx/modules/std.compat.cppm.in

Lines changed: 2 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,17 @@ module;
1717

1818
// The headers of Table 24: C++ library headers [tab:headers.cpp]
1919
// and the headers of Table 25: C++ headers for C library facilities [tab:headers.cpp.c]
20-
#include <algorithm>
21-
#include <any>
22-
#include <array>
23-
#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
24-
# include <atomic>
25-
#endif
26-
#if !defined(_LIBCPP_HAS_NO_THREADS)
27-
# include <barrier>
28-
#endif
29-
#include <bit>
30-
#include <bitset>
3120
#include <cassert>
3221
#include <cctype>
3322
#include <cerrno>
3423
#include <cfenv>
3524
#include <cfloat>
36-
#include <charconv>
37-
#include <chrono>
3825
#include <cinttypes>
3926
#include <climits>
4027
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
4128
# include <clocale>
4229
#endif
4330
#include <cmath>
44-
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
45-
# include <codecvt>
46-
#endif
47-
#include <compare>
48-
#include <complex>
49-
#include <concepts>
50-
#include <condition_variable>
51-
#include <coroutine>
5231
#include <csetjmp>
5332
#include <csignal>
5433
#include <cstdarg>
@@ -65,107 +44,6 @@ module;
6544
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
6645
# include <cwctype>
6746
#endif
68-
#include <deque>
69-
#include <exception>
70-
#include <execution>
71-
#include <expected>
72-
#include <filesystem>
73-
#include <format>
74-
#include <forward_list>
75-
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
76-
# include <fstream>
77-
#endif
78-
#include <functional>
79-
#if !defined(_LIBCPP_HAS_NO_THREADS)
80-
# include <future>
81-
#endif
82-
#include <initializer_list>
83-
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
84-
# include <iomanip>
85-
#endif
86-
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
87-
# include <ios>
88-
#endif
89-
#include <iosfwd>
90-
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
91-
# include <iostream>
92-
#endif
93-
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
94-
# include <istream>
95-
#endif
96-
#include <iterator>
97-
#if !defined(_LIBCPP_HAS_NO_THREADS)
98-
# include <latch>
99-
#endif
100-
#include <limits>
101-
#include <list>
102-
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
103-
# include <locale>
104-
#endif
105-
#include <map>
106-
#include <mdspan>
107-
#include <memory>
108-
#include <memory_resource>
109-
#include <mutex>
110-
#include <new>
111-
#include <numbers>
112-
#include <numeric>
113-
#include <optional>
114-
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
115-
# include <ostream>
116-
#endif
117-
#include <print>
118-
#include <queue>
119-
#include <random>
120-
#include <ranges>
121-
#include <ratio>
122-
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
123-
# include <regex>
124-
#endif
125-
#include <scoped_allocator>
126-
#if !defined(_LIBCPP_HAS_NO_THREADS)
127-
# include <semaphore>
128-
#endif
129-
#include <set>
130-
#if !defined(_LIBCPP_HAS_NO_THREADS)
131-
# include <shared_mutex>
132-
#endif
133-
#include <source_location>
134-
#include <span>
135-
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
136-
# include <sstream>
137-
#endif
138-
#include <stack>
139-
#include <stdexcept>
140-
#if !defined(_LIBCPP_HAS_NO_THREADS)
141-
# include <stop_token>
142-
#endif
143-
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
144-
# include <streambuf>
145-
#endif
146-
#include <string>
147-
#include <string_view>
148-
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
149-
# include <strstream>
150-
#endif
151-
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
152-
# include <syncstream>
153-
#endif
154-
#include <system_error>
155-
#if !defined(_LIBCPP_HAS_NO_THREADS)
156-
# include <thread>
157-
#endif
158-
#include <tuple>
159-
#include <type_traits>
160-
#include <typeindex>
161-
#include <typeinfo>
162-
#include <unordered_map>
163-
#include <unordered_set>
164-
#include <utility>
165-
#include <valarray>
166-
#include <variant>
167-
#include <vector>
168-
#include <version>
16947

17048
// *** Headers not yet available ***
17149
#if __has_include(<debugging>)
@@ -203,6 +81,7 @@ module;
20381
#endif // __has_include(<text_encoding>)
20482

20583
export module std.compat;
84+
export import std;
85+
20686

207-
@LIBCXX_MODULE_STD_INCLUDE_SOURCES@
20887
@LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@

libcxx/modules/std.cppm.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,5 @@ module;
204204

205205
export module std;
206206

207+
207208
@LIBCXX_MODULE_STD_INCLUDE_SOURCES@

libcxx/utils/generate_libcxx_cppm_in.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,35 @@
1515

1616

1717
def write_file(module):
18+
19+
# TODO REMOVE THIS HACK, WE NEED A BETTER WAY TO DETECT C HEADERS
20+
Module_headers = (
21+
module_headers
22+
if module == "std"
23+
else [
24+
"cassert",
25+
"cctype",
26+
"cerrno",
27+
"cfenv",
28+
"cfloat",
29+
"cinttypes",
30+
"climits",
31+
"clocale",
32+
"cmath",
33+
"csetjmp",
34+
"csignal",
35+
"cstdarg",
36+
"cstddef",
37+
"cstdint",
38+
"cstdio",
39+
"cstdlib",
40+
"cstring",
41+
"ctime",
42+
"cuchar",
43+
"cwchar",
44+
"cwctype",
45+
]
46+
)
1847
libcxx_module_directory = os.path.join(
1948
os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "modules"
2049
)
@@ -44,7 +73,7 @@ def write_file(module):
4473
// and the headers of Table 25: C++ headers for C library facilities [tab:headers.cpp.c]
4574
"""
4675
)
47-
for header in module_headers:
76+
for header in Module_headers:
4877
if header in header_restrictions:
4978
module_cpp_in.write(
5079
f"""\
@@ -69,8 +98,9 @@ def write_file(module):
6998
module_cpp_in.write(
7099
f"""
71100
export module {module};
101+
{'export import std;' if module == 'std.compat' else ''}
72102
73-
@LIBCXX_MODULE_STD_INCLUDE_SOURCES@
103+
{'@LIBCXX_MODULE_STD_INCLUDE_SOURCES@' if module == 'std' else ''}
74104
{'@LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@' if module == 'std.compat' else ''}"""
75105
)
76106

0 commit comments

Comments
 (0)