Skip to content
Merged
21 changes: 12 additions & 9 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,33 @@
- Use the Bazel build system when interacting with this repository.
- The CMake build system is available to help users who need it.
- Keep both the CMake and Bazel builds working at all times.
- Use at most one CPU core for all builds, tests, and other expensive commands.
For Bazel, pass `--jobs=1`. For CMake builds, pass `--parallel 1`. For
`make`, pass `-j1`.

## Building with Bazel

To build all code with bazel:
```bash
bazel build src:all
bazel build --jobs=1 src:all
```
To build the Tesseract and Simplex main binaries:
```bash
bazel build src:tesseract src:simplex
bazel build --jobs=1 src:tesseract src:simplex
```

## Running Tests with Bazel

```bash
bazel test src/...
bazel test --jobs=1 src/...
```

## Building with CMake

In case you need to, when building with CMake, use parallel flags to speed up the process.
In case you need to build with CMake, keep the build single-core.

- When using `cmake --build`, add the `--parallel` flag.
- When using `make`, add the `-j` flag (e.g., `make -j$(nproc)`).
- When using `cmake --build`, add `--parallel 1`.
- When using `make`, add `-j1`.

## Running Tests with CMake

Expand All @@ -36,7 +39,7 @@ To run the tests, execute the following commands from the root of the repository
mkdir -p build
cd build
cmake ..
cmake --build . --parallel
cmake --build . --parallel 1
ctest
```

Expand All @@ -49,7 +52,7 @@ To build the Python wheel for `tesseract_decoder` locally, you will need to use
Use the following command:

```bash
bazel build //:tesseract_decoder_wheel --define=VERSION=0.1.1 --define=TARGET_VERSION=py313
bazel build --jobs=1 //:tesseract_decoder_wheel --define=VERSION=0.1.1 --define=TARGET_VERSION=py313
```

- `--define=VERSION=0.1.1`: Sets the version of the wheel. You should replace `0.1.1` with the current version from the `_version.py` file.
Expand All @@ -62,7 +65,7 @@ The resulting wheel file will be located in the `bazel-bin/` directory.
If you change the Python version in `MODULE.bazel`, you will need to regenerate the `requirements_lock.txt` file to ensure all dependencies are compatible. To do this, run the following command:

```bash
bazel run //src/py:requirements.update
bazel run --jobs=1 //src/py:requirements.update
```

This will update the `src/py/requirements_lock.txt` file with the correct dependency versions for the new Python environment.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ target_include_directories(tesseract_lib PUBLIC ${TESSERACT_SRC_DIR})
target_compile_options(tesseract_lib PRIVATE ${OPT_COPTS})
target_link_libraries(tesseract_lib PUBLIC utils boost_headers visualization)

add_library(tesseract_trellis_lib
${TESSERACT_SRC_DIR}/tesseract_trellis.cc
${TESSERACT_SRC_DIR}/tesseract_trellis.h
)
target_include_directories(tesseract_trellis_lib PUBLIC ${TESSERACT_SRC_DIR})
target_compile_options(tesseract_trellis_lib PRIVATE ${OPT_COPTS})
target_link_libraries(tesseract_trellis_lib PUBLIC common utils libstim Threads::Threads)

add_library(simplex ${TESSERACT_SRC_DIR}/simplex.cc ${TESSERACT_SRC_DIR}/simplex.h)
target_include_directories(simplex PUBLIC ${TESSERACT_SRC_DIR})
target_compile_options(simplex PRIVATE ${OPT_COPTS})
Expand All @@ -108,6 +116,12 @@ add_executable(tesseract ${TESSERACT_SRC_DIR}/tesseract_main.cc)
target_compile_options(tesseract PRIVATE ${OPT_COPTS})
target_link_libraries(tesseract PRIVATE tesseract_lib argparse::argparse nlohmann_json::nlohmann_json)

add_executable(tesseract_trellis ${TESSERACT_SRC_DIR}/tesseract_trellis_main.cc)
target_compile_options(tesseract_trellis PRIVATE ${OPT_COPTS})
target_link_libraries(tesseract_trellis
PRIVATE tesseract_trellis_lib argparse::argparse nlohmann_json::nlohmann_json
)

add_executable(simplex_bin ${TESSERACT_SRC_DIR}/simplex_main.cc)
set_target_properties(simplex_bin PROPERTIES OUTPUT_NAME simplex)
target_compile_options(simplex_bin PRIVATE ${OPT_COPTS})
Expand Down Expand Up @@ -137,3 +151,6 @@ 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)

add_executable(tesseract_trellis_test ${TESSERACT_SRC_DIR}/tesseract_trellis.test.cc)
target_link_libraries(tesseract_trellis_test PRIVATE tesseract_trellis_lib GTest::gtest_main)
add_test(NAME tesseract_trellis_test COMMAND tesseract_trellis_test)
39 changes: 39 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ cc_library(
],
)

cc_library(
name = "libtesseract_trellis",
srcs = ["tesseract_trellis.cc"],
hdrs = ["tesseract_trellis.h"],
copts = OPT_COPTS,
linkopts = OPT_LINKOPTS,
deps = [
":libcommon",
":libutils",
"@stim//:stim_lib",
],
)

cc_binary(
name = "tesseract",
srcs = ["tesseract_main.cc"],
Expand All @@ -153,6 +166,19 @@ cc_binary(
],
)

cc_binary(
name = "tesseract_trellis",
srcs = ["tesseract_trellis_main.cc"],
copts = OPT_COPTS,
linkopts = OPT_LINKOPTS,
deps = [
":libtesseract_trellis",
"@argparse",
"@nlohmann_json//:json",
"@stim//:stim_lib",
],
)

cc_test(
name = "tesseract_tests",
timeout = "eternal",
Expand All @@ -169,6 +195,19 @@ cc_test(
],
)

cc_test(
name = "tesseract_trellis_tests",
srcs = ["tesseract_trellis.test.cc"],
copts = OPT_COPTS,
linkopts = OPT_LINKOPTS,
deps = [
":libtesseract_trellis",
"@gtest",
"@gtest//:gtest_main",
"@stim//:stim_lib",
],
)

cc_test(
name = "common_tests",
srcs = ["common.test.cc"],
Expand Down
1 change: 1 addition & 0 deletions src/simplex_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ struct Args {
// Create a writer instance to write the predicted obs to a file
stim::FileFormatData predictions_out_format = stim::format_name_to_enum_map().at(out_format);
FILE* predictions_file = stdout;
// An output path of "-" means stdout.
if (out_fname != "-") {
predictions_file = fopen(out_fname.c_str(), "w");
}
Expand Down
1 change: 1 addition & 0 deletions src/tesseract_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ struct Args {
// Create a writer instance to write the predicted obs to a file
stim::FileFormatData predictions_out_format = stim::format_name_to_enum_map().at(out_format);
FILE* predictions_file = stdout;
// An output path of "-" means stdout.
if (out_fname != "-") {
predictions_file = fopen(out_fname.c_str(), "w");
}
Expand Down
Loading
Loading