simdjson/fuzz/CMakeLists.txt

76 lines
3.0 KiB
CMake
Raw Normal View History

if(NOT SIMDJSON_LEGACY_VISUAL_STUDIO AND NOT SIMDJSON_WINDOWS_DLL)
option(SIMDJSON_ENABLE_FUZZING "enable building the fuzzers" ON)
else()
option(SIMDJSON_ENABLE_FUZZING "enable building the fuzzers" OFF)
endif()
2020-04-17 09:49:10 +08:00
if(SIMDJSON_ENABLE_FUZZING)
2020-04-17 09:49:10 +08:00
# First attempt at a fuzzer, using libFuzzer.
#
# compile like this:
# mkdir build-fuzzer
# cd build-fuzzer
# export LDFLAGS="-fsanitize=address,undefined"
# export CXXFLAGS="-fsanitize=fuzzer-no-link,address,undefined"
# export CFLAGS="-fsanitize=fuzzer-no-link,address,undefined"
# export CXX=clang++
# export CC=clang++
# cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug -DSIMDJSON_ENABLE_FUZZING=On -DSIMDJSON_FUZZ_LINKMAIN=Off -DSIMDJSON_FUZZ_LDFLAGS=-fsanitize=fuzzer
2020-04-17 09:49:10 +08:00
# ninja
# settings this links in a main. useful for reproducing,
# kcov, gdb, afl, valgrind.
# (note that libFuzzer can also reproduce, just pass it the files)
#
# Using this by default, means the fuzzers will be built as a part of the normal
# workflow, meaning they won't bitrot and will participate in refactoring etc.
2020-04-17 09:49:10 +08:00
#
option(SIMDJSON_FUZZ_LINKMAIN "links a main into fuzz targets for building reproducers" On)
# For oss-fuzz - insert $LIB_FUZZING_ENGINE into the link flags, but only for
# the fuzz targets, otherwise the cmake configuration step fails.
set(SIMDJSON_FUZZ_LDFLAGS "" CACHE STRING "LDFLAGS for the fuzz targets")
# Fuzzer build flags and libraries
add_library(simdjson-fuzzer INTERFACE)
CMake refactor stage1 (#1512) * Remove CMP0025 policy This policy is already set to NEW by the minimum required version. * Use HOMEPAGE_URL in the project call * Use VERSION in the project call * Detect if this is the top project * Port simdjson-user-cmakecache to a CMake script * Create a developer mode The SIMDJSON_DEVELOPER_MODE option set to ON will enable targets that are only useful for developers of simdjson. * Consolidate root CML commands into logical sections * Warn about intended use of developer mode * Prettify the just_ascii test * Remove redundant CMake variables * Inline CML contents from include and src * Raise minimum CMake requirement to 3.14 * Define proper install rules * Restore thread support variable * Add BUILD_SHARED_LIBS as a top level only option * Force developer mode to be on in CI * Include flags earlier in developer mode * Set CMAKE_BUILD_TYPE conditionally CMAKE_BUILD_TYPE is used only by single configuration generators and is otherwise completely ignored. * Remove useless static/shared options simdjson now uses the CMake builtin BUILD_SHARED_LIBS to switch the built artifact's type. * Remove unused CMAKE_MODULE_PATH variable * Refactor implementation switching into a module * Factor exception option out into a module * Reformat simdjson-flags.cmake * Rename simdjson-flags to developer-options * Accumulate properties into an include module This is done this way to avoid using utility targets that must be exported and installed, which could potentially be misused by users of the library. * Port impl definitions to props * Port exception options to props * Lift normal options to the top * Port developer options to props * Remove simdjson-flags from benchmark * Document the developer mode in HACKING * Fix include path in installed config file * Fix formatting of prop commands * Fix tests that include .cpp files * Change GCC AVX fixes back to compile options * Deprecate SIMDJSON_BUILD_STATIC * Always link fuzz targets to simdjson * Install CMake from simdjson's debian repo * Add gnupg for apt-key * Make sure ASan link flags come first * Pass CI env variable to cmake invocation * Install package for apt-add-repository * Remove return() from flush macro * Use directory level commands instead of props * Restore the github repository variable * Set developer mode unconditionally for checkperf The CI env variable is only set in the CI and this target is always run in developer mode. * Attempt to fix ODR violation in parsing checks These tests were compiling the simdjson.cpp file again and linking to the simdjson library target causes ODR violations. Instead of linking to the target, just inherit its props. * Move variables before the source dir * Mark props to be flushed after adding more * Use props for every command for the library * Use keyword form for linking libs * Handle deprecation of SIMDJSON_JUST_LIBRARY * Handle deprecations in a separate module Co-authored-by: friendlyanon <friendlyanon@users.noreply.github.com>
2021-04-23 21:24:56 +08:00
target_link_libraries(simdjson-fuzzer INTERFACE simdjson)
if (SIMDJSON_FUZZ_LINKMAIN)
2020-04-17 09:49:10 +08:00
target_sources(simdjson-fuzzer INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/main.cpp)
else ()
target_link_libraries(simdjson-fuzzer INTERFACE ${SIMDJSON_FUZZ_LDFLAGS})
endif ()
target_link_libraries(simdjson-fuzzer INTERFACE simdjson-internal-flags)
# Define the fuzzers
add_custom_target(all_fuzzers)
set(fuzzernames)
2020-04-17 09:49:10 +08:00
function(implement_fuzzer name)
add_executable(${name} ${name}.cpp)
target_link_libraries(${name} PRIVATE simdjson-fuzzer)
add_dependencies(all_fuzzers ${name})
set(fuzzernames ${fuzzernames} ${name} PARENT_SCOPE)
2020-04-17 09:49:10 +08:00
endfunction()
implement_fuzzer(fuzz_atpointer)
2020-04-17 09:49:10 +08:00
implement_fuzzer(fuzz_dump)
implement_fuzzer(fuzz_dump_raw_tape)
implement_fuzzer(fuzz_element)
implement_fuzzer(fuzz_implementations) # parses and serializes again, compares across implementations
implement_fuzzer(fuzz_minify) # minify *with* parsing
implement_fuzzer(fuzz_minifyimpl) # minify *without* parsing, plus compare implementations
implement_fuzzer(fuzz_ndjson) # the ndjson api
2020-10-30 02:14:44 +08:00
implement_fuzzer(fuzz_ondemand)
implement_fuzzer(fuzz_padded)
implement_fuzzer(fuzz_parser)
implement_fuzzer(fuzz_print_json)
implement_fuzzer(fuzz_utf8) # utf8 verification, compares across implementations
# to be able to get a list of all fuzzers from within a script
add_custom_target(print_all_fuzzernames
COMMAND ${CMAKE_COMMAND} -E echo ${fuzzernames})
2020-04-17 09:49:10 +08:00
endif()