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 is ON if asan is easily found=).
$ 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 auto-discovers an appropriate version of clang-format on PATH,
if one exists. Override its choice=-DCAT_CLANG_FORMAT_PATH=/path/to/clang-format=
at configure time.
$ 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-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.
build/runtime/_start.ii build/string/memset.ii build/string/memset.bc build/string/memset.s build/math/sqrt.ii build/linux/syscall0.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 .o files.
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 out-of-line
implementations (cat::println, syscalls, allocators, β¦) 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-libcatNote 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_INSTALL(defaultOFF) β Generate the install / export rules socmake --install <build>lays out a sysroot that other CMake projects can consume viafind_package(cat)andtarget_link_libraries(my_target cat::cat). Off by default keeps the in-tree dev loop minimal.
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_SCCACHE_EXECUTABLEβ Path to a specificsccachebinary (defaults tofind_programonPATH). Only consulted whenCAT_USE_SCCACHE=ON.