@@ -9,92 +9,59 @@ from typing import Any
99from typing import Dict
1010from typing import List
1111
12- STD_MODULE = """module std [system] {
13- textual header "/usr/include/alloca.h"
14- textual header "/usr/include/assert.h"
15- textual header "/usr/include/c++/14.2.0/algorithm"
16- textual header "/usr/include/c++/14.2.0/array"
17- textual header "/usr/include/c++/14.2.0/atomic"
18- textual header "/usr/include/c++/14.2.0/cassert"
19- textual header "/usr/include/c++/14.2.0/cerrno"
20- textual header "/usr/include/c++/14.2.0/chrono"
21- textual header "/usr/include/c++/14.2.0/climits"
22- textual header "/usr/include/c++/14.2.0/compare"
23- textual header "/usr/include/c++/14.2.0/condition_variable"
24- textual header "/usr/include/c++/14.2.0/cstddef"
25- textual header "/usr/include/c++/14.2.0/cstdint"
26- textual header "/usr/include/c++/14.2.0/cstdio"
27- textual header "/usr/include/c++/14.2.0/cstdlib"
28- textual header "/usr/include/c++/14.2.0/cstring"
29- textual header "/usr/include/c++/14.2.0/deque"
30- textual header "/usr/include/c++/14.2.0/functional"
31- textual header "/usr/include/c++/14.2.0/future"
32- textual header "/usr/include/c++/14.2.0/iomanip"
33- textual header "/usr/include/c++/14.2.0/iosfwd"
34- textual header "/usr/include/c++/14.2.0/iostream"
35- textual header "/usr/include/c++/14.2.0/limits"
36- textual header "/usr/include/c++/14.2.0/map"
37- textual header "/usr/include/c++/14.2.0/memory"
38- textual header "/usr/include/c++/14.2.0/mutex"
39- textual header "/usr/include/c++/14.2.0/new"
40- textual header "/usr/include/c++/14.2.0/optional"
41- textual header "/usr/include/c++/14.2.0/ostream"
42- textual header "/usr/include/c++/14.2.0/queue"
43- textual header "/usr/include/c++/14.2.0/random"
44- textual header "/usr/include/c++/14.2.0/set"
45- textual header "/usr/include/c++/14.2.0/stdlib.h"
46- textual header "/usr/include/c++/14.2.0/string"
47- textual header "/usr/include/c++/14.2.0/thread"
48- textual header "/usr/include/c++/14.2.0/type_traits"
49- textual header "/usr/include/c++/14.2.0/vector"
50- textual header "/usr/include/errno.h"
51- textual header "/usr/include/fortify/stdio.h"
52- textual header "/usr/include/fortify/string.h"
53- textual header "/usr/include/fortify/unistd.h"
54- textual header "/usr/include/limits.h"
55- textual header "/usr/include/stdarg.h"
56- textual header "/usr/include/stdbool.h"
57- textual header "/usr/include/stddef.h"
58- textual header "/usr/include/stdint.h"
59- textual header "/usr/include/sys/time.h"
60- textual header "/usr/include/sys/types.h"
61- textual header "/usr/include/time.h"
12+ # We no longer define 'std' or 'musl' manually.
13+ # We rely on -fimplicit-module-maps to find the system-provided ones.
14+ # We only define modules for our project and third-party libraries.
15+ EXTRA_MODULES = """
16+ module "_benchmark" [system] {
17+ header "/usr/include/benchmark/benchmark.h"
18+ export *
6219}
63- module "c_toxcore_third_party_cmp" {
64- header "third_party/cmp/cmp.h"
65- use std
20+ module "_com_google_googletest___gtest" [system] {
21+ header "/usr/include/gtest/gtest.h"
22+ header "/usr/include/gmock/gmock.h"
23+ export *
6624}
67- module "c_toxcore_toxencryptsave_defines" {
68- header "toxencryptsave/defines.h"
25+ module "_com_google_googletest___gtest_main" [system] {
26+ use _com_google_googletest___gtest
27+ export *
6928}
70- module "_benchmark" {
71- textual header "/usr/include/benchmark/benchmark .h"
72- use std
29+ module "_libsodium" [system] {
30+ header "/usr/include/sodium .h"
31+ export *
7332}
74- module "_com_google_googletest___gtest" {
75- textual header "/usr/include/gmock/gmock.h"
76- textual header "/usr/include/gtest/gtest.h"
77- use std
33+ module "_c_std" [system] {
34+ header "/usr/include/stdint.h"
35+ header "/usr/include/stdbool.h"
36+ header "/usr/include/stddef.h"
37+ header "/usr/include/stdio.h"
38+ header "/usr/include/stdlib.h"
39+ header "/usr/include/string.h"
40+ header "/usr/include/inttypes.h"
41+ export *
7842}
79- module "_com_google_googletest___gtest_main" {
80- // Dummy module for gtest_main, assuming it links but headers are in gtest
81- use "_com_google_googletest___gtest"
43+ module "_pthread" [system] {
44+ header "/usr/include/pthread.h"
45+ use _c_std
46+ export _c_std
47+ export *
8248}
83- module "_libsodium" {
84- textual header "/usr/include/sodium.h"
85- }
86- module "_pthread" {
87- textual header "/usr/include/pthread.h"
88- }
89- module "_psocket" {
90- textual header "/usr/include/arpa/inet.h"
91- textual header "/usr/include/fcntl.h"
92- textual header "/usr/include/fortify/sys/socket.h"
93- textual header "/usr/include/linux/if.h"
94- textual header "/usr/include/netdb.h"
95- textual header "/usr/include/netinet/in.h"
96- textual header "/usr/include/sys/epoll.h"
97- textual header "/usr/include/sys/ioctl.h"
49+ module "_psocket" [system] {
50+ header "/usr/include/arpa/inet.h"
51+ header "/usr/include/fcntl.h"
52+ header "/usr/include/fortify/sys/socket.h"
53+ header "/usr/include/linux/if.h"
54+ header "/usr/include/netdb.h"
55+ header "/usr/include/netinet/in.h"
56+ header "/usr/include/sys/epoll.h"
57+ header "/usr/include/sys/ioctl.h"
58+ header "/usr/include/sys/socket.h"
59+ header "/usr/include/sys/stat.h"
60+ header "/usr/include/sys/types.h"
61+ header "/usr/include/unistd.h"
62+ use _c_std
63+ export _c_std
64+ export *
9865}
9966"""
10067
@@ -235,30 +202,42 @@ def main() -> None:
235202 )
236203
237204 with open ("module.modulemap" , "w" ) as f :
238- f .write (STD_MODULE )
205+ f .write (EXTRA_MODULES )
239206 for t in TARGETS :
240207 f .write (f'module "{ t .label } " {{\n ' )
241208 for hdr in t .hdrs :
209+ # Proper modular header
242210 f .write (f' header "{ os .path .join (t .package , hdr )} "\n ' )
243- f .write (" use std\n " )
211+
212+ # Export all dependencies
244213 for dep in t .deps :
245214 mod_name = resolve_module_name (dep , t .package )
246- # Export all dependencies to ensure visibility of types used in headers
247215 f .write (f" use { mod_name } \n " )
248216 f .write (f" export { mod_name } \n " )
217+
218+ # Basic system modules used everywhere
219+ f .write (" use std\n " )
220+ f .write (" use _c_std\n " )
221+ f .write (" use _psocket\n " )
222+ f .write (" use _pthread\n " )
223+ f .write (" use _libsodium\n " )
224+ f .write (" export *\n " )
225+
249226 f .write ("}\n " )
250227
251- # with open("module.modulemap", "r") as f:
252- # print(f.read(), file=sys.stderr)
228+ with open ("module.modulemap" , "r" ) as f :
229+ print ("--- Generated module.modulemap ---" , file = sys .stderr )
230+ print (f .read (), file = sys .stderr )
231+ print ("----------------------------------" , file = sys .stderr )
253232
254233 src_to_module = {}
255234 for t in TARGETS :
256235 for src in t .srcs :
257236 full_src = os .path .join (t .package , src )
258237 src_to_module [full_src ] = t .label
259238
260- # Sort for deterministic output
261239 all_srcs = sorted (src_to_module .keys ())
240+ os .makedirs ("/tmp/clang-modules" , exist_ok = True )
262241
263242 for src in all_srcs :
264243 print (f"Validating { src } " , file = sys .stderr )
@@ -269,14 +248,17 @@ def main() -> None:
269248 "clang" ,
270249 "-fsyntax-only" ,
271250 "-xc++" ,
251+ "-stdlib=libc++" ,
272252 "-Wall" ,
273253 "-Werror" ,
274254 "-Wno-missing-braces" ,
275255 "-DTCP_SERVER_USE_EPOLL" ,
276256 "-std=c++23" ,
277257 "-fdiagnostics-color=always" ,
278258 "-fmodules" ,
279- "-fmodules-strict-decluse" ,
259+ "-fimplicit-module-maps" ,
260+ "-fbuiltin-module-map" ,
261+ "-fmodules-cache-path=/tmp/clang-modules" ,
280262 "-fmodule-map-file=module.modulemap" ,
281263 f"-fmodule-name={ module_name } " ,
282264 "-I." ,
0 commit comments