Skip to content

Commit 4c88fed

Browse files
committed
refactor: Use std:: prefixes more consistently in C++ code.
1 parent 72452f2 commit 4c88fed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1262
-1113
lines changed

BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ genrule(
88
srcs = [
99
"//c-toxcore/toxav:toxav.h",
1010
"//c-toxcore/toxcore:tox.h",
11+
"//c-toxcore/toxcore:tox_attributes.h",
1112
"//c-toxcore/toxcore:tox_dispatch.h",
1213
"//c-toxcore/toxcore:tox_events.h",
1314
"//c-toxcore/toxcore:tox_log_level.h",
@@ -29,6 +30,7 @@ genrule(
2930
cmd = """
3031
cp $(location //c-toxcore/toxav:toxav.h) $(GENDIR)/c-toxcore/tox/toxav.h
3132
cp $(location //c-toxcore/toxcore:tox.h) $(GENDIR)/c-toxcore/tox/tox.h
33+
cp $(location //c-toxcore/toxcore:tox_attributes.h) $(GENDIR)/c-toxcore/tox/tox_attributes.h
3234
cp $(location //c-toxcore/toxcore:tox_dispatch.h) $(GENDIR)/c-toxcore/tox/tox_dispatch.h
3335
cp $(location //c-toxcore/toxcore:tox_events.h) $(GENDIR)/c-toxcore/tox/tox_events.h
3436
cp $(location //c-toxcore/toxcore:tox_log_level.h) $(GENDIR)/c-toxcore/tox/tox_log_level.h

other/docker/modules/check

Lines changed: 69 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -9,92 +9,59 @@ from typing import Any
99
from typing import Dict
1010
from 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.",

other/docker/modules/modules.Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
FROM alpine:3.21.0
1+
FROM alpine:3.23.0
22

33
RUN ["apk", "add", "--no-cache", \
44
"bash", \
55
"benchmark-dev", \
66
"clang", \
77
"gtest-dev", \
8+
"libc++-dev", \
9+
"libc++-static", \
810
"libconfig-dev", \
911
"libsodium-dev", \
1012
"libvpx-dev", \

testing/support/doubles/fake_clock.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define C_TOXCORE_TESTING_SUPPORT_DOUBLES_FAKE_CLOCK_H
33

44
#include <atomic>
5+
#include <cstdint>
56

67
#include "../public/clock.hh"
78

testing/support/doubles/fake_network_stack.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#define C_TOXCORE_TESTING_SUPPORT_DOUBLES_FAKE_NETWORK_STACK_H
33

44
#include <map>
5+
#include <memory>
56
#include <mutex>
7+
#include <vector>
68

79
#include "../public/network.hh"
810
#include "fake_sockets.hh"

testing/support/doubles/fake_sockets.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
#include <algorithm>
44
#include <cerrno>
55
#include <cstring>
6+
#include <deque>
7+
#include <functional>
68
#include <iostream>
9+
#include <mutex>
10+
#include <vector>
711

812
#include "network_universe.hh"
913

testing/support/public/simulation.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef C_TOXCORE_TESTING_SUPPORT_SIMULATION_H
22
#define C_TOXCORE_TESTING_SUPPORT_SIMULATION_H
33

4+
#include <atomic>
45
#include <condition_variable>
56
#include <functional>
67
#include <memory>

testing/support/public/tox_network.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef C_TOXCORE_TESTING_SUPPORT_TOX_NETWORK_H
66
#define C_TOXCORE_TESTING_SUPPORT_TOX_NETWORK_H
77

8+
#include <memory>
9+
#include <utility>
810
#include <vector>
911

1012
#include "simulation.hh"

0 commit comments

Comments
 (0)