libCat is a non-POSIX compliant C++26 runtime.
It has no pthreads nor malloc(), and by extension no exceptions.
It has type-safe arithmetic, SIMD, fast syscalls, CRTP interfaces,
libCat requires a recent development version of Clang 23 from the trunk branch.
It is tested on GitHub using the official nightly distribution,
so this is certainly servicable for any local or downstream development.
Compiling libCat is only routinely tested using ninja, but other build systems may work.
The "Ninja Multi-Config" generator is also supported.
A reasonably recent version of CMake is required (at least 3.28 is recommended).
export CXX=clang++-23
cmake -B build/ -G 'Ninja'
cmake --build build/
./build/tests/unit_tests # or ctest --test-dir/build --output-on-failureThe .clang-format and .clang-tidy configurations are only compatible with correspondingly
recent builds of clang-tools.
Currently, running libCat requires AVX2. On x86 microarchitectures lacking that, the Intel Software Development Emulator is known to work for libCat binaries.
Developers are encouraged to set CAT_USE_SANITIZERS (default OFF).
cmake -B build/ -DCAT_USE_SANITIZERS=ONThis will compile every translation unit with
AddressSanitizer + UndefinedBehaviorSanitizer. Mutually exclusive with link
time optimization. Turning this off in Release / RelWithDebInfo will enable LTO.
libCat provides several developer utilities. They are organized in the cmake/
subdirectory.
cmake --build build/ --target cat-formatRuns clang-format in place on every libCat implementation source and public
header. The files which changed are reported afterwards.
CMake automatically attempts to find an appropriate version of clang-format on PATH.
Override its choice with -DCAT_CLANG_FORMAT_PATH=/path/to/clang-format. This is only
applied to libCat sources, so it is not recommended to configure this unless it failed
to find a suitable version.
cmake --build build/ --target cat-format-checkThe read-only variant of cat-format primarily intended for CI. Performs the
same comparison as cat-format, but instead of rewriting, it reports every
file that would be reformatted. If one or more files are reported, then the script
exits with an error code.
cmake --build build/ --target cat-tidyRuns clang-tidy across every libCat translation unit via the run-clang-tidy
driver, applying fix-its in place and re-formatting touched lines with the
project’s .clang-format rules. Uses the build directory’s
compile_commands.json, which the tidy target forces CMake to emit.
CMake automatically attempts to find an appropriate version of clang-tidy
and run-clang-tidy on PATH (both ship together in the clang-tools-<N>
apt package). Override either with -DCAT_CLANG_TIDY_PATH=/path/to/clang-tidy
or -DCAT_RUN_CLANG_TIDY_PATH=/path/to/run-clang-tidy. These are only applied
to libCat sources, so it is not recommended to configure them unless discovery
failed.
cmake --build build/ --target cat-tidy-checkThe read-only variant of cat-tidy primarily intended for CI. Runs the same
clang-tidy pass with -warnings-as-errors=* so any diagnostic exits the
script with an error code. Fix the reported issues (or run cat-tidy to apply
the auto-fixable subset).
cmake --build build/ --target cat-opt-reportCompiles a Clang optimization report and prints the opt-viewer.py invocation required
to render the resulting record into an interactive HTML document.
Optview2 is not distributed with LLVM, but it may be preferred with this output.
cmake --build build/ --target cat-intermediariesSaves compilation byproducts to the build directories. For example:
build/runtime/_start.ii build/string/memset.ii build/string/memset.bc build/string/memset.s build/linux/syscall0.ii build/tests/test_alloc.ii build/examples/hello.ii
<file>.ii- preprocessed C++ headers and translation units.<file>.bc- LLVM IR bitcode handed to the optimizer.<file>.s- target assembly emitted by codegen, equivalent to generated machine code in.ofiles.
This is useful for manually inspecting macro expansion and optimization, among other purposes.
cmake --build build/ --target cat-syntaxCompiles a libCat with -fsyntax-only. This is useful for quickly checking if
code can compile, without bothering to enter deep LLVM. It will reuse existing
precompiled headers, if they are enabled, further accelerating the development loop.
cmake -B build/ -DCAT_BUILD_SHARED=ON
cmake --build build/ --target cat-replLaunches clang-repl with libCat preloaded so its headers and external
linkage symbols resolve at JIT time. The wrapper reads the matching compile flags
from the build’s compile_commands.json so the REPL parses the same C++26 / freestanding
/ SIMD-intrinsic dialect libCat was built against, and pre-loads the ASan runtime when
sanitizers are on.
For scripted use, the wrapper script also accepts a one-shot --eval /
--eval-file flag that runs the supplied snippets and exits, e.g.
./build/clang-repl-libcat --eval \
'#include <cat/string>
auto _ = cat::println("Meow world!");'
# Meow world!Piping code on stdin works the same way
echo "1 + 1" | ./build/clang-repl-libcat
# 2Note this requires CAT_BUILD_SHARED=ON. Pass extra clang-repl arguments at the
end of the command, after a --.
This target does not require manual invocation. CMake symlinks a .gdbinit
configuration that loads GDB pretty printers from gdb_pretty_printers/cat_printers.py
to every CMake build directory automatically, granted that the user’s GDB is configured
with set auto-load local-gdbinit on.
All build options are CMake cache variables; pass them with -D at configure time.
CAT_PCH(defaultON) - Enable precompiled headers for libCat’s internal build. Private to libCat; downstream consumers ofcatkeep their own PCH strategy intact whether this is on or off.CAT_USE_SCCACHE(default:ONifsccacheis onPATH, elseOFF) Use sccache as the C++ compiler launcher. Combined with-Xclang -fno-pch-timestamp(added automatically for Clang + PCH builds), this gives near-100% hit rates across build directories and fresh checkouts. Override the binary with-DCAT_SCCACHE_EXECUTABLE=/path/to/sccache.
CAT_BUILD_SHARED(defaultOFF) - Also build libCat as a shared library alongside the default static archive. Required for thecat-repltarget. Off by default so the build stays cheap when nobody needs the shared form.CAT_USE_SHARED(defaultOFF) - Linkcatagainst the shared library instead of the static archive, so every in-tree consumer and downstreamfind_package(cat)user that linkscattransparently picks it up. ImpliesCAT_BUILD_SHARED.
CAT_BUILD_UNIT_TESTS(defaultON) - Compile theunit_testsbinary registered withctestasUnitTests.CAT_BUILD_ALL_EXAMPLES(defaultON) - Shortcut that compiles every individual example below.CAT_BUILD_EXAMPLE_HELLO/_ECHO/_CLIENT_SERVER/_WINDOW/_CAT(defaultOFF) - Per-example opt-ins for fine-grained selection whenCAT_BUILD_ALL_EXAMPLES=OFF.CAT_BUILD_LIBC_EXAMPLES(defaultOFF) - Build the libc-linked comparison binaries (hello_libc,memcpy_libc, …) used to A/B performance against the freestanding libCat versions.
CAT_CLANG_FORMAT_PATH- Path to a specificclang-formatbinary (defaults to whatever cmake auto-discovers onPATH). Only consulted by thecat-format/cat-format-checktargets.CAT_CLANG_TIDY_PATH/CAT_RUN_CLANG_TIDY_PATH- Paths to specificclang-tidyandrun-clang-tidybinaries (default to auto-discovery onPATH). Only consulted by thecat-tidy/cat-tidy-checktargets.CAT_SCCACHE_EXECUTABLE- Path to a specificsccachebinary (defaults tofind_programonPATH). Only consulted whenCAT_USE_SCCACHE=ON.