Files
conflict-range/cpp/CMakeLists.txt
T
andrew 3bb5d062ff Harden and fully cover the C++ translation
Add an exhaustive readable-instance sweep and a coverage gate requiring
100% line coverage of the summarised implementation. Delete branches that
are unreachable under `Readable`, centralise and assert the 32-bit offset
contract at the public entry points, and stop materialising `n` zero bytes
when deciding `keyAfterN n k < upper`.

Also add the extreme-offset regression test, harden the corpus parsers,
remove unused model helpers, document the literal-total / fast-readable
split, and refresh the validation and benchmark numbers.
2026-11-17 18:46:24 -05:00

73 lines
3.0 KiB
CMake

cmake_minimum_required(VERSION 3.20)
project(conflict_range_cpp LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
endif()
option(CR_BUILD_FUZZERS "Build libFuzzer differential/safety harnesses" ON)
option(CR_BUILD_BENCH "Build the nanobench comparison" ON)
add_library(cr_literal STATIC src/literal.cpp)
target_include_directories(cr_literal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_library(cr_fast STATIC src/fast.cpp)
target_include_directories(cr_fast PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
# Golden-vector check: the literal translation against vectors produced by
# `lake env lean --run cpp/oracle/gen.lean`.
add_executable(golden_test tests/golden.cpp)
target_link_libraries(golden_test PRIVATE cr_literal)
# Literal vs. fast on Lean-generated cases that satisfy the readable sorting
# invariant.
add_executable(diff_corpus tests/diff_corpus.cpp)
target_link_libraries(diff_corpus PRIVATE cr_literal cr_fast)
# Regression test for offsets at the extremes of `Int`.
add_executable(extreme_test tests/extreme.cpp)
target_include_directories(extreme_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/tests)
target_link_libraries(extreme_test PRIVATE cr_literal cr_fast)
# Deterministic exhaustive sweep of small readable instances. This is the
# driver for the line-coverage check in `run-coverage.sh`.
add_executable(exhaustive_test tests/exhaustive.cpp)
target_include_directories(exhaustive_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/tests)
target_link_libraries(exhaustive_test PRIVATE cr_literal cr_fast)
if(CR_BUILD_BENCH)
add_executable(cr_bench tests/bench.cpp)
target_include_directories(cr_bench PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/third_party
${CMAKE_CURRENT_SOURCE_DIR}/tests)
target_link_libraries(cr_bench PRIVATE cr_literal cr_fast)
target_compile_definitions(cr_bench PRIVATE NDEBUG)
endif()
if(CR_BUILD_FUZZERS AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CR_FUZZ_FLAGS -fsanitize=fuzzer,address,undefined
-fno-sanitize-recover=all -g -O1)
# Compile the implementations into each fuzz target directly, so that the
# library code itself is instrumented (linking a plain static library would
# only instrument the harness).
add_executable(fuzz_readable tests/fuzz_readable.cpp src/literal.cpp
src/fast.cpp)
target_include_directories(fuzz_readable PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/tests)
target_compile_options(fuzz_readable PRIVATE ${CR_FUZZ_FLAGS})
target_link_options(fuzz_readable PRIVATE -fsanitize=fuzzer,address,undefined)
add_executable(fuzz_raw tests/fuzz_raw.cpp src/literal.cpp src/fast.cpp)
target_include_directories(fuzz_raw PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/tests)
target_compile_options(fuzz_raw PRIVATE ${CR_FUZZ_FLAGS})
target_link_options(fuzz_raw PRIVATE -fsanitize=fuzzer,address,undefined)
endif()