From 0f24d396f362bc4709ff73c7cf7fb09910adb4ff Mon Sep 17 00:00:00 2001 From: Alex Shabalin Date: Thu, 15 Feb 2024 12:35:08 +0100 Subject: [PATCH] Fuzzers do not require Catch2 --- CMakeLists.txt | 15 ++++++++------- extra/fuzzer/CMakeLists.txt | 3 +++ flake.nix | 11 ++++++----- test/CMakeLists.txt | 1 + 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 091f2b99..386cc725 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ option(immer_BUILD_TESTS "Build tests" ON) option(immer_BUILD_EXAMPLES "Build examples" ON) option(immer_BUILD_DOCS "Build docs" ON) option(immer_BUILD_EXTRAS "Build extras" ON) +option(immer_INSTALL_FUZZERS "Install fuzzers" off) set(CXX_STANDARD 14 CACHE STRING "c++ standard number") @@ -136,16 +137,16 @@ endif() # Testing # ======= +if (immer_BUILD_TESTS OR immer_BUILD_EXAMPLES OR immer_BUILD_EXTRAS) + add_custom_target(check + COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Build and run all the tests and examples.") +endif() + if (immer_BUILD_TESTS) enable_testing() - find_package(Catch2 REQUIRED) - - add_custom_target(check - COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Build and run all the tests and examples.") - add_subdirectory(test) add_subdirectory(benchmark) endif() diff --git a/extra/fuzzer/CMakeLists.txt b/extra/fuzzer/CMakeLists.txt index 777289f8..2c160f79 100644 --- a/extra/fuzzer/CMakeLists.txt +++ b/extra/fuzzer/CMakeLists.txt @@ -26,4 +26,7 @@ foreach(_file IN LISTS immer_fuzzers) if (CHECK_FUZZERS) add_test("fuzzer/${_output}" ${_output} -max_total_time=1) endif() + if (immer_INSTALL_FUZZERS) + install(TARGETS ${_target} DESTINATION bin) + endif() endforeach() diff --git a/flake.nix b/flake.nix index 0f67ca16..18247fff 100644 --- a/flake.nix +++ b/flake.nix @@ -49,7 +49,7 @@ }; }; - inherit (self.packages.${system}) unit-tests; + inherit (self.packages.${system}) unit-tests fuzzers-debug; } // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux { unit-tests-valgrind = self.packages.${system}.unit-tests.overrideAttrs (prev: { @@ -94,18 +94,19 @@ default = self.packages.${system}.immer; fuzzers-debug = (withLLVM self.packages.${system}.immer).overrideAttrs (prev: { - buildInputs = with pkgs; [catch2_3 boehmgc boost fmt]; + name = "immer-fuzzers"; + # Fuzzers should be built with minimal dependencies to use them easily with OSS-Fuzz + buildInputs = with pkgs; [boehmgc]; nativeBuildInputs = with pkgs; [cmake ninja]; dontBuild = false; dontStrip = true; # fuzzers target is not built by default ninjaFlags = ["fuzzers"]; + cmakeBuildType = "Debug"; cmakeFlags = [ - "-DCMAKE_BUILD_TYPE=Debug" + "-DENABLE_ASAN=ON" "-Dimmer_BUILD_TESTS=OFF" - "-Dimmer_BUILD_EXAMPLES=OFF" "-Dimmer_INSTALL_FUZZERS=ON" - "-DENABLE_ASAN=ON" ]; }); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 590dc775..1812e9ed 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,6 +6,7 @@ add_custom_target(tests COMMENT "Build all the unit tests.") add_dependencies(check tests) +find_package(Catch2 REQUIRED) include(CTest) file(GLOB_RECURSE immer_unit_tests "*.cpp")