From b2e78d3753b7da3be99dc4f4f88b601f45faba06 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Mar 2026 21:36:25 -1000 Subject: [PATCH] Define CODSPEED_ENABLED globally for benchmark source files benchmark.h uses #ifdef CODSPEED_ENABLED to switch benchmark registration to CodSpeed-instrumented variants. This define was only in library.json (applied to library compilation) but not to the benchmark .cpp files that #include . Without it, CodSpeed reports "No benchmarks found". --- script/cpp_benchmark.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/script/cpp_benchmark.py b/script/cpp_benchmark.py index 3dc6e279b9..ce9a0335fa 100755 --- a/script/cpp_benchmark.py +++ b/script/cpp_benchmark.py @@ -43,9 +43,18 @@ def run_benchmarks(selected_components: list[str], build_only: bool = False) -> # containing {"lib_path": "/path/to/google_benchmark"}. lib_config_json = os.environ.get("BENCHMARK_LIB_CONFIG") + pio_options = PLATFORMIO_OPTIONS if lib_config_json: lib_config = json.loads(lib_config_json) benchmark_lib = f"benchmark=symlink://{lib_config['lib_path']}" + # CODSPEED_ENABLED must be defined globally (not just in library build + # flags) because benchmark.h uses #ifdef CODSPEED_ENABLED to switch + # benchmark registration to CodSpeed-instrumented variants. + pio_options = { + **PLATFORMIO_OPTIONS, + "build_flags": PLATFORMIO_OPTIONS["build_flags"] + + ["-DCODSPEED_ENABLED", "-DCODSPEED_SIMULATION"], + } else: benchmark_lib = PLATFORMIO_GOOGLE_BENCHMARK_LIB @@ -56,7 +65,7 @@ def run_benchmarks(selected_components: list[str], build_only: bool = False) -> config_prefix="cppbench", friendly_name="CPP Benchmarks", libraries=benchmark_lib, - platformio_options=PLATFORMIO_OPTIONS, + platformio_options=pio_options, main_entry="main.cpp", label="benchmarks", build_only=build_only,