Skip to content

Commit 600462a

Browse files
authored
[libc++][modules] Adds std.compat module. (#71438)
This adds the std.compat module. The patch contains a bit of refactoring to avoid code duplication between the std and std.compat module. Implements parts of - P2465R3 Standard Library Modules std and std.compat
1 parent a176710 commit 600462a

34 files changed

+1775
-306
lines changed

libcxx/modules/CMakeLists.txt

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,30 @@ set(LIBCXX_MODULE_STD_SOURCES
118118
std/version.inc
119119
)
120120

121+
set(LIBCXX_MODULE_STD_COMPAT_SOURCES
122+
std.compat/cassert.inc
123+
std.compat/cctype.inc
124+
std.compat/cerrno.inc
125+
std.compat/cfenv.inc
126+
std.compat/cfloat.inc
127+
std.compat/cinttypes.inc
128+
std.compat/climits.inc
129+
std.compat/clocale.inc
130+
std.compat/cmath.inc
131+
std.compat/csetjmp.inc
132+
std.compat/csignal.inc
133+
std.compat/cstdarg.inc
134+
std.compat/cstddef.inc
135+
std.compat/cstdint.inc
136+
std.compat/cstdio.inc
137+
std.compat/cstdlib.inc
138+
std.compat/cstring.inc
139+
std.compat/ctime.inc
140+
std.compat/cuchar.inc
141+
std.compat/cwchar.inc
142+
std.compat/cwctype.inc
143+
)
144+
121145
# TODO MODULES the CMakeLists.txt in the install directory is only temporary
122146
# When that is removed the configured file can use the substitution
123147
# LIBCXX_GENERATED_INCLUDE_TARGET_DIR avoiding this set.
@@ -154,10 +178,25 @@ configure_file(
154178
@ONLY
155179
)
156180

181+
set(LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES)
182+
foreach(file ${LIBCXX_MODULE_STD_COMPAT_SOURCES})
183+
set(
184+
LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES
185+
"${LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES}#include \"${file}\"\n"
186+
)
187+
endforeach()
188+
189+
configure_file(
190+
"std.compat.cppm.in"
191+
"${LIBCXX_GENERATED_MODULE_DIR}/std.compat.cppm"
192+
@ONLY
193+
)
194+
157195
set(_all_modules)
158196
list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt")
159197
list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.cppm")
160-
foreach(file ${LIBCXX_MODULE_STD_SOURCES})
198+
list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.compat.cppm")
199+
foreach(file ${LIBCXX_MODULE_STD_SOURCES} ${LIBCXX_MODULE_STD_COMPAT_SOURCES})
161200
set(src "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
162201
set(dst "${LIBCXX_GENERATED_MODULE_DIR}/${file}")
163202
add_custom_command(OUTPUT ${dst}

libcxx/modules/CMakeLists.txt.in

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ macro(compile_define_if condition def)
2929
endif()
3030
endmacro()
3131

32+
### STD
33+
3234
add_library(std)
3335
target_sources(std
3436
PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
@@ -52,3 +54,29 @@ set_target_properties(std
5254
PROPERTIES
5355
OUTPUT_NAME "c++std"
5456
)
57+
58+
### STD.COMPAT
59+
60+
add_library(std.compat)
61+
target_sources(std.compat
62+
PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
63+
std.compat.cppm
64+
)
65+
66+
target_include_directories(std.compat SYSTEM PRIVATE @LIBCXX_CONFIGURED_INCLUDE_DIRS@)
67+
68+
if (NOT @LIBCXX_ENABLE_EXCEPTIONS@)
69+
target_compile_options(std.compat PUBLIC -fno-exceptions)
70+
endif()
71+
72+
target_compile_options(std.compat
73+
PUBLIC
74+
-nostdinc++
75+
-Wno-reserved-module-identifier
76+
-Wno-reserved-user-defined-literal
77+
@LIBCXX_COMPILE_FLAGS@
78+
)
79+
set_target_properties(std.compat
80+
PROPERTIES
81+
OUTPUT_NAME "c++std.compat"
82+
)

libcxx/modules/std.compat.cppm.in

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
// WARNING, this entire header is generated by
11+
// utils/generate_libcxx_cppm_in.py
12+
// DO NOT MODIFY!
13+
14+
module;
15+
16+
#include <__config>
17+
18+
// The headers of Table 24: C++ library headers [tab:headers.cpp]
19+
// 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>
31+
#include <cassert>
32+
#include <cctype>
33+
#include <cerrno>
34+
#include <cfenv>
35+
#include <cfloat>
36+
#include <charconv>
37+
#include <chrono>
38+
#include <cinttypes>
39+
#include <climits>
40+
#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
41+
# include <clocale>
42+
#endif
43+
#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>
52+
#include <csetjmp>
53+
#include <csignal>
54+
#include <cstdarg>
55+
#include <cstddef>
56+
#include <cstdint>
57+
#include <cstdio>
58+
#include <cstdlib>
59+
#include <cstring>
60+
#include <ctime>
61+
#include <cuchar>
62+
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
63+
# include <cwchar>
64+
#endif
65+
#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
66+
# include <cwctype>
67+
#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>
169+
170+
// *** Headers not yet available ***
171+
#if __has_include(<debugging>)
172+
# error "please update the header information for <debugging> in headers_not_available in utils/libcxx/header_information.py"
173+
#endif // __has_include(<debugging>)
174+
#if __has_include(<flat_map>)
175+
# error "please update the header information for <flat_map> in headers_not_available in utils/libcxx/header_information.py"
176+
#endif // __has_include(<flat_map>)
177+
#if __has_include(<flat_set>)
178+
# error "please update the header information for <flat_set> in headers_not_available in utils/libcxx/header_information.py"
179+
#endif // __has_include(<flat_set>)
180+
#if __has_include(<generator>)
181+
# error "please update the header information for <generator> in headers_not_available in utils/libcxx/header_information.py"
182+
#endif // __has_include(<generator>)
183+
#if __has_include(<hazard_pointer>)
184+
# error "please update the header information for <hazard_pointer> in headers_not_available in utils/libcxx/header_information.py"
185+
#endif // __has_include(<hazard_pointer>)
186+
#if __has_include(<linalg>)
187+
# error "please update the header information for <linalg> in headers_not_available in utils/libcxx/header_information.py"
188+
#endif // __has_include(<linalg>)
189+
#if __has_include(<rcu>)
190+
# error "please update the header information for <rcu> in headers_not_available in utils/libcxx/header_information.py"
191+
#endif // __has_include(<rcu>)
192+
#if __has_include(<spanstream>)
193+
# error "please update the header information for <spanstream> in headers_not_available in utils/libcxx/header_information.py"
194+
#endif // __has_include(<spanstream>)
195+
#if __has_include(<stacktrace>)
196+
# error "please update the header information for <stacktrace> in headers_not_available in utils/libcxx/header_information.py"
197+
#endif // __has_include(<stacktrace>)
198+
#if __has_include(<stdfloat>)
199+
# error "please update the header information for <stdfloat> in headers_not_available in utils/libcxx/header_information.py"
200+
#endif // __has_include(<stdfloat>)
201+
#if __has_include(<text_encoding>)
202+
# error "please update the header information for <text_encoding> in headers_not_available in utils/libcxx/header_information.py"
203+
#endif // __has_include(<text_encoding>)
204+
205+
export module std.compat;
206+
207+
@LIBCXX_MODULE_STD_INCLUDE_SOURCES@
208+
@LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@

libcxx/modules/std.compat/cassert.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
export {
11+
// This module exports nothing.
12+
} // export

libcxx/modules/std.compat/cctype.inc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
export {
11+
using ::isalnum;
12+
using ::isalpha;
13+
using ::isblank;
14+
using ::iscntrl;
15+
using ::isdigit;
16+
using ::isgraph;
17+
using ::islower;
18+
using ::isprint;
19+
using ::ispunct;
20+
using ::isspace;
21+
using ::isupper;
22+
using ::isxdigit;
23+
using ::tolower;
24+
using ::toupper;
25+
} // export

libcxx/modules/std.compat/cerrno.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
export {
11+
// This module exports nothing.
12+
} // export

libcxx/modules/std.compat/cfenv.inc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
export {
11+
// types
12+
using ::fenv_t;
13+
using ::fexcept_t;
14+
15+
// functions
16+
using ::feclearexcept;
17+
using ::fegetexceptflag;
18+
using ::feraiseexcept;
19+
using ::fesetexceptflag;
20+
using ::fetestexcept;
21+
22+
using ::fegetround;
23+
using ::fesetround;
24+
25+
using ::fegetenv;
26+
using ::feholdexcept;
27+
using ::fesetenv;
28+
using ::feupdateenv;
29+
} // export

0 commit comments

Comments
 (0)