1010//
1111//===----------------------------------------------------------------------===//
1212
13+ // Note that this module map requires some changes to the Musl headers in order
14+ // for it to work. Specifically:
15+ //
16+ // - The types need to be broken out of <bits/alltypes.h> into individual files
17+ // in <bits/types>.
18+ //
19+ // - The definitions included in <bits/alltypes.h> need to be broken out into
20+ // <bits/musldefs.h>.
21+ //
22+ // - A _modules directory needs to be created; for each of the files mentioned
23+ // in _modules below there should be a header that looks like
24+ //
25+ // #if !__building_module(stdc_foo)
26+ // #error "Do not include this header directly, include <foo.h> instead"
27+ // #endif
28+ // #include <foo.h>
29+ //
30+ // This is so that the replacement headers from Clang and Libc++ work as
31+ // expected.
32+
1333module _musl [system] {
1434 config_macros _GNU_SOURCE, _BSD_SOURCE, _XOPEN_SOURCE, _POSIX_SOURCE, _POSIX_C_SOURCE, _LARGEFILE64_SOURCE, _ALL_SOURCE, _DEFAULT_SOURCE, __STRICT_ANSI__
1535
@@ -28,164 +48,270 @@ module _musl [system] {
2848 }
2949}
3050
31- module stdc_assert [system] {
32- config_macros NDEBUG
51+ // Headers that can be overridden by Clang or libc++; in this case what we do is
52+ // we create an underscored module to wrap the actual header, then have the
53+ // module with the nicer name include a forwarding header from _modules. This
54+ // ensures that e.g. `import stdc_float` will result in pulling in the Clang
55+ // or libc++ versions as expected.
56+
57+ module _stdc_assert [system] {
3358 textual header "assert.h"
59+ }
60+ module stdc_assert [system] {
61+ header "_modules/stdc_assert.h"
3462 export *
3563}
3664
37- module stdc_float [system] {
38- header "float .h"
65+ module _stdc_complex [system] {
66+ header "complex .h"
3967 export *
4068}
41-
42- module stdc_iso646 [system] {
43- header "iso646.h"
69+ module stdc_complex [system] {
70+ header "_modules/stdc_complex.h"
4471 export *
4572}
4673
47- module stdc_limits [system] {
74+ module _stdc_ctype [system] {
4875 config_macros _BSD_SOURCE, _GNU_SOURCE, _POSIX_C_SOURCE, _POSIX_SOURCE, _XOPEN_SOURCE
49- header "limits .h"
76+ header "ctype .h"
5077 export *
5178}
52-
53- module stdc_stdalign [system] {
54- header "stdalign.h"
79+ module stdc_ctype [system] {
80+ header "_modules/stdc_ctype.h"
5581 export *
5682}
5783
58- module stdc_stdarg [system] {
59- header "stdarg.h"
84+ module _stdc_errno [system] {
85+ config_macros _GNU_SOURCE
86+ header "errno.h"
6087 export *
6188}
62-
63- module stdc_stdatomic [system] {
64- header "stdatomic.h"
89+ module stdc_errno [system] {
90+ header "_modules/stdc_errno.h"
6591 export *
6692}
6793
68- module stdc_stdbool [system] {
69- header "stdbool .h"
94+ module _stdc_fenv [system] {
95+ header "fenv .h"
7096 export *
7197}
72-
73- module stdc_stddef [system] {
74- header "stddef.h"
98+ module stdc_fenv [system] {
99+ header "_modules/stdc_fenv.h"
75100 export *
76101}
77102
78- module stdc_stdint [system] {
79- header "stdint .h"
103+ module _stdc_float [system] {
104+ header "float .h"
80105 export *
81106}
82-
83- module stdc_time [system] {
84- config_macros _POSIX_SOURCE, _POSIX_C_SOURCE, _XOPEN_SOURCE, _GNU_SOURCE, _BSD_SOURCE
85- header "time.h"
107+ module stdc_float [system] {
108+ header "_modules/stdc_float.h"
86109 export *
87110}
88111
89- module stdc_tgmath [system] {
90- header "tgmath .h"
112+ module _stdc_inttypes [system] {
113+ header "inttypes .h"
91114 export *
92115}
93-
94- module stdc_complex [system] {
95- header "complex.h"
116+ module stdc_inttypes [system] {
117+ header "_modules/stdc_inttypes.h"
118+ use stdc_stdint
96119 export *
97120}
98121
99- module stdc_ctype [system] {
100- config_macros _BSD_SOURCE, _GNU_SOURCE, _POSIX_C_SOURCE, _POSIX_SOURCE, _XOPEN_SOURCE
101- header "ctype.h"
122+ module _stdc_iso646 [system] {
123+ header "iso646.h"
102124 export *
103125}
104-
105- module stdc_errno [system] {
106- config_macros _GNU_SOURCE
107- header "errno.h"
126+ module stdc_iso646 [system] {
127+ header "_modules/stdc_iso646.h"
108128 export *
109129}
110130
111- module stdc_fenv [system] {
112- header "fenv.h"
131+ module _stdc_limits [system] {
132+ config_macros _BSD_SOURCE, _GNU_SOURCE, _POSIX_C_SOURCE, _POSIX_SOURCE, _XOPEN_SOURCE
133+ header "limits.h"
113134 export *
114135}
115-
116- module stdc_inttypes [system] {
117- header "inttypes.h"
136+ module stdc_limits [system] {
137+ header "_modules/stdc_limits.h"
118138 export *
119139}
120140
121- module stdc_locale [system] {
141+ module _stdc_locale [system] {
122142 config_macros _BSD_SOURCE, _GNU_SOURCE, _POSIX_C_SOURCE, _POSIX_SOURCE, _XOPEN_SOURCE
123143 header "locale.h"
124144 export *
125145}
146+ module stdc_locale [system] {
147+ header "_modules/stdc_locale.h"
148+ export *
149+ }
126150
127- module stdc_math [system] {
151+ module _stdc_math [system] {
128152 config_macros _BSD_SOURCE, _GNU_SOURCE, _XOPEN_SOURCE
129153 header "math.h"
130154 export *
131155}
156+ module stdc_math [system] {
157+ header "_modules/stdc_math.h"
158+ export *
159+ }
132160
133- module stdc_setjmp [system] {
161+ module _stdc_setjmp [system] {
134162 config_macros _BSD_SOURCE, _GNU_SOURCE, _POSIX_C_SOURCE, _POSIX_SOURCE, _XOPEN_SOURCE
135163 header "setjmp.h"
136164 export *
137165}
166+ module stdc_setjmp [system] {
167+ header "_modules/stdc_setjmp.h"
168+ export *
169+ }
138170
139- module stdc_signal [system] {
140- config_macros _BSD_SOURCE, _GNU_SOURCE, _POSIX_C_SOURCE, _POSIX_SOURCE, _XOPEN_SOURCE
141- header "signal.h"
171+ module _stdc_stdalign [system] {
172+ header "stdalign.h"
173+ export *
174+ }
175+ module stdc_stdalign [system] {
176+ header "_modules/stdc_stdalign.h"
142177 export *
143178}
144179
145- module stdc_stdio [system] {
180+ module _stdc_stdarg [system] {
181+ header "stdarg.h"
182+ export *
183+ }
184+ module stdc_stdarg [system] {
185+ header "_modules/stdc_stdarg.h"
186+ export *
187+ }
188+
189+ module _stdc_stdatomic [system] {
190+ header "stdatomic.h"
191+ export *
192+ }
193+ module stdc_stdatomic [system] {
194+ header "_modules/stdc_stdatomic.h"
195+ export *
196+ }
197+
198+ module _stdc_stdbool [system] {
199+ header "stdbool.h"
200+ export *
201+ }
202+ module stdc_stdbool [system] {
203+ header "_modules/stdc_stdbool.h"
204+ export *
205+ }
206+
207+ module _stdc_stddef [system] {
208+ header "stddef.h"
209+ export *
210+ }
211+ module stdc_stddef [system] {
212+ header "_modules/stdc_stddef.h"
213+ export *
214+ }
215+
216+ module _stdc_stdint [system] {
217+ header "stdint.h"
218+ export *
219+ }
220+ module stdc_stdint [system] {
221+ header "_modules/stdc_stdint.h"
222+ export *
223+ }
224+
225+ module _stdc_stdio [system] {
146226 config_macros _BSD_SOURCE, _GNU_SOURCE, _LARGEFILE64_SOURCE, _POSIX_C_SOURCE, _POSIX_SOURCE, _XOPEN_SOURCE
147227 header "stdio.h"
148228 export *
149229}
230+ module stdc_stdio [system] {
231+ header "_modules/stdc_stdio.h"
232+ export *
233+ }
150234
151- module stdc_stdlib [system] {
235+ module _stdc_stdlib [system] {
152236 config_macros _BSD_SOURCE, _GNU_SOURCE, _LARGEFILE64_SOURCE, _POSIX_C_SOURCE, _POSIX_SOURCE, _XOPEN_SOURCE
153237 header "stdlib.h"
154238 export *
155239}
156-
157- module stdc_stdnoreturn [system] {
158- header "stdnoreturn.h"
240+ module stdc_stdlib [system] {
241+ header "_modules/stdc_stdlib.h"
159242 export *
160243}
161244
162- module stdc_string [system] {
245+ module _stdc_string [system] {
163246 config_macros _BSD_SOURCE, _GNU_SOURCE, _POSIX_C_SOURCE, _POSIX_SOURCE, _XOPEN_SOURCE
164247 header "string.h"
165248 export *
166249}
250+ module stdc_string [system] {
251+ header "_modules/stdc_string.h"
252+ export *
253+ }
167254
168- module stdc_threads [system] {
169- header "threads.h"
255+ module _stdc_tgmath [system] {
256+ header "tgmath.h"
257+ export *
258+ }
259+ module stdc_tgmath [system] {
260+ header "_modules/stdc_tgmath.h"
170261 export *
171262}
172263
173- module stdc_uchar [system] {
264+ module _stdc_uchar [system] {
174265 header "uchar.h"
175266 export *
176267}
268+ module stdc_uchar [system] {
269+ header "_modules/stdc_uchar.h"
270+ export *
271+ }
177272
178- module stdc_wchar [system] {
273+ module _stdc_wchar [system] {
179274 config_macros _BSD_SOURCE, _GNU_SOURCE, _POSIX_C_SOURCE, _POSIX_SOURCE, _XOPEN_SOURCE
180275 header "wchar.h"
181276 export *
182277}
278+ module stdc_wchar [system] {
279+ header "_modules/stdc_wchar.h"
280+ export *
281+ }
183282
184- module stdc_wctype [system] {
283+ module _stdc_wctype [system] {
185284 config_macros _BSD_SOURCE, _GNU_SOURCE, _POSIX_C_SOURCE, _POSIX_SOURCE, _XOPEN_SOURCE
186285 header "wctype.h"
187286 export *
188287}
288+ module stdc_wctype [system] {
289+ header "_modules/stdc_wctype.h"
290+ export *
291+ }
292+
293+ // C library headers
294+ module stdc_time [system] {
295+ config_macros _POSIX_SOURCE, _POSIX_C_SOURCE, _XOPEN_SOURCE, _GNU_SOURCE, _BSD_SOURCE
296+ header "time.h"
297+ export *
298+ }
299+
300+ module stdc_signal [system] {
301+ config_macros _BSD_SOURCE, _GNU_SOURCE, _POSIX_C_SOURCE, _POSIX_SOURCE, _XOPEN_SOURCE
302+ header "signal.h"
303+ export *
304+ }
305+
306+ module stdc_stdnoreturn [system] {
307+ header "stdnoreturn.h"
308+ export *
309+ }
310+
311+ module stdc_threads [system] {
312+ header "threads.h"
313+ export *
314+ }
189315
190316// POSIX
191317module posix_aio [system] {
0 commit comments