Squashed 'external/toxcore/c-toxcore/' changes from c9cdae001..9ed2fa80d
9ed2fa80d fix(toxav): remove extra copy of video frame on encode de30cf3ad docs: Add new file kinds, that should be useful to all clients. d5b5e879d fix(DHT): Correct node skipping logic timed out nodes. 30e71fe97 refactor: Generate event dispatch functions and add tox_events_dispatch. 8fdbb0b50 style: Format parameter lists in event handlers. d00dee12b refactor: Add warning logs when losing chat invites. b144e8db1 feat: Add a way to look up a file number by ID. 849281ea0 feat: Add a way to fetch groups by chat ID. a2c177396 refactor: Harden event system and improve type safety. 8f5caa656 refactor: Add MessagePack string support to bin_pack. 34e8d5ad5 chore: Add GitHub CodeQL workflow and local Docker runner. f7b068010 refactor: Add nullability annotations to event headers. 788abe651 refactor(toxav): Use system allocator for mutexes. 2e4b423eb refactor: Use specific typedefs for public API arrays. 2baf34775 docs(toxav): update idle iteration interval see 679444751876fa3882a717772918ebdc8f083354 2f87ac67b feat: Add Event Loop abstraction (Ev). f8dfc38d8 test: Fix data race in ToxScenario virtual_clock. 38313921e test(TCP): Add regression test for TCP priority queue integrity. f94a50d9a refactor(toxav): Replace mutable_mutex with dynamically allocated mutex. ad054511e refactor: Internalize DHT structs and add debug helpers. 8b467cc96 fix: Prevent potential integer overflow in group chat handshake. 4962bdbb8 test: Improve TCP simulation and add tests 5f0227093 refactor: Allow nullable data in group chat handlers. e97b18ea9 chore: Improve Windows Docker support. b14943bbd refactor: Move Logger out of Messenger into Tox. dd3136250 cleanup: Apply nullability qualifiers to C++ codebase. 1849f70fc refactor: Extract low-level networking code to net and os_network. 8fec75421 refactor: Delete tox_random, align on rng and os_random. a03ae8051 refactor: Delete tox_memory, align on mem and os_memory. 4c88fed2c refactor: Use `std::` prefixes more consistently in C++ code. 72452f2ae test: Add some more tests for onion and shared key cache. d5a51b09a cleanup: Use tox_attributes.h in tox_private.h and install it. b6f5b9fc5 test: Add some benchmarks for various high level things. 8a8d02785 test(support): Introduce threaded Tox runner and simulation barrier d68d1d095 perf(toxav): optimize audio and video intermediate buffers by keeping them around REVERT: c9cdae001 fix(toxav): remove extra copy of video frame on encode git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: 9ed2fa80d582c714d6bdde6a7648220a92cddff8
This commit is contained in:
@@ -6,92 +6,79 @@ import sys
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import field
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
|
||||
STD_MODULE = """module std [system] {
|
||||
textual header "/usr/include/alloca.h"
|
||||
textual header "/usr/include/assert.h"
|
||||
textual header "/usr/include/c++/14.2.0/algorithm"
|
||||
textual header "/usr/include/c++/14.2.0/array"
|
||||
textual header "/usr/include/c++/14.2.0/atomic"
|
||||
textual header "/usr/include/c++/14.2.0/cassert"
|
||||
textual header "/usr/include/c++/14.2.0/cerrno"
|
||||
textual header "/usr/include/c++/14.2.0/chrono"
|
||||
textual header "/usr/include/c++/14.2.0/climits"
|
||||
textual header "/usr/include/c++/14.2.0/compare"
|
||||
textual header "/usr/include/c++/14.2.0/cstddef"
|
||||
textual header "/usr/include/c++/14.2.0/cstdint"
|
||||
textual header "/usr/include/c++/14.2.0/cstdio"
|
||||
textual header "/usr/include/c++/14.2.0/cstdlib"
|
||||
textual header "/usr/include/c++/14.2.0/cstring"
|
||||
textual header "/usr/include/c++/14.2.0/deque"
|
||||
textual header "/usr/include/c++/14.2.0/functional"
|
||||
textual header "/usr/include/c++/14.2.0/iomanip"
|
||||
textual header "/usr/include/c++/14.2.0/iosfwd"
|
||||
textual header "/usr/include/c++/14.2.0/iostream"
|
||||
textual header "/usr/include/c++/14.2.0/limits"
|
||||
textual header "/usr/include/c++/14.2.0/map"
|
||||
textual header "/usr/include/c++/14.2.0/memory"
|
||||
textual header "/usr/include/c++/14.2.0/mutex"
|
||||
textual header "/usr/include/c++/14.2.0/new"
|
||||
textual header "/usr/include/c++/14.2.0/optional"
|
||||
textual header "/usr/include/c++/14.2.0/ostream"
|
||||
textual header "/usr/include/c++/14.2.0/queue"
|
||||
textual header "/usr/include/c++/14.2.0/random"
|
||||
textual header "/usr/include/c++/14.2.0/stdlib.h"
|
||||
textual header "/usr/include/c++/14.2.0/string"
|
||||
textual header "/usr/include/c++/14.2.0/thread"
|
||||
textual header "/usr/include/c++/14.2.0/type_traits"
|
||||
textual header "/usr/include/c++/14.2.0/vector"
|
||||
textual header "/usr/include/errno.h"
|
||||
textual header "/usr/include/fortify/stdio.h"
|
||||
textual header "/usr/include/fortify/string.h"
|
||||
textual header "/usr/include/fortify/unistd.h"
|
||||
textual header "/usr/include/limits.h"
|
||||
textual header "/usr/include/stdarg.h"
|
||||
textual header "/usr/include/stdbool.h"
|
||||
textual header "/usr/include/stddef.h"
|
||||
textual header "/usr/include/stdint.h"
|
||||
textual header "/usr/include/sys/time.h"
|
||||
textual header "/usr/include/sys/types.h"
|
||||
textual header "/usr/include/time.h"
|
||||
# We no longer define 'std' or 'musl' manually.
|
||||
# We rely on -fimplicit-module-maps to find the system-provided ones.
|
||||
# We only define modules for our project and third-party libraries.
|
||||
EXTRA_MODULES = """
|
||||
module "_system" [system] {
|
||||
header "/usr/include/stdint.h"
|
||||
header "/usr/include/stdbool.h"
|
||||
header "/usr/include/stddef.h"
|
||||
header "/usr/include/stdio.h"
|
||||
header "/usr/include/stdlib.h"
|
||||
header "/usr/include/string.h"
|
||||
header "/usr/include/inttypes.h"
|
||||
header "/usr/include/limits.h"
|
||||
header "/usr/include/errno.h"
|
||||
header "/usr/include/unistd.h"
|
||||
header "/usr/include/fcntl.h"
|
||||
header "/usr/include/time.h"
|
||||
header "/usr/include/assert.h"
|
||||
header "/usr/include/pthread.h"
|
||||
header "/usr/include/arpa/inet.h"
|
||||
header "/usr/include/netdb.h"
|
||||
header "/usr/include/netinet/in.h"
|
||||
header "/usr/include/sys/types.h"
|
||||
header "/usr/include/sys/stat.h"
|
||||
header "/usr/include/sys/time.h"
|
||||
header "/usr/include/sys/socket.h"
|
||||
header "/usr/include/sys/epoll.h"
|
||||
header "/usr/include/sys/ioctl.h"
|
||||
header "/usr/include/sys/resource.h"
|
||||
header "/usr/include/sys/uio.h"
|
||||
header "/usr/include/sys/mman.h"
|
||||
header "/usr/include/sys/wait.h"
|
||||
header "/usr/include/sys/select.h"
|
||||
header "/usr/include/poll.h"
|
||||
header "/usr/include/sched.h"
|
||||
header "/usr/include/signal.h"
|
||||
header "/usr/include/ctype.h"
|
||||
header "/usr/include/alloca.h"
|
||||
header "/usr/include/malloc.h"
|
||||
header "/usr/include/dirent.h"
|
||||
export *
|
||||
}
|
||||
module "c_toxcore_third_party_cmp" {
|
||||
header "third_party/cmp/cmp.h"
|
||||
use std
|
||||
module "_libsodium" [system] {
|
||||
header "/usr/include/sodium.h"
|
||||
use _system
|
||||
export *
|
||||
}
|
||||
module "c_toxcore_toxencryptsave_defines" {
|
||||
header "toxencryptsave/defines.h"
|
||||
module "_benchmark" [system] {
|
||||
header "/usr/include/benchmark/benchmark.h"
|
||||
use _system
|
||||
export *
|
||||
}
|
||||
module "_benchmark" {
|
||||
textual header "/usr/include/benchmark/benchmark.h"
|
||||
use std
|
||||
module "_com_google_googletest___gtest" [system] {
|
||||
header "/usr/include/gtest/gtest.h"
|
||||
header "/usr/include/gmock/gmock.h"
|
||||
use _system
|
||||
export *
|
||||
}
|
||||
module "_com_google_googletest___gtest" {
|
||||
textual header "/usr/include/gmock/gmock.h"
|
||||
textual header "/usr/include/gtest/gtest.h"
|
||||
use std
|
||||
module "_com_google_googletest___gtest_main" [system] {
|
||||
use _com_google_googletest___gtest
|
||||
export *
|
||||
}
|
||||
module "_com_google_googletest___gtest_main" {
|
||||
// Dummy module for gtest_main, assuming it links but headers are in gtest
|
||||
use "_com_google_googletest___gtest"
|
||||
module "_opus" [system] {
|
||||
header "/usr/include/opus/opus.h"
|
||||
use _system
|
||||
export *
|
||||
}
|
||||
module "_libsodium" {
|
||||
textual header "/usr/include/sodium.h"
|
||||
}
|
||||
module "_pthread" {
|
||||
textual header "/usr/include/pthread.h"
|
||||
}
|
||||
module "_psocket" {
|
||||
textual header "/usr/include/arpa/inet.h"
|
||||
textual header "/usr/include/fcntl.h"
|
||||
textual header "/usr/include/fortify/sys/socket.h"
|
||||
textual header "/usr/include/linux/if.h"
|
||||
textual header "/usr/include/netdb.h"
|
||||
textual header "/usr/include/netinet/in.h"
|
||||
textual header "/usr/include/sys/epoll.h"
|
||||
textual header "/usr/include/sys/ioctl.h"
|
||||
module "_libvpx" [system] {
|
||||
header "/usr/include/vpx/vpx_encoder.h"
|
||||
header "/usr/include/vpx/vpx_decoder.h"
|
||||
use _system
|
||||
export *
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -100,24 +87,16 @@ module "_psocket" {
|
||||
class Target:
|
||||
name: str
|
||||
package: str
|
||||
srcs: List[str] = field(default_factory=list)
|
||||
hdrs: List[str] = field(default_factory=list)
|
||||
deps: List[str] = field(default_factory=list)
|
||||
srcs: list[str] = field(default_factory=list)
|
||||
hdrs: list[str] = field(default_factory=list)
|
||||
deps: list[str] = field(default_factory=list)
|
||||
|
||||
@property
|
||||
def label(self) -> str:
|
||||
# Sanitize label for module name
|
||||
sanitized = (f"//c-toxcore/{self.package}:{self.name}".replace(
|
||||
"/", "_").replace(":",
|
||||
"_").replace(".",
|
||||
"_").replace("-",
|
||||
"_").replace("@", "_"))
|
||||
if sanitized.startswith("__"):
|
||||
sanitized = sanitized[2:]
|
||||
return sanitized
|
||||
return f"c-toxcore/{self.package}:{self.name}"
|
||||
|
||||
|
||||
TARGETS: List[Target] = []
|
||||
TARGETS: list[Target] = []
|
||||
|
||||
|
||||
class BuildContext:
|
||||
@@ -140,16 +119,29 @@ class BuildContext:
|
||||
def bzl_cc_fuzz_test(self, *args: Any, **kwargs: Any) -> None:
|
||||
pass
|
||||
|
||||
def bzl_select(self, selector: Dict[str, List[str]]) -> List[str]:
|
||||
def bzl_select(self, selector: dict[str, list[str]]) -> list[str]:
|
||||
return selector.get("//tools/config:linux",
|
||||
selector.get("//conditions:default", []))
|
||||
|
||||
def bzl_glob(self, include: List[str]) -> List[str]:
|
||||
def bzl_glob(self,
|
||||
include: list[str],
|
||||
exclude: list[str] | None = None,
|
||||
**kwargs: Any) -> list[str]:
|
||||
results = []
|
||||
for pattern in include:
|
||||
full_pattern = os.path.join(self.package, pattern)
|
||||
files = glob.glob(full_pattern)
|
||||
files = glob.glob(full_pattern, recursive=True)
|
||||
results.extend([os.path.relpath(f, self.package) for f in files])
|
||||
|
||||
if exclude:
|
||||
excluded_files = set()
|
||||
for pattern in exclude:
|
||||
full_pattern = os.path.join(self.package, pattern)
|
||||
files = glob.glob(full_pattern, recursive=True)
|
||||
excluded_files.update(
|
||||
[os.path.relpath(f, self.package) for f in files])
|
||||
results = [f for f in results if f not in excluded_files]
|
||||
|
||||
return results
|
||||
|
||||
def _add_target(self, name: str, srcs: Any, hdrs: Any, deps: Any) -> None:
|
||||
@@ -174,6 +166,9 @@ class BuildContext:
|
||||
**kwargs: Any) -> None:
|
||||
self._add_target(name, srcs, hdrs, deps)
|
||||
|
||||
def bzl_project(self, *args: Any, **kwargs: Any) -> None:
|
||||
pass
|
||||
|
||||
def bzl_cc_test(self,
|
||||
name: str,
|
||||
srcs: Any = (),
|
||||
@@ -184,29 +179,44 @@ class BuildContext:
|
||||
|
||||
|
||||
def resolve_module_name(dep: str, current_pkg: str) -> str:
|
||||
# Resolve to canonical label first
|
||||
label = dep
|
||||
if dep.startswith("@"):
|
||||
label = dep
|
||||
elif dep.startswith("//"):
|
||||
if ":" in dep:
|
||||
label = dep
|
||||
else:
|
||||
pkg_name = os.path.basename(dep)
|
||||
label = f"{dep}:{pkg_name}"
|
||||
elif dep.startswith(":"):
|
||||
label = f"//c-toxcore/{current_pkg}{dep}"
|
||||
if dep in ["@psocket", "@pthread"]:
|
||||
return "_system"
|
||||
if dep == "@libsodium":
|
||||
return "_libsodium"
|
||||
if dep == "@benchmark":
|
||||
return "_benchmark"
|
||||
if dep == "@com_google_googletest//:gtest":
|
||||
return "_com_google_googletest___gtest"
|
||||
if dep == "@com_google_googletest//:gtest_main":
|
||||
return "_com_google_googletest___gtest_main"
|
||||
if dep == "@opus":
|
||||
return "_opus"
|
||||
if dep == "@libvpx":
|
||||
return "_libvpx"
|
||||
|
||||
# Sanitize
|
||||
sanitized = (label.replace("/", "_").replace(":", "_").replace(
|
||||
".", "_").replace("-", "_").replace("@", "_"))
|
||||
if sanitized.startswith("__"):
|
||||
sanitized = sanitized[2:]
|
||||
return sanitized
|
||||
# Resolve to canonical label first
|
||||
if dep.startswith("@"):
|
||||
return dep
|
||||
if dep.startswith("//"):
|
||||
label = dep[2:]
|
||||
if ":" in label:
|
||||
return label
|
||||
pkg_name = os.path.basename(label)
|
||||
return f"{label}:{pkg_name}"
|
||||
if dep.startswith(":"):
|
||||
return f"c-toxcore/{current_pkg}{dep}"
|
||||
|
||||
return dep
|
||||
|
||||
|
||||
def main() -> None:
|
||||
packages = ["toxcore", "testing/support"]
|
||||
packages = []
|
||||
for root, dirs, files in os.walk("."):
|
||||
if "BUILD.bazel" in files:
|
||||
pkg = os.path.relpath(root, ".")
|
||||
if pkg == ".":
|
||||
pkg = ""
|
||||
packages.append(pkg)
|
||||
|
||||
for pkg in packages:
|
||||
ctx = BuildContext(pkg)
|
||||
@@ -214,39 +224,53 @@ def main() -> None:
|
||||
if not os.path.exists(build_file):
|
||||
continue
|
||||
|
||||
# Use a defaultdict to handle any unknown functions as no-ops
|
||||
from collections import defaultdict
|
||||
|
||||
env: dict[str, Any] = defaultdict(lambda: lambda *args, **kwargs: None)
|
||||
env.update({
|
||||
"load": ctx.bzl_load,
|
||||
"exports_files": ctx.bzl_exports_files,
|
||||
"cc_library": ctx.bzl_cc_library,
|
||||
"no_undefined_cc_library": ctx.bzl_cc_library,
|
||||
"cc_binary": ctx.bzl_cc_binary,
|
||||
"cc_test": ctx.bzl_cc_test,
|
||||
"cc_fuzz_test": ctx.bzl_cc_fuzz_test,
|
||||
"select": ctx.bzl_select,
|
||||
"glob": ctx.bzl_glob,
|
||||
"alias": ctx.bzl_alias,
|
||||
"sh_library": ctx.bzl_sh_library,
|
||||
"project": ctx.bzl_project,
|
||||
})
|
||||
|
||||
with open(build_file, "r") as f:
|
||||
exec(
|
||||
f.read(),
|
||||
{
|
||||
"load": ctx.bzl_load,
|
||||
"exports_files": ctx.bzl_exports_files,
|
||||
"cc_library": ctx.bzl_cc_library,
|
||||
"cc_binary": ctx.bzl_cc_binary,
|
||||
"cc_test": ctx.bzl_cc_test,
|
||||
"cc_fuzz_test": ctx.bzl_cc_fuzz_test,
|
||||
"select": ctx.bzl_select,
|
||||
"glob": ctx.bzl_glob,
|
||||
"alias": ctx.bzl_alias,
|
||||
"sh_library": ctx.bzl_sh_library,
|
||||
},
|
||||
)
|
||||
exec(f.read(), env)
|
||||
|
||||
with open("module.modulemap", "w") as f:
|
||||
f.write(STD_MODULE)
|
||||
f.write(EXTRA_MODULES)
|
||||
for t in TARGETS:
|
||||
f.write(f'module "{t.label}" {{\n')
|
||||
for hdr in t.hdrs:
|
||||
# Proper modular header
|
||||
f.write(f' header "{os.path.join(t.package, hdr)}"\n')
|
||||
f.write(" use std\n")
|
||||
|
||||
# Use all dependencies
|
||||
for dep in t.deps:
|
||||
mod_name = resolve_module_name(dep, t.package)
|
||||
# Export all dependencies to ensure visibility of types used in headers
|
||||
f.write(f" use {mod_name}\n")
|
||||
f.write(f" export {mod_name}\n")
|
||||
f.write(f' use "{mod_name}"\n')
|
||||
|
||||
# Re-export everything we use to match standard C++ transitive include behavior.
|
||||
f.write(" export *\n")
|
||||
|
||||
# Basic system modules used everywhere
|
||||
f.write(' use "_system"\n')
|
||||
|
||||
f.write("}\n")
|
||||
|
||||
# with open("module.modulemap", "r") as f:
|
||||
# print(f.read(), file=sys.stderr)
|
||||
if "--print-modulemap" in sys.argv:
|
||||
with open("module.modulemap", "r") as f:
|
||||
print(f.read())
|
||||
return
|
||||
|
||||
src_to_module = {}
|
||||
for t in TARGETS:
|
||||
@@ -254,29 +278,44 @@ def main() -> None:
|
||||
full_src = os.path.join(t.package, src)
|
||||
src_to_module[full_src] = t.label
|
||||
|
||||
# Sort for deterministic output
|
||||
all_srcs = sorted(src_to_module.keys())
|
||||
all_srcs = [src for src in all_srcs if src.endswith(".c")]
|
||||
os.makedirs("/tmp/clang-modules", exist_ok=True)
|
||||
|
||||
for src in all_srcs:
|
||||
print(f"Validating {src}", file=sys.stderr)
|
||||
module_name = src_to_module[src]
|
||||
|
||||
lang = "-xc" if src.endswith(".c") else "-xc++"
|
||||
std = "-std=c11" if src.endswith(".c") else "-std=c++23"
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
"clang",
|
||||
"-fsyntax-only",
|
||||
"-xc++",
|
||||
lang,
|
||||
"-stdlib=libc++" if lang == "-xc++" else "-nostdinc++",
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-Wno-missing-braces",
|
||||
"-DTCP_SERVER_USE_EPOLL",
|
||||
"-std=c++23",
|
||||
"-D_XOPEN_SOURCE=600",
|
||||
"-D_GNU_SOURCE",
|
||||
std,
|
||||
"-fdiagnostics-color=always",
|
||||
"-fmodules",
|
||||
"-fmodules-strict-decluse",
|
||||
"-Xclang",
|
||||
"-fmodules-local-submodule-visibility",
|
||||
"-fmodules-decluse",
|
||||
"-Xclang",
|
||||
"-fno-modules-error-recovery",
|
||||
"-fno-implicit-module-maps",
|
||||
"-fno-builtin-module-map",
|
||||
"-fmodules-cache-path=/tmp/clang-modules",
|
||||
"-fmodule-map-file=module.modulemap",
|
||||
f"-fmodule-name={module_name}",
|
||||
"-I.",
|
||||
"-I/usr/include/opus",
|
||||
src,
|
||||
],
|
||||
check=True,
|
||||
|
||||
Reference in New Issue
Block a user