diff --git a/.circleci/config.yml b/.circleci/config.yml index 3e6f293e780..a7139aded69 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,13 +10,36 @@ jobs: x86_64: working_directory: ~/work docker: - - image: circleci/builder-base:latest + - image: ubuntu steps: - checkout - - run: add-apt-repository ppa:chris-lea/libsodium - run: apt update - - run: apt install -y clang cmake libgtest-dev libopus-dev libsodium-dev libvpx-dev pkg-config - - run: cmake -H. -B_build -DDEBUG=ON -DTRACE=ON -DERROR_ON_WARNING=ON -DASAN=ON -DMUST_BUILD_TOXAV=ON -DSTRICT_ABI=ON -DTEST_TIMEOUT_SECONDS=90 -DUSE_IPV6=OFF - - run: make -C _build -j$(nproc) - - run: make -C _build test ARGS="-j50 --rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 || make -C _build test ARGS="-j50 --rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 + - run: apt install -y --no-install-recommends + clang + cmake + libconfig-dev + libgtest-dev + libopus-dev + libsodium-dev + libvpx-dev + ninja-build + pkg-config + - run: . .travis/flags-clang.sh; + add_flag -fsanitize=address; + cmake -H. -B_build -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="$PWD/_install" + -DTRACE=ON + -DMUST_BUILD_TOXAV=ON + -DSTRICT_ABI=ON + -DTEST_TIMEOUT_SECONDS=120 + -DUSE_IPV6=OFF + - run: cd _build && ninja install -j$(nproc) + # Retry once, because sometimes tests time out. + # TODO(iphydf): Find out why tests time out on CircleCI. + - run: cd _build && ctest -j50 --output-on-failure + || ctest -j50 --output-on-failure diff --git a/.travis.yml b/.travis.yml index 5bb5a87d467..416aecc7be0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,10 @@ language: c matrix: include: - stage: "Stage 1" - env: JOB=toxcore ENV=linux + env: JOB=cmake-linux compiler: gcc addons: - apt: &apt-dependencies + apt: packages: - libconfig-dev # For tox-bootstrapd. - libcv-dev # For av_test. @@ -23,57 +23,55 @@ matrix: - libgtest-dev # For unit tests. - libvpx-dev # For toxav. - portaudio19-dev # For av_test. + install: .travis/$JOB install + script: .travis/$JOB script + after_script: .travis/upload-coverage - stage: "Stage 1" - if: type IN (push, api, cron) - env: JOB=autotools ENV=linux + env: JOB=autotools-linux compiler: clang addons: - apt: *apt-dependencies - - stage: "Stage 1" - if: type IN (push, api, cron) - env: JOB=toxcore ENV=windows ARCH=i686 - group: deprecated-2017Q4 - services: - - docker - - stage: "Stage 1" - if: type IN (push, api, cron) - env: JOB=toxcore ENV=windows ARCH=x86_64 - group: deprecated-2017Q4 - services: - - docker + apt: + packages: + - libconfig-dev # For tox-bootstrapd. + - libopus-dev # For toxav. + - libvpx-dev # For toxav. + install: .travis/$JOB install + script: .travis/$JOB script - stage: "Stage 1" if: type IN (push, api, cron) - env: JOB=installmd ENV=windows SUPPORT_ARCH_i686=true SUPPORT_ARCH_x86_64=false SUPPORT_TEST=true ENABLE_ARCH_i686=true ENABLE_ARCH_x86_64=false ENABLE_TEST=true ALLOW_TEST_FAILURE=true - services: - - docker + env: JOB=cmake-win32 + services: [docker] + install: .travis/$JOB install + script: .travis/$JOB script - stage: "Stage 1" if: type IN (push, api, cron) - env: JOB=installmd ENV=windows SUPPORT_ARCH_i686=false SUPPORT_ARCH_x86_64=true SUPPORT_TEST=true ENABLE_ARCH_i686=false ENABLE_ARCH_x86_64=true ENABLE_TEST=true ALLOW_TEST_FAILURE=true - services: - - docker + env: JOB=cmake-win64 + services: [docker] + install: .travis/$JOB install + script: .travis/$JOB script - stage: "Stage 1" if: type IN (push, api, cron) - env: JOB=toxcore ENV=freebsd - dist: trusty + env: JOB=cmake-freebsd sudo: required - install: other/travis/phase $JOB $ENV install stage1 - script: other/travis/phase $JOB $ENV script stage1 + install: .travis/$JOB-stage1 install + script: .travis/$JOB-stage1 script - stage: "Stage 1" if: type IN (push, api, cron) - env: JOB=tox-bootstrapd-docker ENV=linux - services: - - docker - sudo: required + env: JOB=tox-bootstrapd-docker + services: [docker] + script: .travis/$JOB - stage: "Stage 2" if: type IN (push, api, cron) - env: JOB=toxcore ENV=freebsd - dist: trusty + env: JOB=cmake-freebsd sudo: required - install: other/travis/phase $JOB $ENV install stage2 + install: .travis/$JOB-stage2 install + script: .travis/$JOB-stage2 script - stage: "Stage 2" if: type IN (push, api, cron) - env: JOB=toxcore ENV=osx RUN_TESTS=true + env: JOB=cmake-osx os: osx + install: .travis/$JOB install + script: .travis/$JOB script fast_finish: true cache: @@ -81,11 +79,6 @@ cache: - $HOME/cache - /opt/freebsd/cache -install: other/travis/phase $JOB $ENV install -script: other/travis/phase $JOB $ENV script -after_script: other/travis/phase $JOB $ENV after_script -after_failure: other/travis/phase $JOB $ENV after_failure - notifications: irc: channels: diff --git a/.travis/autotools-linux b/.travis/autotools-linux new file mode 100755 index 00000000000..6d38e34eb18 --- /dev/null +++ b/.travis/autotools-linux @@ -0,0 +1,52 @@ +#!/bin/sh + +ACTION="$1" + +set -eu + +CACHEDIR="$HOME/cache" +NPROC=`nproc` + +travis_install() { + # Install vanilla NaCl only. + [ -f "$CACHEDIR/lib/amd64/libnacl.a" ] || { + curl https://hyperelliptic.org/nacl/nacl-20110221.tar.bz2 | tar jx + cd nacl-20110221 # pushd + "./do" + # "make install" + mkdir -p "$CACHEDIR/include"; mv build/*/include/* "$CACHEDIR/include" + mkdir -p "$CACHEDIR/lib" ; mv build/*/lib/* "$CACHEDIR/lib" + cd - # popd + } +} + +travis_script() { + . ".travis/flags-$CC.sh" + + add_ld_flag -Wl,-z,defs + + # Make compilation error on a warning + add_flag -Werror + + add_config_flag --with-nacl-libs="$CACHEDIR/lib/amd64" + add_config_flag --with-nacl-headers="$CACHEDIR/include/amd64" + add_config_flag --disable-ipv6 + add_config_flag --enable-nacl + add_config_flag --enable-daemon + add_config_flag --enable-logging + add_config_flag --with-log-level=TRACE + + autoreconf -fi + mkdir -p _build + cd _build # pushd + ../configure $CONFIG_FLAGS || (cat config.log && false) + make "-j$NPROC" -k CFLAGS="$C_FLAGS" LDFLAGS="$LD_FLAGS" + make "-j$NPROC" -k distcheck DISTCHECK_CONFIGURE_FLAGS="$CONFIG_FLAGS" + cd - # popd +} + +if [ "-z" "$ACTION" ]; then + "travis_script" +else + "travis_$ACTION" +fi diff --git a/.travis/cmake-freebsd-stage1 b/.travis/cmake-freebsd-stage1 new file mode 100755 index 00000000000..3954e2af861 --- /dev/null +++ b/.travis/cmake-freebsd-stage1 @@ -0,0 +1,23 @@ +#!/bin/sh + +ACTION="$1" + +set -eu + +. other/travis/env.sh +. other/travis/env-freebsd.sh + +travis_install() { + . other/travis/freebsd-install + . other/travis/freebsd-install-stage1 +} + +travis_script() { + echo "Nothing to do here. Building happens in stage 2." +} + +if [ "-z" "$ACTION" ]; then + "travis_script" +else + "travis_$ACTION" +fi diff --git a/.travis/cmake-freebsd-stage2 b/.travis/cmake-freebsd-stage2 new file mode 100755 index 00000000000..57b8a0f8f65 --- /dev/null +++ b/.travis/cmake-freebsd-stage2 @@ -0,0 +1,23 @@ +#!/bin/sh + +ACTION="$1" + +set -eu + +. other/travis/env.sh +. other/travis/env-freebsd.sh + +travis_install() { + . other/travis/freebsd-install + . other/travis/freebsd-install-stage2 +} + +travis_script() { + . other/travis/toxcore-script +} + +if [ "-z" "$ACTION" ]; then + "travis_script" +else + "travis_$ACTION" +fi diff --git a/.travis/cmake-linux b/.travis/cmake-linux new file mode 100755 index 00000000000..d257261ba8c --- /dev/null +++ b/.travis/cmake-linux @@ -0,0 +1,75 @@ +#!/bin/sh + +ACTION="$1" + +set -eu + +CACHEDIR="$HOME/cache" +NPROC=`nproc` +ASTYLE="$CACHEDIR/astyle/build/gcc/bin/astyle" + +travis_install() { + which coveralls || { + # Install cpp-coveralls to upload test coverage results. + pip install --user ndg-httpsclient urllib3[secure] cpp-coveralls + + # Work around https://github.com/eddyxu/cpp-coveralls/issues/108 by manually + # installing the pyOpenSSL module and injecting it into urllib3 as per + # https://urllib3.readthedocs.io/en/latest/user-guide.html#ssl-py2 + sed -i -e '/^import sys$/a import urllib3.contrib.pyopenssl\nurllib3.contrib.pyopenssl.inject_into_urllib3()' `which coveralls` + } + + # Install astyle (version in ubuntu-precise too old). + [ -f "$ASTYLE" ] || { + wget -O ../astyle.tar.gz https://deb.debian.org/debian/pool/main/a/astyle/astyle_2.06.orig.tar.gz + tar -xf ../astyle.tar.gz -C "$CACHEDIR" + make -C "$CACHEDIR/astyle/build/gcc" "-j$NPROC" + } + + # Install libsodium (not in ubuntu-precise). + [ -f "$CACHEDIR/lib/libsodium.a" ] || { + git clone --depth=1 --branch=stable https://github.com/jedisct1/libsodium ../libsodium + cd ../libsodium # pushd + ./autogen.sh + ./configure --prefix="$CACHEDIR" + make install "-j$NPROC" + cd - # popd + } +} + +travis_script() { + . ".travis/flags-$CC.sh" + + add_ld_flag -Wl,-z,defs + + # Make compilation error on a warning + add_flag -Werror + + # Coverage flags. + add_flag -fprofile-arcs -ftest-coverage + + cmake -B_build -H. \ + -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="$PWD/_install" \ + -DTRACE=ON \ + -DMUST_BUILD_TOXAV=ON \ + -DSTRICT_ABI=ON \ + -DTEST_TIMEOUT_SECONDS=120 \ + -DUSE_IPV6=OFF + + cd _build # pushd + make "-j$NPROC" -k install + make "-j$NPROC" test ARGS="-j50" CTEST_OUTPUT_ON_FAILURE=1 + cd - # popd + + other/astyle/format-source . "$ASTYLE" +} + +if [ "-z" "$ACTION" ]; then + "travis_script" +else + "travis_$ACTION" +fi diff --git a/.travis/cmake-osx b/.travis/cmake-osx new file mode 100755 index 00000000000..529a23094ab --- /dev/null +++ b/.travis/cmake-osx @@ -0,0 +1,46 @@ +#!/bin/sh + +ACTION="$1" + +set -eu + +CACHEDIR="$HOME/cache" +NPROC=`sysctl -n hw.physicalcpu` + +travis_install() { + # Workaround for bug in Homebrew where it only finds an old Ruby version. + brew update + + brew install libsodium libvpx opus libconfig +} + +travis_script() { + . ".travis/flags-$CC.sh" + + add_ld_flag -undefined error + + # Make compilation error on a warning + add_flag -Werror + + cmake -B_build -H. \ + -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="$PWD/_install" \ + -DTRACE=ON \ + -DMUST_BUILD_TOXAV=ON \ + -DTEST_TIMEOUT_SECONDS=120 \ + -DUSE_IPV6=OFF + + cd _build # pushd + make "-j$NPROC" -k install + make "-j$NPROC" test ARGS="-j50" CTEST_OUTPUT_ON_FAILURE=1 + cd - # popd +} + +if [ "-z" "$ACTION" ]; then + "travis_script" +else + "travis_$ACTION" +fi diff --git a/.travis/cmake-win32 b/.travis/cmake-win32 new file mode 100755 index 00000000000..e4be36f0e8e --- /dev/null +++ b/.travis/cmake-win32 @@ -0,0 +1,7 @@ +#!/bin/sh + +i686=true +x86_64=false +WINDOWS_ARCH=win32 + +. .travis/cmake-windows.sh diff --git a/.travis/cmake-win64 b/.travis/cmake-win64 new file mode 100755 index 00000000000..f961a00b8ec --- /dev/null +++ b/.travis/cmake-win64 @@ -0,0 +1,7 @@ +#!/bin/sh + +i686=false +x86_64=true +WINDOWS_ARCH=win64 + +. .travis/cmake-windows.sh diff --git a/.travis/cmake-windows.sh b/.travis/cmake-windows.sh new file mode 100644 index 00000000000..a7d1f7e109f --- /dev/null +++ b/.travis/cmake-windows.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +ACTION="$1" + +set -eu + +CACHEDIR="$HOME/cache" +NPROC=`nproc` + +travis_install() { + cd other/docker/windows + + docker build \ + --build-arg SUPPORT_ARCH_i686=$i686 \ + --build-arg SUPPORT_ARCH_x86_64=$x86_64 \ + --build-arg SUPPORT_TEST=true \ + -t toxcore-$WINDOWS_ARCH \ + . +} + +travis_script() { + . ".travis/flags-$CC.sh" + + # Allows wine to display source code file names and line numbers on crash in + # its backtrace. + add_flag -gdwarf-2 + + docker run \ + -e ALLOW_TEST_FAILURE=true \ + -e ENABLE_ARCH_i686=$i686 \ + -e ENABLE_ARCH_x86_64=$x86_64 \ + -e ENABLE_TEST=true \ + -e EXTRA_CMAKE_FLAGS="-DBOOTSTRAP_DAEMON=OFF -DDEBUG=ON -DTEST_TIMEOUT_SECONDS=90" \ + -e DCMAKE_C_FLAGS="$C_FLAGS" \ + -e CMAKE_CXX_FLAGS="$CXX_FLAGS" \ + -e CMAKE_EXE_LINKER_FLAGS="$LD_FLAGS" \ + -e CMAKE_SHARED_LINKER_FLAGS="$LD_FLAGS" \ + -v "$PWD:/toxcore" \ + -v "$PWD/result:/prefix" \ + --rm \ + toxcore-$WINDOWS_ARCH +} + +if [ "-z" "$ACTION" ]; then + "travis_script" +else + "travis_$ACTION" +fi diff --git a/.travis/flags-clang.sh b/.travis/flags-clang.sh new file mode 100644 index 00000000000..1bca35cad3d --- /dev/null +++ b/.travis/flags-clang.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +. .travis/flags.sh + +# Add all warning flags we can. +add_flag -Wall +add_flag -Wextra +add_flag -Weverything + +# Disable specific warning flags for both C and C++. + +# TODO(iphydf): Clean these up. Probably all of these are actual bugs. +add_flag -Wno-cast-align +# Very verbose, not very useful. This warns about things like int -> uint +# conversions that change sign without a cast and narrowing conversions. +add_flag -Wno-conversion +# TODO(iphydf): Check enum values when received from the user, then assume +# correctness and remove this suppression. +add_flag -Wno-covered-switch-default +# Due to clang's tolower() macro being recursive +# https://github.com/TokTok/c-toxcore/pull/481 +add_flag -Wno-disabled-macro-expansion +# We don't put __attribute__ on the public API. +add_flag -Wno-documentation-deprecated-sync +# Bootstrap daemon does this. +add_flag -Wno-format-nonliteral +# struct Foo foo = {0}; is a common idiom. +add_flag -Wno-missing-field-initializers +# Useful sometimes, but we accept padding in structs for clarity. +# Reordering fields to avoid padding will reduce readability. +add_flag -Wno-padded +# This warns on things like _XOPEN_SOURCE, which we currently need (we +# probably won't need these in the future). +add_flag -Wno-reserved-id-macro +# TODO(iphydf): Clean these up. They are likely not bugs, but still +# potential issues and probably confusing. +add_flag -Wno-sign-compare +# Our use of mutexes results in a false positive, see 1bbe446. +add_flag -Wno-thread-safety-analysis +# File transfer code has this. +add_flag -Wno-type-limits +# Callbacks often don't use all their parameters. +add_flag -Wno-unused-parameter +# libvpx uses __attribute__((unused)) for "potentially unused" static +# functions to avoid unused static function warnings. +add_flag -Wno-used-but-marked-unused +# We use variable length arrays a lot. +add_flag -Wno-vla + +# Disable specific warning flags for C++. + +# Comma at end of enum is supported everywhere we run. +add_cxx_flag -Wno-c++98-compat-pedantic +# TODO(iphydf): Stop using flexible array members. +add_cxx_flag -Wno-c99-extensions +# We're C-compatible, so use C style casts. +add_cxx_flag -Wno-old-style-cast + +# Downgrade to warning so we still see it. +add_flag -Wno-error=documentation-unknown-command +add_flag -Wno-error=unreachable-code +add_flag -Wno-error=unused-variable diff --git a/.travis/flags-gcc.sh b/.travis/flags-gcc.sh new file mode 100644 index 00000000000..0d262060907 --- /dev/null +++ b/.travis/flags-gcc.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +. .travis/flags.sh + +# Add all warning flags we can. +add_flag -Wall +add_flag -Wextra + +# Disable specific warning flags for both C and C++. + +# struct Foo foo = {0}; is a common idiom. +add_flag -Wno-missing-field-initializers +# TODO(iphydf): Clean these up. They are likely not bugs, but still +# potential issues and probably confusing. +add_flag -Wno-sign-compare +# File transfer code has this. +add_flag -Wno-type-limits +# Callbacks often don't use all their parameters. +add_flag -Wno-unused-parameter diff --git a/.travis/flags.sh b/.travis/flags.sh new file mode 100644 index 00000000000..0c80e7038d4 --- /dev/null +++ b/.travis/flags.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +add_config_flag() { CONFIG_FLAGS="$CONFIG_FLAGS $@"; } +add_c_flag() { C_FLAGS="$C_FLAGS $@"; } +add_cxx_flag() { CXX_FLAGS="$CXX_FLAGS $@"; } +add_ld_flag() { LD_FLAGS="$LD_FLAGS $@"; } +add_flag() { add_c_flag "$@"; add_cxx_flag "$@"; } + +export LD_LIBRARY_PATH="$CACHEDIR/lib" +export PKG_CONFIG_PATH="$CACHEDIR/lib/pkgconfig" + +# Our own flags which we can insert in the correct place. We don't use CFLAGS +# and friends here (we unset them below), because they influence config tests +# such as ./configure and cmake tests. Our warning flags break those tests, so +# we can't add them globally here. +CONFIG_FLAGS="" +C_FLAGS="" +CXX_FLAGS="" +LD_FLAGS="" + +unset CFLAGS +unset CXXFLAGS +unset CPPFLAGS +unset LDFLAGS + +# Optimisation flags. +add_flag -O3 -march=native + +# Warn on non-ISO C. +add_c_flag -pedantic + +add_flag -g3 +add_flag -ftrapv diff --git a/other/travis/tox-bootstrapd-docker-linux-script b/.travis/tox-bootstrapd-docker similarity index 99% rename from other/travis/tox-bootstrapd-docker-linux-script rename to .travis/tox-bootstrapd-docker index bb3b5422dd0..9e476b5fbf7 100755 --- a/other/travis/tox-bootstrapd-docker-linux-script +++ b/.travis/tox-bootstrapd-docker @@ -60,4 +60,3 @@ if ! python3 ../fun/bootstrap_node_info.py ipv4 localhost 33445 ; then echo "Error: Unable to get bootstrap node info" exit 1 fi - diff --git a/other/travis/toxcore-linux-after_script b/.travis/upload-coverage similarity index 100% rename from other/travis/toxcore-linux-after_script rename to .travis/upload-coverage diff --git a/CMakeLists.txt b/CMakeLists.txt index cc55a23560b..8cd26f434a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,6 @@ message("SOVERSION: ${SOVERSION}") # ################################################################################ -include(AddCompilerFlag) include(ApiDsl) include(ModulePackage) include(StrictAbi) @@ -63,25 +62,22 @@ if(APPLE) endif() if(UNIX) - if(CMAKE_SYSTEM_NAME MATCHES ".*Linux") - set(LINUX TRUE) - elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*") - set(OPENBSD TRUE) - elseif(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*") - set(NETBSD TRUE) - elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*|FreeBSD") - set(FREEBSD TRUE) - endif() + if(CMAKE_SYSTEM_NAME MATCHES ".*Linux") + set(LINUX TRUE) + elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*") + set(OPENBSD TRUE) + elseif(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*") + set(NETBSD TRUE) + elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*|FreeBSD") + set(FREEBSD TRUE) + endif() endif() enable_testing() set(CMAKE_MACOSX_RPATH ON) -if(${CMAKE_VERSION} VERSION_LESS "3.1.0") - add_cflag("-std=c99") - add_cxxflag("-std=c++11") -else() +if(NOT ${CMAKE_VERSION} VERSION_LESS "3.1.0") # Set standard version for compiler. set(CMAKE_C_STANDARD 99) set(CMAKE_CXX_STANDARD 11) @@ -92,93 +88,9 @@ else() message(STATUS "Supported C++ compiler features = ${CMAKE_CXX_COMPILE_FEATURES}") endif() -if(NOT MSVC) - # Warn on non-ISO C. - add_cflag("-pedantic") - - option(ERROR_ON_WARNING "Make compilation error on a warning" OFF) - if(ERROR_ON_WARNING) - add_flag("-Werror") - endif() - - option(COVERAGE "Track code coverage" OFF) - if(COVERAGE) - add_flag("-fprofile-instr-generate") - add_flag("-fcoverage-mapping") - endif() - - option(DEBUG "Enable assertions and other debugging facilities" OFF) - if(DEBUG) - set(MIN_LOGGER_LEVEL DEBUG) - add_cflag("-g3") - if(MINGW) - # Allows wine to display source code file names and line numbers on crash in its backtrace - add_flag("-gdwarf-2") - endif() - # Crash on signed integer overflow. - add_flag("-ftrapv") - endif() - - option(WARNINGS "Enable additional compiler warnings" ON) - if(WARNINGS) - # Add all warning flags we can. - add_flag("-Wall") - add_flag("-Wextra") - add_flag("-Weverything") - - # Disable specific warning flags for both C and C++. - - # TODO(iphydf): Clean these up. Probably all of these are actual bugs. - add_flag("-Wno-cast-align") - # Very verbose, not very useful. This warns about things like int -> uint - # conversions that change sign without a cast and narrowing conversions. - add_flag("-Wno-conversion") - # TODO(iphydf): Check enum values when received from the user, then assume - # correctness and remove this suppression. - add_flag("-Wno-covered-switch-default") - # Due to clang's tolower() macro being recursive - # https://github.com/TokTok/c-toxcore/pull/481 - add_flag("-Wno-disabled-macro-expansion") - # We don't put __attribute__ on the public API. - add_flag("-Wno-documentation-deprecated-sync") - # Bootstrap daemon does this. - add_flag("-Wno-format-nonliteral") - # struct Foo foo = {0}; is a common idiom. - add_flag("-Wno-missing-field-initializers") - # Useful sometimes, but we accept padding in structs for clarity. - # Reordering fields to avoid padding will reduce readability. - add_flag("-Wno-padded") - # This warns on things like _XOPEN_SOURCE, which we currently need (we - # probably won't need these in the future). - add_flag("-Wno-reserved-id-macro") - # TODO(iphydf): Clean these up. They are likely not bugs, but still - # potential issues and probably confusing. - add_flag("-Wno-sign-compare") - # Our use of mutexes results in a false positive, see 1bbe446. - add_flag("-Wno-thread-safety-analysis") - # File transfer code has this. - add_flag("-Wno-type-limits") - # Callbacks often don't use all their parameters. - add_flag("-Wno-unused-parameter") - # libvpx uses __attribute__((unused)) for "potentially unused" static - # functions to avoid unused static function warnings. - add_flag("-Wno-used-but-marked-unused") - # We use variable length arrays a lot. - add_flag("-Wno-vla") - - # Disable specific warning flags for C++. - - # Comma at end of enum is supported everywhere we run. - add_cxxflag("-Wno-c++98-compat-pedantic") - # TODO(iphydf): Stop using flexible array members. - add_cxxflag("-Wno-c99-extensions") - # We're C-compatible, so use C style casts. - add_cxxflag("-Wno-old-style-cast") - - # Downgrade to warning so we still see it. - add_flag("-Wno-error=unreachable-code") - add_flag("-Wno-error=unused-variable") - endif() +option(TRACE "Enable DEBUG level logging (default)" ON) +if(DEBUG) + set(MIN_LOGGER_LEVEL DEBUG) endif() option(TRACE "Enable TRACE level logging (expensive, for network debugging)" OFF) @@ -190,18 +102,6 @@ if(MIN_LOGGER_LEVEL) add_definitions(-DMIN_LOGGER_LEVEL=LOG_${MIN_LOGGER_LEVEL}) endif() -option(ASAN "Enable address-sanitizer to detect invalid memory accesses" OFF) -if(ASAN) - add_cflag("-fsanitize=address") - add_dllflag("-fsanitize=address") -endif() - -if(LINUX) - add_dllflag("-Wl,-z,defs") -else() - add_dllflag("-undefined error") -endif() - option(USE_IPV6 "Use IPv6 in tests" ON) if(NOT USE_IPV6) add_definitions(-DUSE_IPV6=0) diff --git a/cmake/AddCompilerFlag.cmake b/cmake/AddCompilerFlag.cmake deleted file mode 100644 index 6a4a3f563a8..00000000000 --- a/cmake/AddCompilerFlag.cmake +++ /dev/null @@ -1,47 +0,0 @@ -include(CheckCCompilerFlag) -include(CheckCXXCompilerFlag) - -function(add_cflag flag) - string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" var ${flag}) - if(NOT DEFINED HAVE_C${var}) - message(STATUS "checking for C compiler flag: ${flag}") - endif() - set(CMAKE_REQUIRED_QUIET TRUE) - - check_c_compiler_flag("${flag}" HAVE_C${var} QUIET) - if(HAVE_C${var}) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE) - endif() -endfunction() - -function(add_cxxflag flag) - string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" var ${flag}) - if(NOT DEFINED HAVE_CXX${var}) - message(STATUS "checking for C++ compiler flag: ${flag}") - endif() - set(CMAKE_REQUIRED_QUIET TRUE) - - check_cxx_compiler_flag("${flag}" HAVE_CXX${var} QUIET) - if(HAVE_CXX${var}) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE) - endif() -endfunction() - -function(add_dllflag flag) - string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" var ${flag}) - if(NOT DEFINED HAVE_LD${var}) - message(STATUS "checking for C++ compiler flag: ${flag}") - endif() - set(CMAKE_REQUIRED_QUIET TRUE) - - check_c_compiler_flag("${flag}" HAVE_LD${var} QUIET) - if(HAVE_LD${var}) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${flag}" PARENT_SCOPE) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}" PARENT_SCOPE) - endif() -endfunction() - -macro(add_flag flag) - add_cflag(${flag}) - add_cxxflag(${flag}) -endmacro() diff --git a/cmake/CompileGTest.cmake b/cmake/CompileGTest.cmake index f9aa4506d67..9aa4712f1cf 100644 --- a/cmake/CompileGTest.cmake +++ b/cmake/CompileGTest.cmake @@ -1,5 +1,8 @@ # Find and compile the GTest library. +include(CheckCXXCompilerFlag) +include(CheckIncludeFileCXX) + message(STATUS "Checking for gtest") # Look for the sources. diff --git a/configure.ac b/configure.ac index 450a1d538eb..d070cd77f30 100644 --- a/configure.ac +++ b/configure.ac @@ -350,7 +350,9 @@ if test "x$WANT_NACL" = "xyes"; then if (test -f "$NACL_SEARCH_LIBS/cpucycles.o") && (test -f "$NACL_SEARCH_LIBS/randombytes.o"); then NACL_OBJECTS="$NACL_SEARCH_LIBS/cpucycles.o $NACL_SEARCH_LIBS/randombytes.o" + AC_MSG_NOTICE([found extra NaCl objects: $NACL_OBJECTS]) if test "x$ADD_NACL_OBJECTS_TO_PKGCONFIG" = "xyes"; then + AC_MSG_NOTICE([adding extra NaCl objects to pkg-config file]) NACL_OBJECTS_PKGCONFIG="$NACL_OBJECTS" fi else diff --git a/other/bootstrap_daemon/src/Makefile.inc b/other/bootstrap_daemon/src/Makefile.inc index 1c313d44bf3..6b820be09bb 100644 --- a/other/bootstrap_daemon/src/Makefile.inc +++ b/other/bootstrap_daemon/src/Makefile.inc @@ -33,6 +33,7 @@ tox_bootstrapd_LDADD = \ libtoxcore.la \ $(LIBCONFIG_LIBS) \ $(LIBSODIUM_LIBS) \ + $(NACL_OBJECTS) \ $(NACL_LIBS) endif diff --git a/other/docker/windows/build_toxcore.sh b/other/docker/windows/build_toxcore.sh index a38304554b6..da465eb114c 100644 --- a/other/docker/windows/build_toxcore.sh +++ b/other/docker/windows/build_toxcore.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/bin/sh set -e -x @@ -57,9 +57,13 @@ build() -DCMAKE_INSTALL_PREFIX="${STATIC_TOXCORE_PREFIX_DIR}" \ -DENABLE_SHARED=OFF \ -DENABLE_STATIC=ON \ + -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}" \ + -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" \ + -DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS}" \ + -DCMAKE_SHARED_LINKER_FLAGS="${CMAKE_SHARED_LINKER_FLAGS}" \ ${EXTRA_CMAKE_FLAGS} \ .. - cmake --build . --target install + cmake --build . --target install -- -j$(nproc) if [ "${ENABLE_TEST}" = "true" ]; then rm -rf /root/.wine @@ -79,7 +83,7 @@ build() if [ "${ALLOW_TEST_FAILURE}" = "true" ]; then set +e fi - cmake --build . --target test + cmake --build . --target test -- ARGS="-j50" if [ "${ALLOW_TEST_FAILURE}" = "true" ]; then set -e fi diff --git a/other/travis/autotools-linux-install b/other/travis/autotools-linux-install deleted file mode 100644 index ca0adff7782..00000000000 --- a/other/travis/autotools-linux-install +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -. other/travis/toxcore-linux-install - -# Also install vanilla NaCl -[ -f $CACHE_DIR/lib/amd64/libnacl.a ] || { - curl https://hyperelliptic.org/nacl/nacl-20110221.tar.bz2 | tar jx - cd nacl-20110221 # pushd - "./do" - # "make install" - mv build/*/include/* $CACHE_DIR/include - mv build/*/lib/* $CACHE_DIR/lib - cd - # popd -} diff --git a/other/travis/autotools-script b/other/travis/autotools-script deleted file mode 100755 index d72ec2a99e0..00000000000 --- a/other/travis/autotools-script +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -if perl -e ' - use Socket qw(PF_INET6 SOCK_STREAM pack_sockaddr_in6 IN6ADDR_LOOPBACK); - - socket(S, PF_INET6, SOCK_STREAM, 0) || exit 1; - bind(S, pack_sockaddr_in6(0, IN6ADDR_LOOPBACK)) || exit 1; -'; then - IPV6_FLAG="--enable-ipv6" -else - IPV6_FLAG="--disable-ipv6" -fi - -# Build toxcore with some custom flags here. Note that this does *not* run the -# tests, so any flags passed here are irrelevant to testing. This only checks -# that we can build toxcore with the specified flags. Tests run with default -# configure flags. -./autogen.sh -./configure \ - --with-nacl-libs=$CACHE_DIR/lib/amd64 \ - --with-nacl-headers=$CACHE_DIR/include/amd64 \ - --enable-nacl \ - --enable-daemon \ - --enable-logging \ - $IPV6_FLAG \ - --with-log-level=TRACE - -# We use make instead of RUN $MAKE here, because the autotools build will only -# ever run natively on the Linux container, never on a Windows cross compilation -# docker instance or an OSX machine. -make -j$NPROC -k - -# This runs `make check` with the default configure flags, not with the ones -# above. -TESTS $MAX_TEST_RETRIES make distcheck -j$NPROC -k diff --git a/other/travis/env-linux.sh b/other/travis/env-linux.sh deleted file mode 100644 index 9f25e911dd3..00000000000 --- a/other/travis/env-linux.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -export PATH=/opt/ghc/7.8.4/bin:/opt/cabal/1.18/bin:/opt/alex/3.1.7/bin:/opt/happy/1.19.5/bin:$PATH -export PATH=$HOME/.cabal/bin:$PATH - -CMAKE=cmake -# Asan is disabled because it's currently broken on Travis. -# See https://github.com/travis-ci/travis-ci/issues/9033. -CMAKE_EXTRA_FLAGS="$CMAKE_EXTRA_FLAGS -DASAN=OFF" -NPROC=`nproc` -CURDIR=$PWD -RUN_TESTS=true - -RUN() { - "$@" -} - -TESTS() { - COUNT="$1"; shift - "$@" || { - if [ $COUNT -gt 1 ]; then - TESTS `expr $COUNT - 1` "$@" - else - false - fi - } -} diff --git a/other/travis/env-osx.sh b/other/travis/env-osx.sh deleted file mode 100644 index af1794f432e..00000000000 --- a/other/travis/env-osx.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -CMAKE=cmake -CMAKE_EXTRA_FLAGS="$CMAKE_EXTRA_FLAGS" -NPROC=`sysctl -n hw.ncpu` -CURDIR=$PWD - -RUN() { - "$@" -} - -TESTS() { - COUNT="$1"; shift - "$@" || { - if [ $COUNT -gt 1 ]; then - TESTS `expr $COUNT - 1` "$@" - else - false - fi - } -} diff --git a/other/travis/env-windows.sh b/other/travis/env-windows.sh deleted file mode 100644 index 525630ae970..00000000000 --- a/other/travis/env-windows.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh - -CMAKE_EXTRA_FLAGS="$CMAKE_EXTRA_FLAGS -DBOOTSTRAP_DAEMON=OFF -DERROR_ON_WARNING=OFF" - -if [ "$JOB" = "toxcore" ]; then - CMAKE=$ARCH-w64-mingw32.shared-cmake - NPROC=`nproc` - CURDIR=/work - RUN_TESTS=true - - RUN() { - ./dockcross "$@" - } - - TESTS() { - shift # Ignore test run count. - - # Download Microsoft DLLs. - curl http://www.dlldump.com/dllfiles/I/iphlpapi.dll -o _build/iphlpapi.dll - curl http://www.dlldump.com/dllfiles/W/ws2_32.dll -o _build/ws2_32.dll - - # Copy our dependency DLLs. - ./dockcross sh -c 'cp $WINEDLLPATH/*.dll _build' - - # Run tests in docker. - ./dockcross "$@" || { - cat _build/Testing/Temporary/LastTest.log - # Ignore test failures on Windows builds for now. - #false - } - } -elif [ "$JOB" = "installmd" ]; then - true -else - echo "Unsupported JOB=$JOB" -fi diff --git a/other/travis/freebsd-script-stage1 b/other/travis/freebsd-script-stage1 deleted file mode 100755 index ce16aea1b69..00000000000 --- a/other/travis/freebsd-script-stage1 +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -# We don't want toxcore-script to run yet, it should be done during FreeBSD stage 2 -exit 0 diff --git a/other/travis/installmd-windows-install b/other/travis/installmd-windows-install deleted file mode 100755 index 8a85bbbd3fd..00000000000 --- a/other/travis/installmd-windows-install +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -cd other/docker/windows - -docker build \ - --build-arg SUPPORT_ARCH_i686=${SUPPORT_ARCH_i686} \ - --build-arg SUPPORT_ARCH_x86_64=${SUPPORT_ARCH_x86_64} \ - --build-arg SUPPORT_TEST=${SUPPORT_TEST} \ - -t toxcore \ - . - -cd - diff --git a/other/travis/installmd-windows-script b/other/travis/installmd-windows-script deleted file mode 100755 index 906a7f1d62e..00000000000 --- a/other/travis/installmd-windows-script +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -docker run \ - -e ALLOW_TEST_FAILURE=${ALLOW_TEST_FAILURE} \ - -e ENABLE_ARCH_i686=${ENABLE_ARCH_i686} \ - -e ENABLE_ARCH_x86_64=${ENABLE_ARCH_x86_64} \ - -e ENABLE_TEST=${ENABLE_TEST} \ - -e EXTRA_CMAKE_FLAGS="${CMAKE_EXTRA_FLAGS} -DDEBUG=ON -DTEST_TIMEOUT_SECONDS=90" \ - -v ${PWD}:/toxcore \ - -v ${PWD}/result:/prefix \ - --rm \ - toxcore diff --git a/other/travis/phase b/other/travis/phase deleted file mode 100755 index cb9c2abf00b..00000000000 --- a/other/travis/phase +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -set -e -u -x - -JOB="$1" -ENV="$2" -PHASE="$3" -STAGE="" - -set +u -if [ ! -z "$4" ] ; then - STAGE="$4" -fi -set -u - -. "other/travis/env.sh" -. "other/travis/env-$ENV.sh" - -try_source() { - SCRIPT="other/travis/$1" - if [ -f "$SCRIPT" ]; then - . "$SCRIPT" - fi - if [ ! -z "$STAGE" ] && [ -f "$SCRIPT-$STAGE" ]; then - . "$SCRIPT-$STAGE" - fi -} - -try_source "$PHASE" -try_source "$ENV-$PHASE" -try_source "$JOB-$PHASE" -try_source "$JOB-$ENV-$PHASE" diff --git a/other/travis/toxcore-after_failure b/other/travis/toxcore-after_failure deleted file mode 100755 index e1f5c39963d..00000000000 --- a/other/travis/toxcore-after_failure +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -if [ -d /cores ]; then - for core in /cores/*; do - lldb --core $core --one-line "bt all" < /dev/null - done -fi diff --git a/other/travis/toxcore-linux-install b/other/travis/toxcore-linux-install deleted file mode 100755 index 19dccf64838..00000000000 --- a/other/travis/toxcore-linux-install +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -# Install cpp-coveralls to upload test coverage results. -pip install --user ndg-httpsclient urllib3[secure] cpp-coveralls - -# Work around https://github.com/eddyxu/cpp-coveralls/issues/108 by manually -# installing the pyOpenSSL module and injecting it into urllib3 as per -# https://urllib3.readthedocs.io/en/latest/user-guide.html#ssl-py2 -sed -i -e '/^import sys$/a import urllib3.contrib.pyopenssl\nurllib3.contrib.pyopenssl.inject_into_urllib3()' `which coveralls` - -# Install astyle (version in ubuntu-precise too old). -[ -f $ASTYLE ] || { - wget -O ../astyle.tar.gz https://deb.debian.org/debian/pool/main/a/astyle/astyle_2.06.orig.tar.gz - tar -xf ../astyle.tar.gz -C $CACHE_DIR - make -C $CACHE_DIR/astyle/build/gcc -j$NPROC -} - -# Install libsodium (not in ubuntu-precise). -[ -f $CACHE_DIR/lib/libsodium.a ] || { - git clone --depth=1 --branch=stable https://github.com/jedisct1/libsodium ../libsodium - cd ../libsodium # pushd - ./autogen.sh - ./configure --prefix=$CACHE_DIR - make install -j$NPROC - cd - # popd -} diff --git a/other/travis/toxcore-osx-install b/other/travis/toxcore-osx-install deleted file mode 100755 index 8f13cb5fd97..00000000000 --- a/other/travis/toxcore-osx-install +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -# Workaround for bug in Homebrew where it only finds an old Ruby version. -brew update - -brew install libsodium libvpx opus libconfig astyle diff --git a/other/travis/toxcore-windows-install b/other/travis/toxcore-windows-install deleted file mode 100755 index 6160856b616..00000000000 --- a/other/travis/toxcore-windows-install +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -DOCKER_IMAGE=toktoknet/windows:latest.$ARCH-shared - -docker pull $DOCKER_IMAGE -docker run --rm $DOCKER_IMAGE > dockcross -chmod +x dockcross diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c index b2f0e5f0d3b..027f69c3712 100644 --- a/toxcore/crypto_core.c +++ b/toxcore/crypto_core.c @@ -89,28 +89,28 @@ int32_t public_key_cmp(const uint8_t *pk1, const uint8_t *pk2) uint8_t random_u08(void) { uint8_t randnum; - randombytes(&randnum, 1); + random_bytes(&randnum, 1); return randnum; } uint16_t random_u16(void) { uint16_t randnum; - randombytes((uint8_t *)&randnum, sizeof(randnum)); + random_bytes((uint8_t *)&randnum, sizeof(randnum)); return randnum; } uint32_t random_u32(void) { uint32_t randnum; - randombytes((uint8_t *)&randnum, sizeof(randnum)); + random_bytes((uint8_t *)&randnum, sizeof(randnum)); return randnum; } uint64_t random_u64(void) { uint64_t randnum; - randombytes((uint8_t *)&randnum, sizeof(randnum)); + random_bytes((uint8_t *)&randnum, sizeof(randnum)); return randnum; } @@ -266,13 +266,13 @@ void increment_nonce_number(uint8_t *nonce, uint32_t host_order_num) /* Fill the given nonce with random bytes. */ void random_nonce(uint8_t *nonce) { - randombytes(nonce, crypto_box_NONCEBYTES); + random_bytes(nonce, crypto_box_NONCEBYTES); } /* Fill a key CRYPTO_SYMMETRIC_KEY_SIZE big with random bytes */ void new_symmetric_key(uint8_t *key) { - randombytes(key, CRYPTO_SYMMETRIC_KEY_SIZE); + random_bytes(key, CRYPTO_SYMMETRIC_KEY_SIZE); } int32_t crypto_new_keypair(uint8_t *public_key, uint8_t *secret_key)