Zig library that compiles to a single-file C library (dist/core.c) for controlling CodSpeed instrumentations via IPC. Consumed as FFI by integrations in multiple languages (Python, Rust, C/C++, etc.).
zig build # Build (outputs zig-out/lib/core.linux.c, zig-out/lib/core.macos.c)
zig build test --summary all # Run tests
just release # Build + generate dist/core.c
just cmake-run-example # Build and run the C example via CMake
just bazel-run-example # Build and run the C example via Bazel
just test-valgrind # Compile example with gcc/clang and run under valgrind
just fmt # Format Zig sourceRequires Zig 0.14+. Optional: Just for convenience commands.
src/c.zig— C FFI export layer. All public API functions are defined here withpub export fn.src/instrument_hooks.zig— MainInstrumentHooksstruct combining all subsystems.src/instruments/root.zig— Instrumentation backend union (valgrind, walltime, analysis, none). Fallback chain: valgrind (Linux only) > analysis > walltime > none.src/instruments/{valgrind,walltime,analysis}.zig— Individual backends.walltimesubscribes to theIntegrationMode.Walltimerunner mode (covers any walltime profiler: perf, Instruments, etc.).src/runner_fifo.zig— IPC protocol with the CodSpeed runner via named pipes.src/fifo/— Low-level pipe reader/writer with bincode serialization.root.zigdispatches bybuiltin.os.tagtoposix.zig(Linux + macOS, mkfifo) orwindows.zig(stub returningerror.Unsupported; real Win32 named-pipe port pending).src/shared.zig— Protocol types (Commandunion,MarkerType, version).src/bincode.zig— Bincode binary serialization (port of qbradley/bincode-zig).src/environment/root.zig— Key-value integration/toolchain metadata and linked library collection, serialized to JSON.src/environment/linked_libraries/root.zig— Collects metadata about dynamically linked libraries (path, soname, build ID, verdef).src/environment/linked_libraries/elf_view.zig— Read-only ELF navigation helper for parsing in-memory program headers (PT_DYNAMIC, PT_NOTE, DT_VERDEF). Portable across all Linux architectures.src/environment/linked_libraries/testdata/test_lib.c— Minimal C source compiled into a test fixture.sobybuild.zig. Linked into the test binary so it appears indl_iterate_phdrfor ElfView tests.src/features.zig— Runtime feature flags (bit set).src/logger.zig— Simple leveled logging via Cprintf.src/utils.zig— Low-level utilities (sleepwith Windows/POSIX branches,printvia Cprintf). The monotonic-clock implementation lives directly insrc/c.zigwith per-OS branches (Linuxclock_gettime, macOS Mach time, Windows returns 0).src/root.zig— Test runner entry point (imports all modules for testing).
includes/core.h— Manually maintained C API header. Must be updated when adding/removing exported functions.includes/compat.h— Cross-platform compatibility macros.includes/valgrind.h,includes/callgrind.h— Valgrind client request headers.dist/core.c— Generated single-file C library with three branches: Linux (#else) and macOS (#elif defined(__APPLE__)) get the full Zig-transpiled implementation; Windows (#if defined(_WIN32)) gets hand-written stubs fromscripts/stub.c.scripts/release.py— Readszig-out/lib/core.linux.candzig-out/lib/core.macos.c, applies post-processing (struct-name unmangling), and stitches them together withscripts/stub.cand the valgrind wrapper intodist/core.c.scripts/stub.c— Hand-written Windows-only stubs. Must be updated when adding exported functions until the Zig source compiles for windows targets, after which this file can be dropped.
Communication with the CodSpeed runner happens over two named pipes (POSIX FIFOs on Linux/macOS):
/tmp/runner.ctl.fifo— Commands (hooks -> runner)/tmp/runner.ack.fifo— Acknowledgments (runner -> hooks)
Messages use bincode serialization with [u32 length][payload] framing. Protocol version: 2.
IntegrationMode (negotiated via Command.GetIntegrationMode/IntegrationModeResponse):
Walltime— any walltime profiler (perf on Linux, Instruments on macOS, etc.).Simulation— runner-side simulation.Analysis— analysis pass.
Wire format uses ordinal positions, so renaming variants in Zig is safe as long as ordering stays in sync with runner_shared on the Rust side.
- Implement the logic in the appropriate module.
- Add the
pub export fnwrapper insrc/c.zig. Returnu8status codes (0 = success, non-zero = error). - Add the declaration in
includes/core.h. - Add a stub in
scripts/stub.c. - Run
just releaseto regeneratedist/core.c.
- Zig code is formatted with
zig fmt. - C/C++ code follows Google style (
.clang-format), pointer-left alignment. - Pre-commit hooks enforce formatting and build checks.
- Error handling at FFI boundary: return
u8(0 = ok, 1 = error). Never panic in release builds (std.debug.no_panic). - Memory:
std.heap.c_allocatorin production,std.testing.allocatorin tests. - Hot paths (FIFO read/write) use pre-allocated buffers to avoid allocations.
- Tests live alongside the code in each
.zigfile. src/root.zigimports all modules to run all tests.build.zigcompiles a test fixture shared library (libtest_fixture.so) fromsrc/environment/linked_libraries/testdata/test_lib.cand links it into the test binary. ElfView tests usedl_iterate_phdrto find it at runtime — no file parsing, same code path as production.- CI tests across multiple platforms (Linux x86/ARM, macOS, Windows), compiler versions (GCC 9-15, Clang 13-19), and cross-compilation targets.
Follow conventional commits. Reference Linear issues when applicable (inferred from branch name).