build-sanitize.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env bash
  2. # A sanitizer build of the app, the tests and the tools (round 190rb, the 0.1.32 quality release), Linux / macOS with
  3. # GCC or Clang:
  4. #
  5. # scripts/build-sanitize.sh [extra cmake arguments...]
  6. #
  7. # env: SAN=address,undefined (default; e.g. thread for TSan, which cannot be combined with address)
  8. # BUILD=build-san the build folder
  9. # JOBS=3 parallel compiles (tests.cpp alone needs several GB under ASan)
  10. # NOBUILD=1 only configure (e.g. to build through your own job queue)
  11. #
  12. # Running (the suppression files list system libraries, third-party code and LYNX's deliberate process-life caches;
  13. # a real LYNX leak is fixed, never suppressed). The main thread needs a big stack under ASan (its frames grow): ulimit -s 1048576
  14. # export ASAN_OPTIONS=detect_leaks=1:abort_on_error=0:halt_on_error=1:detect_stack_use_after_return=0:\
  15. # suppressions=$PWD/tests/sanitizers/asan.supp
  16. # export LSAN_OPTIONS=suppressions=$PWD/tests/sanitizers/lsan.supp:print_suppressions=0
  17. # export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=0:suppressions=$PWD/tests/sanitizers/ubsan.supp
  18. # build-san/lynx_tests "<FL Studio>/Data" build-san/LYNX_artefacts/RelWithDebInfo/LYNX --selftest out.txt
  19. #
  20. # -O1 keeps the run fast enough for the whole suite while every report still has its file:line; NDEBUG as in releases
  21. # (the same code paths as the shipped app). LTO is off (the sanitizers' instrumentation and LTO do not mix well).
  22. set -euo pipefail
  23. cd "$(dirname "$0")/.."
  24. SAN="${SAN:-address,undefined}"
  25. BUILD="${BUILD:-build-san}"
  26. if [[ ! -f "$BUILD/CMakeCache.txt" ]]; then
  27. cmake -S . -B "$BUILD" -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo \
  28. -DCMAKE_C_FLAGS_RELWITHDEBINFO="-O1 -g -DNDEBUG" -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O1 -g -DNDEBUG" \
  29. -DLYNX_SANITIZE="$SAN" -DLYNX_LTO=OFF "$@"
  30. fi
  31. [[ "${NOBUILD:-0}" == 1 ]] && exit 0
  32. cmake --build "$BUILD" -j "${JOBS:-3}" --target LYNX lynx_tests