Public headers expose only approved third-party types
Context#
Designing the installed public C++ headers for dftracer-utils.
Decision#
Public headers may name only third-party types that were made public on purpose: ankerl unordered_dense for speed, moodycamel concurrentqueue in Channel<T>, tl::expected as the error type, simdjson inside json/ only (JsonValue holds simdjson::dom::element by value), and MPI in MPI builds. Hide RocksDB, nanoarrow, zlib, and moodycamel or simdjson outside their one owning header or module. Hide service types such as RocksDatabase with a pimpl, use a std:: container instead of an ankerl map where speed does not matter, and move single-module code to src/.
Why#
Every dependency named in a public header must be installed with the package. A user program with another version of the library can get two definitions of one type (an ODR violation), which can crash without an error. An exposed type also becomes part of the API and increases compile time. cmake/modules/Dependencies.cmake installs simdjson, ankerl and nanoarrow headers only for this reason.
Rejected options#
Leaving using Batch = rocksdb::WriteBatch in index/store/database.h.
Evidence#
The planned guard is a ctest that compiles each public header alone, with an include path of include/ plus only public dependencies. This catches both internal dependency leaks and headers that do not include their own requirements.
Also found by searching
- which third party dependencies can appear in a public header
- prevent internal dependency types from leaking into an installed C++ API
- how should public headers hide RocksDB and zlib types
- what is safe to expose in dftracer-utils headers