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 <benchmark/benchmark.h>.
Without it, CodSpeed reports "No benchmarks found".
This commit is contained in:
J. Nick Koston
2026-03-16 21:36:25 -10:00
parent 7c95a83c6c
commit b2e78d3753
+10 -1
View File
@@ -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,