codspeed 4.6.0

Core instrumentation library for CodSpeed
Documentation
import re
from pathlib import Path

content = Path("zig-out/lib/core.c").read_text()
print(f"Read zig-out/lib/core.c ({len(content.splitlines())} lines)")

valgrind_wrapper = Path("src/helpers/valgrind_wrapper.c").read_text()
STUB = Path("scripts/stub.c").read_text()

# Zig's C backend mangles struct names (e.g. instrument_hooks_InstrumentHooks__547),
# and there's no way to control this from Zig source. Replace with the stable
# name from core.h so that core.c can be included alongside core.h without
# type conflicts.
REPLACEMENTS = [
    (
        re.compile(r"struct instrument_hooks_InstrumentHooks__\d+"),
        "struct InstrumentHooks",
    ),
]

print("\nPost-processing replacements:")
for pattern, replacement in REPLACEMENTS:
    match = pattern.search(content)
    if not match:
        raise RuntimeError(f"Pattern not found: {pattern.pattern}")
    count = len(pattern.findall(content))
    print(f"  {match.group(0):>50s}  ->  {replacement}  ({count} occurrences)")
    content = pattern.sub(replacement, content)

# Add core.h include at the top of the Zig block so consumers get the
# constants (MARKER_TYPE_*) and inline helpers from core.h automatically.
content = '#include "core.h"\n' + content

TEMPLATE = f"""\
// This file is generated by scripts/release.py
// Do not edit it manually.

// Include compatibility layer for cross-platform support
#include "compat.h"

#if defined(_WIN32) || defined(__APPLE__)
{STUB}
#else
{content}
#endif
{valgrind_wrapper}
"""

Path("dist/core.c").write_text(TEMPLATE)
print(f"\nWrote dist/core.c ({len(TEMPLATE.splitlines())} lines)")