Skip to content

Commit a800485

Browse files
[libc++][Modules] Recreate the top level std clang module
lldb needs the `std` clang module to make all of libc++ available in the debugger. Make a new header to include the rest of the public headers and use to build a `std` module that just re-exports the rest of libc++. Reviewed By: Mordante, JDevlieghere, #libc Differential Revision: https://reviews.llvm.org/D156177
1 parent 6a8b66e commit a800485

File tree

5 files changed

+253
-0
lines changed

5 files changed

+253
-0
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ set(files
653653
__ranges/views.h
654654
__ranges/zip_view.h
655655
__split_buffer
656+
__std_clang_module
656657
__std_mbstate_t.h
657658
__stop_token/atomic_unique_lock.h
658659
__stop_token/intrusive_list_view.h

libcxx/include/__std_clang_module

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
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+
// This header should not be directly included, it's exclusively to import all
11+
// of the libc++ public clang modules for the `std` clang module to export. In
12+
// other words, it's to facilitate `@import std;` in Objective-C++ and `import std`
13+
// in Swift to expose all of the libc++ interfaces. This is generally not
14+
// recommended, however there are some clients that need to import all of libc++
15+
// without knowing what "all" is.
16+
#if !__building_module(std)
17+
# error "Do not include this header directly, include individual headers instead"
18+
#endif
19+
20+
#include <__availability>
21+
#include <__config>
22+
23+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24+
# pragma GCC system_header
25+
#endif
26+
27+
#include <algorithm>
28+
#include <any>
29+
#include <array>
30+
#include <atomic>
31+
#include <bit>
32+
#include <bitset>
33+
#include <charconv>
34+
#include <chrono>
35+
#include <compare>
36+
#include <complex>
37+
#include <concepts>
38+
#include <condition_variable>
39+
#include <deque>
40+
#include <exception>
41+
#include <execution>
42+
#include <expected>
43+
#include <format>
44+
#include <forward_list>
45+
#include <functional>
46+
#include <initializer_list>
47+
#include <iosfwd>
48+
#include <iterator>
49+
#include <limits>
50+
#include <list>
51+
#include <map>
52+
#include <mdspan>
53+
#include <memory>
54+
#include <memory_resource>
55+
#include <new>
56+
#include <numbers>
57+
#include <numeric>
58+
#include <optional>
59+
#include <queue>
60+
#include <random>
61+
#include <ranges>
62+
#include <ratio>
63+
#include <scoped_allocator>
64+
#include <set>
65+
#include <source_location>
66+
#include <span>
67+
#include <stack>
68+
#include <stdexcept>
69+
#include <string>
70+
#include <string_view>
71+
#include <system_error>
72+
#include <tuple>
73+
#include <type_traits>
74+
#include <typeindex>
75+
#include <typeinfo>
76+
#include <unordered_map>
77+
#include <unordered_set>
78+
#include <utility>
79+
#include <valarray>
80+
#include <variant>
81+
#include <vector>
82+
#include <version>
83+
84+
#include <cassert>
85+
#include <ccomplex>
86+
#include <cctype>
87+
#include <cerrno>
88+
#include <cfenv>
89+
#include <cfloat>
90+
#include <cinttypes>
91+
#include <ciso646>
92+
#include <climits>
93+
#include <cmath>
94+
#include <csetjmp>
95+
#include <csignal>
96+
#include <cstdarg>
97+
#include <cstdbool>
98+
#include <cstddef>
99+
#include <cstdint>
100+
#include <cstdio>
101+
#include <cstdlib>
102+
#include <cstring>
103+
#include <ctgmath>
104+
#include <ctime>
105+
#include <cuchar>
106+
107+
#include <complex.h>
108+
#include <ctype.h>
109+
#include <errno.h>
110+
#include <fenv.h>
111+
#include <float.h>
112+
#include <inttypes.h>
113+
#include <limits.h>
114+
#include <math.h>
115+
#include <setjmp.h>
116+
#include <stdbool.h>
117+
#include <stddef.h>
118+
#include <stdint.h>
119+
#include <stdio.h>
120+
#include <stdlib.h>
121+
#include <string.h>
122+
#include <tgmath.h>
123+
#include <uchar.h>
124+
125+
#ifndef _LIBCPP_HAS_NO_LOCALIZATION
126+
# include <codecvt>
127+
# ifndef _LIBCPP_HAS_NO_FILESYSTEM
128+
# include <fstream>
129+
# endif
130+
# include <iomanip>
131+
# include <ios>
132+
# include <iostream>
133+
# include <istream>
134+
# include <locale>
135+
# include <ostream>
136+
# include <regex>
137+
# include <sstream>
138+
# include <streambuf>
139+
# include <strstream>
140+
141+
# include <clocale>
142+
143+
# include <locale.h>
144+
#endif
145+
146+
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
147+
# include <cwchar>
148+
# include <cwctype>
149+
150+
# include <wchar.h>
151+
# include <wctype.h>
152+
#endif
153+
154+
#ifdef _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
155+
# include <print>
156+
#endif
157+
158+
#ifndef _LIBCPP_CXX03_LANG
159+
# ifndef _LIBCPP_HAS_NO_THREADS
160+
# include <future>
161+
# include <mutex>
162+
# include <thread>
163+
# endif
164+
165+
# include <experimental/deque>
166+
# include <experimental/forward_list>
167+
# include <experimental/iterator>
168+
# include <experimental/list>
169+
# include <experimental/map>
170+
# include <experimental/memory_resource>
171+
# include <experimental/propagate_const>
172+
# ifndef _LIBCPP_HAS_NO_LOCALIZATION
173+
# include <experimental/regex>
174+
# endif
175+
# include <experimental/set>
176+
# include <experimental/simd>
177+
# include <experimental/string>
178+
# include <experimental/type_traits>
179+
# include <experimental/unordered_map>
180+
# include <experimental/unordered_set>
181+
# include <experimental/utility>
182+
# include <experimental/vector>
183+
#endif
184+
185+
#if _LIBCPP_STD_VER >= 14
186+
# ifndef _LIBCPP_HAS_NO_THREADS
187+
# include <shared_mutex>
188+
# endif
189+
#endif
190+
191+
#if _LIBCPP_STD_VER >= 17
192+
# ifndef _LIBCPP_HAS_NO_FILESYSTEM
193+
# include <filesystem>
194+
# endif
195+
#endif
196+
197+
#if _LIBCPP_STD_VER >= 20
198+
# include <coroutine>
199+
200+
# ifndef _LIBCPP_HAS_NO_THREADS
201+
# include <barrier>
202+
# include <latch>
203+
# include <semaphore>
204+
# include <stop_token>
205+
# endif
206+
#endif
207+
208+
#if _LIBCPP_STD_VER >= 23
209+
# ifndef _LIBCPP_HAS_NO_THREADS
210+
# include <stdatomic.h>
211+
# endif
212+
#endif

libcxx/include/module.modulemap.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,13 @@ module std_experimental [system] {
627627
}
628628
}
629629

