diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..e4213a70 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +/_build +/_install diff --git a/.github/scripts/cmake-alpine-s390x b/.github/scripts/cmake-alpine-s390x new file mode 100755 index 00000000..13b99bdb --- /dev/null +++ b/.github/scripts/cmake-alpine-s390x @@ -0,0 +1,55 @@ +#!/bin/bash +# Copyright (C) 2018-2023 nurupo + +# Toxcore building + +set -eux + +cd .. # /work +. cmake-alpine-run.sh + +# === Get VM ready to build the code === + +start_vm + +RUN apk add cmake g++ ninja + +mv c-toxcore / + +# Copy over toxcore code from host to qemu +scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P "$SSH_PORT" -r /c-toxcore root@localhost:~ + +cd /c-toxcore +. ".github/scripts/flags-gcc.sh" + +# Make compilation error on a warning +add_flag -Werror + +# - disabling toxav because vpx doesn't work on s390x. +# - disabling bootstrap daemons because we don't need them for testing (saving time). +# - disabling shared libraries because it saves a lot of time on building PIC objects. +# - enable unity build because it saves a lot of time as well (fewer objects to build). +RUN "cmake -B_build -Hc-toxcore -GNinja \ + -DCMAKE_C_FLAGS='$C_FLAGS' \ + -DCMAKE_CXX_FLAGS='$CXX_FLAGS' \ + -DCMAKE_EXE_LINKER_FLAGS='$LD_FLAGS' \ + -DCMAKE_SHARED_LINKER_FLAGS='$LD_FLAGS' \ + -DCMAKE_INSTALL_PREFIX:PATH='_install' \ + -DCMAKE_UNITY_BUILD=ON \ + -DMIN_LOGGER_LEVEL=TRACE \ + -DNON_HERMETIC_TESTS=ON \ + -DENABLE_SHARED=OFF \ + -DBUILD_TOXAV=OFF \ + -DDHT_BOOTSTRAP=OFF \ + -DBOOTSTRAP_DAEMON=OFF \ + -DSTRICT_ABI=ON \ + -DTEST_TIMEOUT_SECONDS=90 \ + -DUSE_IPV6=OFF \ + -DAUTOTEST=ON" + +RUN 'cmake --build _build --parallel 2 --target install -- -k 0' +RUN 'cd _build && ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:1 --timeout 90 || true' & + +# Give the tests 5 minutes to run. Sometimes, the per-test timeout doesn't +# work, so we put a global timeout here for everything. +sleep 300 diff --git a/.github/scripts/cmake-freebsd-stage2 b/.github/scripts/cmake-freebsd similarity index 55% rename from .github/scripts/cmake-freebsd-stage2 rename to .github/scripts/cmake-freebsd index f6bdd09e..a7101f39 100755 --- a/.github/scripts/cmake-freebsd-stage2 +++ b/.github/scripts/cmake-freebsd @@ -1,23 +1,19 @@ #!/bin/bash -# Copyright (C) 2018-2021 nurupo +# Copyright (C) 2018-2023 nurupo # Toxcore building set -eux -if [ "$PWD" != "/work" ]; then - cd .. - mv c-toxcore / - mkdir c-toxcore - cd /work -fi - +cd .. # /work . cmake-freebsd-run.sh # === Get VM ready to build the code === gunzip "$IMAGE_NAME.gz" +mv c-toxcore / + start_vm # Copy over toxcore code from host to qemu @@ -26,27 +22,34 @@ scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P "$SSH_PORT" - RUN ls -lh cd /c-toxcore -. ".github/scripts/flags-clang.sh" +. '.github/scripts/flags-clang.sh' add_ld_flag -Wl,-z,defs -# Make compilation error on a warning +# Make compilation error on a warning. add_flag -Werror -RUN 'cmake -B_build -Hc-toxcore \ - -DCMAKE_C_FLAGS="$C_FLAGS" \ - -DCMAKE_CXX_FLAGS="$CXX_FLAGS" \ - -DCMAKE_EXE_LINKER_FLAGS="$LD_FLAGS" \ - -DCMAKE_SHARED_LINKER_FLAGS="$LD_FLAGS" \ - -DCMAKE_INSTALL_PREFIX:PATH="_install" \ +# This triggers on FreeBSD's clang. +add_flag -Wno-format +add_flag -Wno-unsafe-buffer-usage + +RUN "cmake -B_build -Hc-toxcore \ + -DCMAKE_C_FLAGS='$C_FLAGS' \ + -DCMAKE_CXX_FLAGS='$CXX_FLAGS' \ + -DCMAKE_EXE_LINKER_FLAGS='$LD_FLAGS' \ + -DCMAKE_SHARED_LINKER_FLAGS='$LD_FLAGS' \ + -DCMAKE_INSTALL_PREFIX:PATH='_install' \ -DMIN_LOGGER_LEVEL=TRACE \ -DMUST_BUILD_TOXAV=ON \ -DNON_HERMETIC_TESTS=ON \ -DSTRICT_ABI=ON \ -DTEST_TIMEOUT_SECONDS=90 \ -DUSE_IPV6=OFF \ - -DAUTOTEST=ON' + -DAUTOTEST=ON" -# We created the VM with the same number of cores as the host, so the host-ran `nproc` here is fine +# We created the VM with the same number of cores as the host, so the host-ran `nproc` here is fine. RUN 'gmake "-j$NPROC" -k install -C_build' RUN 'gmake "-j$NPROC" test ARGS="-j50" -C_build || true' + +# Gracefully shut down the VM. +stop_vm diff --git a/.github/scripts/flags.sh b/.github/scripts/flags.sh index 80a56c01..dd7ca18b 100644 --- a/.github/scripts/flags.sh +++ b/.github/scripts/flags.sh @@ -28,8 +28,6 @@ add_flag -O3 -march=native # Warn on non-ISO C. add_c_flag -pedantic -add_c_flag -std=c99 -add_cxx_flag -std=c++11 add_flag -g3 add_flag -ftrapv diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eacf919c..f0c169a0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,6 +90,26 @@ jobs: with: file: other/docker/compcert/Dockerfile + build-alpine-s390x: + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Docker Build + uses: docker/build-push-action@v2 + with: + file: other/docker/alpine-s390x/Dockerfile + + build-freebsd: + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Docker Build + uses: docker/build-push-action@v2 + with: + file: other/docker/freebsd/Dockerfile + cimplefmt: runs-on: ubuntu-latest steps: @@ -117,16 +137,6 @@ jobs: - name: Cross compilation run: .github/scripts/cmake-win64 script - build-freebsd: - runs-on: ubuntu-latest - container: toxchat/freebsd - steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - - name: Build on FreeBSD - run: .github/scripts/cmake-freebsd-stage2 - build-macos: runs-on: macos-latest steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index 028112d4..e5cdd9f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,8 @@ # ################################################################################ -cmake_minimum_required(VERSION 2.8.12) -cmake_policy(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.5) +cmake_policy(VERSION 3.5) project(toxcore) list(APPEND CMAKE_MODULE_PATH ${toxcore_SOURCE_DIR}/cmake) @@ -79,21 +79,14 @@ enable_testing() set(CMAKE_MACOSX_RPATH ON) -if(${CMAKE_VERSION} VERSION_LESS "3.1.0") - if(NOT MSVC) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") - endif() -else() - # Set standard version for compiler. - set(CMAKE_C_STANDARD 99) - set(CMAKE_CXX_STANDARD 17) - set(CMAKE_C_EXTENSIONS OFF) - set(CMAKE_CXX_EXTENSIONS OFF) +# Set standard version for compiler. +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_C_EXTENSIONS OFF) +set(CMAKE_CXX_EXTENSIONS OFF) - message(STATUS "Supported C compiler features = ${CMAKE_C_COMPILE_FEATURES}") - message(STATUS "Supported C++ compiler features = ${CMAKE_CXX_COMPILE_FEATURES}") -endif() +message(STATUS "Supported C compiler features = ${CMAKE_C_COMPILE_FEATURES}") +message(STATUS "Supported C++ compiler features = ${CMAKE_CXX_COMPILE_FEATURES}") set(MIN_LOGGER_LEVEL "" CACHE STRING "Logging level to use (TRACE, DEBUG, INFO, WARNING, ERROR)") if(MIN_LOGGER_LEVEL) diff --git a/cmake/StrictAbi.cmake b/cmake/StrictAbi.cmake index 22b1ca44..f91ec160 100644 --- a/cmake/StrictAbi.cmake +++ b/cmake/StrictAbi.cmake @@ -29,7 +29,7 @@ function(_make_version_script target) list(GET sublib 1 ns) execute_process( - COMMAND ${SHELL} -c "egrep '^\\w' ${header} | grep '${ns}_[a-z0-9_]*(' | grep -v '^typedef' | grep -o '${ns}_[a-z0-9_]*(' | egrep -o '\\w+' | sort -u" + COMMAND ${SHELL} -c "egrep '^\\w' ${header} | grep '${ns}_[a-z0-9_]*(' | grep -v '^typedef' | grep -o '${ns}_[a-z0-9_]*(' | egrep -o '[a-z0-9_]+' | sort -u" OUTPUT_VARIABLE sublib_SYMS OUTPUT_STRIP_TRAILING_WHITESPACE) string(REPLACE "\n" ";" sublib_SYMS ${sublib_SYMS}) diff --git a/other/analysis/run-clang-tidy b/other/analysis/run-clang-tidy index a87b517b..1fa49759 100755 --- a/other/analysis/run-clang-tidy +++ b/other/analysis/run-clang-tidy @@ -2,6 +2,9 @@ CHECKS="*" +# We don't use memcpy_s. +CHECKS="$CHECKS,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling" + # __attribute__((nonnull)) causes this warning on defensive null checks. CHECKS="$CHECKS,-clang-diagnostic-pointer-bool-conversion" CHECKS="$CHECKS,-clang-diagnostic-tautological-pointer-compare" @@ -57,6 +60,11 @@ CHECKS="$CHECKS,-readability-redundant-control-flow" CHECKS="$CHECKS,-bugprone-narrowing-conversions" CHECKS="$CHECKS,-cppcoreguidelines-narrowing-conversions" +# TODO(iphydf): Probably fix this in tox-bootstrapd.c. +CHECKS="$CHECKS,-cert-dcl03-c" +CHECKS="$CHECKS,-hicpp-static-assert" +CHECKS="$CHECKS,-misc-static-assert" + # TODO(iphydf): We might want some of these. For the ones we don't want, add a # comment explaining why not. CHECKS="$CHECKS,-clang-analyzer-optin.performance.Padding" diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 6a5f4618..8d607165 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -b18557c5c89ac6a06137a692418270ab08adc0544ed631545b862fca21502743 /usr/local/bin/tox-bootstrapd +05c389460de83d58533a658d0df625600bc3e6940bbcc738db9dddee249fac59 /usr/local/bin/tox-bootstrapd diff --git a/other/docker/alpine-s390x/Dockerfile b/other/docker/alpine-s390x/Dockerfile new file mode 100644 index 00000000..86b1f1fd --- /dev/null +++ b/other/docker/alpine-s390x/Dockerfile @@ -0,0 +1,6 @@ +FROM toxchat/alpine-s390x:latest + +WORKDIR /work/c-toxcore +COPY . /work/c-toxcore/ + +RUN .github/scripts/cmake-alpine-s390x diff --git a/other/docker/alpine-s390x/run b/other/docker/alpine-s390x/run new file mode 100755 index 00000000..f77eede2 --- /dev/null +++ b/other/docker/alpine-s390x/run @@ -0,0 +1,5 @@ +#!/bin/sh + +set -eux +BUILD=alpine-s390x +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . diff --git a/other/docker/autotools/run b/other/docker/autotools/run index 895ff3ca..aadb1440 100755 --- a/other/docker/autotools/run +++ b/other/docker/autotools/run @@ -1,3 +1,5 @@ #!/bin/sh -docker build -t toxchat/c-toxcore:autotools -f other/docker/autotools/Dockerfile . +set -eux +BUILD=autotools +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . diff --git a/other/docker/cimplefmt/run b/other/docker/cimplefmt/run index 5016a063..1211bb89 100755 --- a/other/docker/cimplefmt/run +++ b/other/docker/cimplefmt/run @@ -5,4 +5,4 @@ if [ "$1" = "-u" ]; then docker pull toxchat/haskell:hs-cimple docker build -t toxchat/cimplefmt -f other/docker/cimplefmt/Dockerfile . fi -docker run --rm -v "$PWD:/work" toxchat/cimplefmt "$@" +docker run --name toxcore-cimplefmt --rm -v "$PWD:/work" toxchat/cimplefmt "$@" diff --git a/other/docker/circleci/run b/other/docker/circleci/run index 22aedf9f..668e0fc8 100755 --- a/other/docker/circleci/run +++ b/other/docker/circleci/run @@ -3,4 +3,4 @@ SANITIZER="${1:-asan}" docker build -t toxchat/c-toxcore:circleci other/docker/circleci -docker run --rm -it -v "$PWD:/c-toxcore" toxchat/c-toxcore:circleci "$SANITIZER" +docker run --name toxcore-circleci --rm -it -v "$PWD:/c-toxcore" toxchat/c-toxcore:circleci "$SANITIZER" diff --git a/other/docker/compcert/run b/other/docker/compcert/run index a0613428..8b03c84c 100755 --- a/other/docker/compcert/run +++ b/other/docker/compcert/run @@ -1,5 +1,5 @@ #!/bin/sh set -eux - -docker build -t toxchat/c-toxcore:compcert -f other/docker/compcert/Dockerfile . +BUILD=compcert +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . diff --git a/other/docker/coverage/run b/other/docker/coverage/run index cfb57691..a170812b 100755 --- a/other/docker/coverage/run +++ b/other/docker/coverage/run @@ -4,4 +4,4 @@ set -eux docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile . docker build -t toxchat/c-toxcore:coverage other/docker/coverage -docker run --rm -it -p "28192:80" toxchat/c-toxcore:coverage +docker run --name toxcore-coverage --rm -it -p "28192:80" toxchat/c-toxcore:coverage diff --git a/other/docker/doxygen/run b/other/docker/doxygen/run index 85b24cb7..c702ba5f 100755 --- a/other/docker/doxygen/run +++ b/other/docker/doxygen/run @@ -3,4 +3,4 @@ set -eux docker build -t toxchat/c-toxcore:docs -f other/docker/doxygen/Dockerfile . -docker run --rm -it -p "28192:80" toxchat/c-toxcore:docs +docker run --name toxcore-docs --rm -it -p "28192:80" toxchat/c-toxcore:docs diff --git a/other/docker/freebsd/Dockerfile b/other/docker/freebsd/Dockerfile new file mode 100644 index 00000000..6e933d0f --- /dev/null +++ b/other/docker/freebsd/Dockerfile @@ -0,0 +1,6 @@ +FROM toxchat/freebsd:latest + +WORKDIR /work/c-toxcore +COPY . /work/c-toxcore/ + +RUN .github/scripts/cmake-freebsd diff --git a/other/docker/freebsd/run b/other/docker/freebsd/run new file mode 100755 index 00000000..f4448a46 --- /dev/null +++ b/other/docker/freebsd/run @@ -0,0 +1,5 @@ +#!/bin/sh + +set -eux +BUILD=freebsd +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . diff --git a/other/docker/misra/run b/other/docker/misra/run index ab228f7a..2f96bb4b 100755 --- a/other/docker/misra/run +++ b/other/docker/misra/run @@ -1,3 +1,5 @@ #!/bin/sh -docker build -f other/docker/misra/Dockerfile . +set -eux +BUILD=misra +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . diff --git a/other/docker/perf/run b/other/docker/perf/run index 44f336ca..4834614e 100755 --- a/other/docker/perf/run +++ b/other/docker/perf/run @@ -3,7 +3,7 @@ set -eux docker build -t toxchat/c-toxcore:perf -f other/docker/perf/Dockerfile . -docker run --privileged --rm -it \ +docker run --name toxcore-perf --privileged --rm -it \ -v "$PWD:/work/c-toxcore" \ toxchat/c-toxcore:perf \ "$@" diff --git a/other/docker/tcc/run b/other/docker/tcc/run index be28a71c..870852ba 100755 --- a/other/docker/tcc/run +++ b/other/docker/tcc/run @@ -1,5 +1,5 @@ #!/bin/sh set -eux - -docker build -t toxchat/c-toxcore:tcc -f other/docker/tcc/Dockerfile . +BUILD=tcc +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . diff --git a/other/docker/tokstyle/run b/other/docker/tokstyle/run index 30c2a738..c743defd 100755 --- a/other/docker/tokstyle/run +++ b/other/docker/tokstyle/run @@ -1,3 +1,5 @@ #!/bin/sh -docker build -f other/docker/tokstyle/Dockerfile . +set -eux +BUILD=tokstyle +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . diff --git a/toxcore/network.c b/toxcore/network.c index 0dd3c539..3e0e6f49 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -1184,11 +1184,11 @@ Networking_Core *new_networking_ex( int n = 1024 * 1024 * 2; if (net_setsockopt(ns, temp->sock, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) != 0) { - LOGGER_ERROR(log, "failed to set socket option %d", SO_RCVBUF); + LOGGER_WARNING(log, "failed to set socket option %d", SO_RCVBUF); } if (net_setsockopt(ns, temp->sock, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n)) != 0) { - LOGGER_ERROR(log, "failed to set socket option %d", SO_SNDBUF); + LOGGER_WARNING(log, "failed to set socket option %d", SO_SNDBUF); } /* Enable broadcast on socket */