From fc95154ede86da8e20af706e07846aa0c88bb861 Mon Sep 17 00:00:00 2001 From: noajshu Date: Sun, 31 Aug 2025 01:39:12 +0000 Subject: [PATCH 1/3] feat: Add CMake test support and parallel build instructions --- AGENTS.md | 8 ++++++++ CMakeLists.txt | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index c0b30ad..17966fa 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -4,6 +4,14 @@ - A bug in some LLM coding environments makes Bazel difficult to use, so agents should rely on CMake. - Keep both the CMake and Bazel builds working at all times. +## Building with CMake + +When building with CMake, use parallel flags to speed up the process. + +- When using `cmake --build`, add the `--parallel` flag. +- When using `make`, add the `-j` flag (e.g., `make -j$(nproc)`). + + ## Building the Python Wheel To build the Python wheel for `tesseract_decoder` locally, you will need to use the `bazel build` command and provide the version and Python target version as command-line arguments. This is because the `py_wheel` rule in the `BUILD` file uses "Make" variable substitution, which expects these values to be defined at build time. diff --git a/CMakeLists.txt b/CMakeLists.txt index 10e5ea6..817ccda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,15 @@ FetchContent_Declare( set(PYBIND11_TEST OFF CACHE BOOL "" FORCE) FetchContent_MakeAvailable(pybind11) +# Google Test +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG release-1.12.1 +) +FetchContent_MakeAvailable(googletest) + + set(OPT_COPTS -Ofast -fno-fast-math -march=native) set(TESSERACT_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) @@ -111,3 +120,14 @@ set_target_properties(tesseract_decoder PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_SOURCE_DIR}/src ) +# === Tests === +enable_testing() + +add_executable(common_test ${TESSERACT_SRC_DIR}/common.test.cc) +target_link_libraries(common_test PRIVATE common GTest::gtest_main) +add_test(NAME common_test COMMAND common_test) + +add_executable(tesseract_test ${TESSERACT_SRC_DIR}/tesseract.test.cc) +target_link_libraries(tesseract_test PRIVATE tesseract_lib simplex GTest::gtest_main) +add_test(NAME tesseract_test COMMAND tesseract_test) + From 8e688560713a1d85e2df972a587d07ed7940b322 Mon Sep 17 00:00:00 2001 From: noajshu Date: Sun, 31 Aug 2025 01:39:45 +0000 Subject: [PATCH 2/3] docs: Add CMake test instructions to AGENTS.md --- AGENTS.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index 17966fa..dc7ddb2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -11,6 +11,19 @@ When building with CMake, use parallel flags to speed up the process. - When using `cmake --build`, add the `--parallel` flag. - When using `make`, add the `-j` flag (e.g., `make -j$(nproc)`). +## Running Tests with CMake + +To run the tests, execute the following commands from the root of the repository: + +```bash +mkdir -p build +cd build +cmake .. +cmake --build . --parallel +ctest +``` + + ## Building the Python Wheel From 5110df8f13779edf58ba0ef8cacfb63e8055b1b8 Mon Sep 17 00:00:00 2001 From: noajshu Date: Sun, 31 Aug 2025 01:41:25 +0000 Subject: [PATCH 3/3] style: Apply clang-format to tesseract.pybind.h --- src/tesseract.pybind.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tesseract.pybind.h b/src/tesseract.pybind.h index df17a0c..5a68648 100644 --- a/src/tesseract.pybind.h +++ b/src/tesseract.pybind.h @@ -199,8 +199,6 @@ void add_tesseract_module(py::module& root) { `TesseractConfig` object. )pbdoc"); - - py::class_(m, "TesseractDecoder", R"pbdoc( A class that implements the Tesseract decoding algorithm.