630+
// Convenience method to get all of the above modules in a single import statement.
631+
// Importing only the needed modules is likely to be more performant.
632+
module std [system] {
633+
header "__std_clang_module"
634+
export *
635+
}
636+
630637
// Implementation detail headers that are private to libc++. These modules
631638
// must not be directly imported.
632639
module std_private_assert [system] {

libcxx/test/libcxx/modules_include.gen.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,34 @@
4444
4545
#include <{header}>
4646
""")
47+
48+
print(f"""
49+
//--- __std_clang_module.compile.pass.mm
50+
// RUN{BLOCKLIT}: %{{cxx}} %s %{{flags}} %{{compile_flags}} -fmodules -fcxx-modules -fmodules-cache-path=%t -fsyntax-only
51+
52+
// REQUIRES{BLOCKLIT}: modules-build
53+
// UNSUPPORTED{BLOCKLIT}: use_module_std
54+
55+
// GCC doesn't support -fcxx-modules
56+
// UNSUPPORTED{BLOCKLIT}: gcc
57+
58+
// The Windows headers don't appear to be compatible with modules
59+
// UNSUPPORTED{BLOCKLIT}: windows
60+
// UNSUPPORTED{BLOCKLIT}: buildhost=windows
61+
62+
// The AIX headers don't appear to be compatible with modules
63+
// UNSUPPORTED{BLOCKLIT}: LIBCXX-AIX-FIXME
64+
65+
// The Android headers don't appear to be compatible with modules yet
66+
// XFAIL{BLOCKLIT}: LIBCXX-ANDROID-FIXME
67+
68+
// TODO: Investigate this failure
69+
// UNSUPPORTED{BLOCKLIT}: LIBCXX-FREEBSD-FIXME
70+
71+
// Lit seems to compile this twice: once with the default flags and once with with
72+
// the flags specified in the RUN directive. Guard the first compile from failing.
73+
#if __has_feature(modules)
74+
@import std;
75+
#endif
76+
77+
""")

libcxx/utils/generate_iwyu_mapping.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def generate_map(include):
7777
continue
7878
elif i == "__split_buffer":
7979
public = ["deque", "vector"]
80+
elif i == "__std_clang_module":
81+
continue
8082
elif i == "__std_mbstate_t.h":
8183
continue
8284
elif i == "__threading_support":

0 commit comments

Comments
 (0)