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:
4
other/docker/codeql/build.sh
Normal file
4
other/docker/codeql/build.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
cmake -GNinja -B build -S .
|
||||
cmake --build build --parallel "$(nproc)"
|
||||
53
other/docker/codeql/codeql.Dockerfile
Normal file
53
other/docker/codeql/codeql.Dockerfile
Normal file
@@ -0,0 +1,53 @@
|
||||
# other/docker/codeql/codeql.Dockerfile
|
||||
FROM toxchat/c-toxcore:sources AS sources
|
||||
FROM ubuntu:22.04
|
||||
|
||||
RUN apt-get update && \
|
||||
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
ca-certificates \
|
||||
cmake \
|
||||
curl \
|
||||
git \
|
||||
libconfig-dev \
|
||||
libopus-dev \
|
||||
libsodium-dev \
|
||||
libvpx-dev \
|
||||
ninja-build \
|
||||
pkg-config \
|
||||
unzip \
|
||||
wget \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install CodeQL
|
||||
ARG CODEQL_VERSION=v2.23.9
|
||||
RUN curl -L -o /tmp/codeql.zip https://github.com/github/codeql-cli-binaries/releases/download/${CODEQL_VERSION}/codeql-linux64.zip && \
|
||||
unzip -q /tmp/codeql.zip -d /opt && \
|
||||
rm /tmp/codeql.zip
|
||||
|
||||
ENV PATH="/opt/codeql:$PATH"
|
||||
|
||||
RUN groupadd -r -g 1000 builder \
|
||||
&& useradd -m --no-log-init -r -g builder -u 1000 builder
|
||||
|
||||
WORKDIR /home/builder/c-toxcore
|
||||
|
||||
# Copy sources
|
||||
COPY --chown=builder:builder --from=sources /src/ /home/builder/c-toxcore/
|
||||
|
||||
# Pre-create build directory
|
||||
RUN mkdir -p build codeql-db && chown builder:builder codeql-db build
|
||||
|
||||
# Copy scripts
|
||||
COPY --chown=builder:builder other/docker/codeql/build.sh .
|
||||
COPY --chown=builder:builder other/docker/codeql/run-analysis.sh .
|
||||
|
||||
RUN chmod +x build.sh run-analysis.sh
|
||||
|
||||
USER builder
|
||||
|
||||
# Download standard queries as builder
|
||||
RUN codeql pack download codeql/cpp-queries
|
||||
|
||||
CMD ["./run-analysis.sh"]
|
||||
15
other/docker/codeql/run
Executable file
15
other/docker/codeql/run
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eux
|
||||
|
||||
BUILD=codeql
|
||||
|
||||
# Ensure the sources image is built
|
||||
other/docker/sources/build.sh
|
||||
|
||||
# Build the codeql image
|
||||
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .
|
||||
|
||||
# Run the container
|
||||
echo "Running CodeQL analysis..."
|
||||
docker run --rm "toxchat/c-toxcore:$BUILD"
|
||||
8
other/docker/codeql/run-analysis.sh
Normal file
8
other/docker/codeql/run-analysis.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo "Creating CodeQL Database..."
|
||||
codeql database create codeql-db --language=cpp --overwrite --command="./build.sh"
|
||||
echo "Analyzing..."
|
||||
codeql database analyze codeql-db codeql/cpp-queries:codeql-suites/cpp-security-and-quality.qls --format=csv --output=codeql-db/results.csv
|
||||
echo "Analysis complete. Results in codeql-db/results.csv"
|
||||
cat codeql-db/results.csv
|
||||
@@ -1,8 +0,0 @@
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
cc_library(
|
||||
name = "sodium",
|
||||
testonly = True,
|
||||
srcs = ["sodium.c"],
|
||||
deps = ["@libsodium"],
|
||||
)
|
||||
@@ -1,43 +0,0 @@
|
||||
{
|
||||
"ana": {
|
||||
"activated": [
|
||||
"base","mallocWrapper","escape","mutex","mutexEvents","access","assert","expRelation"
|
||||
],
|
||||
"arrayoob": true,
|
||||
"wp": true,
|
||||
"apron": {
|
||||
"strengthening": true
|
||||
},
|
||||
"base": {
|
||||
"structs" : {
|
||||
"domain" : "combined-sk"
|
||||
},
|
||||
"arrays": {
|
||||
"domain": "partitioned"
|
||||
}
|
||||
},
|
||||
"malloc": {
|
||||
"wrappers": [
|
||||
"mem_balloc",
|
||||
"mem_alloc",
|
||||
"mem_valloc",
|
||||
"mem_vrealloc"
|
||||
]
|
||||
}
|
||||
},
|
||||
"warn": {
|
||||
"behavior": false,
|
||||
"call": false,
|
||||
"integer": true,
|
||||
"float": false,
|
||||
"race": false,
|
||||
"deadcode": false,
|
||||
"unsound": false,
|
||||
"imprecise": false,
|
||||
"success": false,
|
||||
"unknown": false
|
||||
},
|
||||
"exp": {
|
||||
"earlyglobs": true
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
FROM toxchat/c-toxcore:sources AS sources
|
||||
FROM ghcr.io/goblint/analyzer:2.5.0
|
||||
|
||||
RUN apt-get update && \
|
||||
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
|
||||
libsodium-dev \
|
||||
tcc \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /work
|
||||
COPY --from=sources /src/ /work/
|
||||
|
||||
COPY other/deploy/single-file/make_single_file /work/
|
||||
|
||||
RUN ./make_single_file -core auto_tests/tox_new_test.c other/docker/goblint/sodium.c > analysis.c
|
||||
# Try compiling+linking just to make sure we have all the fake functions.
|
||||
RUN tcc analysis.c
|
||||
|
||||
COPY other/docker/goblint/analysis.json /work/other/docker/goblint/
|
||||
RUN /opt/goblint/analyzer/bin/goblint --conf /work/other/docker/goblint/analysis.json analysis.c
|
||||
@@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eux
|
||||
BUILD=goblint
|
||||
other/docker/sources/build.sh
|
||||
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .
|
||||
@@ -1,123 +0,0 @@
|
||||
#include <sodium.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk, const unsigned char *seed)
|
||||
{
|
||||
memset(pk, 0, 32);
|
||||
memset(sk, 0, 32);
|
||||
return 0;
|
||||
}
|
||||
int crypto_sign_ed25519_pk_to_curve25519(unsigned char *curve25519_pk,
|
||||
const unsigned char *ed25519_pk)
|
||||
{
|
||||
memset(curve25519_pk, 0, 32);
|
||||
return 0;
|
||||
}
|
||||
int crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk,
|
||||
const unsigned char *ed25519_sk)
|
||||
{
|
||||
memset(curve25519_sk, 0, 32);
|
||||
return 0;
|
||||
}
|
||||
void sodium_memzero(void *const pnt, const size_t len)
|
||||
{
|
||||
memset(pnt, 0, len);
|
||||
}
|
||||
int sodium_mlock(void *const addr, const size_t len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int sodium_munlock(void *const addr, const size_t len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int crypto_verify_32(const unsigned char *x, const unsigned char *y)
|
||||
{
|
||||
return memcmp(x, y, 32);
|
||||
}
|
||||
int crypto_verify_64(const unsigned char *x, const unsigned char *y)
|
||||
{
|
||||
return memcmp(x, y, 64);
|
||||
}
|
||||
int crypto_sign_detached(unsigned char *sig, unsigned long long *siglen_p,
|
||||
const unsigned char *m, unsigned long long mlen,
|
||||
const unsigned char *sk)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int crypto_sign_verify_detached(const unsigned char *sig,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *pk)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int crypto_box_beforenm(unsigned char *k, const unsigned char *pk,
|
||||
const unsigned char *sk)
|
||||
{
|
||||
memset(k, 0, 32);
|
||||
return 0;
|
||||
}
|
||||
int crypto_box_afternm(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
{
|
||||
memset(c, 0, 32);
|
||||
return 0;
|
||||
}
|
||||
int crypto_box_open_afternm(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int crypto_scalarmult_curve25519_base(unsigned char *q,
|
||||
const unsigned char *n)
|
||||
{
|
||||
memset(q, 0, 32);
|
||||
return 0;
|
||||
}
|
||||
int crypto_auth(unsigned char *out, const unsigned char *in,
|
||||
unsigned long long inlen, const unsigned char *k)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int crypto_auth_verify(const unsigned char *h, const unsigned char *in,
|
||||
unsigned long long inlen, const unsigned char *k)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int crypto_hash_sha256(unsigned char *out, const unsigned char *in,
|
||||
unsigned long long inlen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int crypto_hash_sha512(unsigned char *out, const unsigned char *in,
|
||||
unsigned long long inlen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int crypto_pwhash_scryptsalsa208sha256(unsigned char *const out,
|
||||
unsigned long long outlen,
|
||||
const char *const passwd,
|
||||
unsigned long long passwdlen,
|
||||
const unsigned char *const salt,
|
||||
unsigned long long opslimit,
|
||||
size_t memlimit)
|
||||
{
|
||||
memset(out, 0, outlen);
|
||||
return 0;
|
||||
}
|
||||
void randombytes(unsigned char *const buf, const unsigned long long buf_len)
|
||||
{
|
||||
memset(buf, 0, buf_len);
|
||||
}
|
||||
uint32_t randombytes_uniform(const uint32_t upper_bound)
|
||||
{
|
||||
return upper_bound;
|
||||
}
|
||||
int sodium_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
FROM alpine:3.21.0
|
||||
FROM alpine:3.23.0
|
||||
|
||||
RUN ["apk", "add", "--no-cache", \
|
||||
"bash", \
|
||||
"benchmark-dev", \
|
||||
"clang", \
|
||||
"gmock", \
|
||||
"gtest-dev", \
|
||||
"libc++-dev", \
|
||||
"libc++-static", \
|
||||
"libconfig-dev", \
|
||||
"libsodium-dev", \
|
||||
"libvpx-dev", \
|
||||
|
||||
@@ -114,6 +114,21 @@ build() {
|
||||
make install
|
||||
cd ..
|
||||
|
||||
echo
|
||||
echo "=== Building GTest $VERSION_GTEST $ARCH ==="
|
||||
curl "${CURL_OPTIONS[@]}" "https://github.com/google/googletest/archive/refs/tags/v$VERSION_GTEST.tar.gz" -o "googletest-$VERSION_GTEST.tar.gz"
|
||||
check_sha256 "65fab701d9829d38cb77c14acdc431d2108bfdbf8979e40eb8ae567edf10b27c" "googletest-$VERSION_GTEST.tar.gz"
|
||||
tar -xf "googletest-$VERSION_GTEST.tar.gz"
|
||||
cd "googletest-$VERSION_GTEST"
|
||||
cmake \
|
||||
-DCMAKE_TOOLCHAIN_FILE=../windows_toolchain.cmake \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX_DIR" \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-S . -B build
|
||||
cmake --build build --target install --parallel "$(nproc)"
|
||||
cd ..
|
||||
|
||||
rm -rf /tmp/*
|
||||
}
|
||||
|
||||
|
||||
1
other/docker/windows/dockerignore
Normal file
1
other/docker/windows/dockerignore
Normal file
@@ -0,0 +1 @@
|
||||
!other/docker/windows/*.sh
|
||||
26
other/docker/windows/run
Executable file
26
other/docker/windows/run
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DOCKERFLAGS=(--build-arg SUPPORT_TEST=true)
|
||||
|
||||
. "$(cd "$(dirname "${BASH_SOURCE[0]}")/../sources" && pwd)/run.sh"
|
||||
|
||||
# Create a temporary directory for the source to workaround potential bind mount issues
|
||||
# (e.g. FUSE/SSHFS filesystems or Docker daemon visibility issues).
|
||||
TEMP_SRC=$(mktemp -d -t toxcore-src-XXXXXX)
|
||||
cleanup() {
|
||||
rm -rf "$TEMP_SRC"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
echo "Copying source to temporary directory $TEMP_SRC..."
|
||||
# Exclude .git and build artifacts to speed up copy
|
||||
rsync -a --exclude .git --exclude _build . "$TEMP_SRC/"
|
||||
|
||||
docker run \
|
||||
-e ENABLE_TEST=true \
|
||||
-e EXTRA_CMAKE_FLAGS=-DUNITTEST=ON \
|
||||
-v "$TEMP_SRC:/toxcore" \
|
||||
-v /tmp/c-toxcore-build:/prefix \
|
||||
-t \
|
||||
--rm \
|
||||
toxchat/c-toxcore:windows
|
||||
@@ -7,6 +7,7 @@ FROM debian:trixie-slim
|
||||
ARG VERSION_OPUS=1.4 \
|
||||
VERSION_SODIUM=1.0.19 \
|
||||
VERSION_VPX=1.14.0 \
|
||||
VERSION_GTEST=1.17.0 \
|
||||
ENABLE_HASH_VERIFICATION=true \
|
||||
\
|
||||
SUPPORT_TEST=false \
|
||||
@@ -21,14 +22,14 @@ ENV SUPPORT_TEST=${SUPPORT_TEST} \
|
||||
CROSS_COMPILE=${CROSS_COMPILE}
|
||||
|
||||
WORKDIR /work
|
||||
COPY check_sha256.sh .
|
||||
COPY get_packages.sh .
|
||||
COPY other/docker/windows/check_sha256.sh .
|
||||
COPY other/docker/windows/get_packages.sh .
|
||||
RUN ./get_packages.sh
|
||||
|
||||
COPY build_dependencies.sh .
|
||||
COPY other/docker/windows/build_dependencies.sh .
|
||||
RUN ./build_dependencies.sh
|
||||
|
||||
COPY build_toxcore.sh .
|
||||
COPY other/docker/windows/build_toxcore.sh .
|
||||
|
||||
ENV ENABLE_TEST=false \
|
||||
ALLOW_TEST_FAILURE=false \
|
||||
24
other/docker/windows/windows.Dockerfile.dockerignore
Normal file
24
other/docker/windows/windows.Dockerfile.dockerignore
Normal file
@@ -0,0 +1,24 @@
|
||||
# ===== common =====
|
||||
# Ignore everything ...
|
||||
**/*
|
||||
# ... except sources
|
||||
!**/*.[ch]
|
||||
!**/*.cc
|
||||
!**/*.hh
|
||||
!CHANGELOG.md
|
||||
!LICENSE
|
||||
!README.md
|
||||
!auto_tests/data/*
|
||||
!other/bootstrap_daemon/bash-completion/**
|
||||
!other/bootstrap_daemon/tox-bootstrapd.*
|
||||
!other/proxy/*.mod
|
||||
!other/proxy/*.sum
|
||||
!other/proxy/*.go
|
||||
# ... and CMake build files (used by most builds).
|
||||
!**/CMakeLists.txt
|
||||
!.github/scripts/flags*.sh
|
||||
!cmake/*.cmake
|
||||
!other/pkgconfig/*
|
||||
!other/rpm/*
|
||||
!so.version
|
||||
!other/docker/windows/*.sh
|
||||
Reference in New Issue
Block a user