Skip to content

fix: resolve relative __FILE__ against the compiler's directory - #58

Draft
lvaroqui wants to merge 1 commit into
mainfrom
fix/resolve-relative-file-against-compile-dir
Draft

lvaroqui wants to merge 1 commit into
mainfrom
fix/resolve-relative-file-against-compile-dir

Conversation

@lvaroqui

Copy link
Copy Markdown

Resolves a relative __FILE__ against the directory the compiler ran in, so benchmark URIs stay inside the repository when ccache rewrites paths.

With ccache and base_dir (CCACHE_BASEDIR) set, ccache rewrites the absolute source path CMake passes to the compiler into a path relative to the compiler's working directory. get_path_relative_to_workspace then resolved that relative path against the directory the benchmark runs in, so URIs became ../../../tests/benchmarks/bench.cpp::…. The number of .. also depended on how deep the checkout is.

  • core/CMakeLists.txt adds an INTERFACE definition CODSPEED_COMPILE_DIR to every target that links codspeed: CMAKE_BINARY_DIR with Ninja (which compiles everything from the top build directory), the consuming target's BINARY_DIR otherwise (Makefiles compile from each target's build directory).
  • CUR_FILE (benchmark.h) passes it to get_path_relative_to_workspace, which joins it to a relative path before making it relative to the workspace root.
  • Absolute __FILE__, Bazel, and build systems that don't set the definition behave as before.

Reproduced in Docker (checkout at /home/runner/work/repro/repro, benchmark at tests/benchmarks/bench.cpp, ccache 4.12.3):

Generator Fix __FILE__ URI
Make no ../../../tests/benchmarks/bench.cpp ../../../tests/benchmarks/bench.cpp::BM_sum
Ninja no ../tests/benchmarks/bench.cpp ../tests/benchmarks/bench.cpp::BM_sum
Make yes ../../../tests/benchmarks/bench.cpp tests/benchmarks/bench.cpp::BM_sum
Ninja yes ../tests/benchmarks/bench.cpp tests/benchmarks/bench.cpp::BM_sum

Accepted gaps

  • Only the Makefile and Ninja generators are verified. Visual Studio and Xcode use the BINARY_DIR branch.
  • The URIs of projects built with ccache base_dir change, so their benchmark history restarts.

Refs COD-4223 (the issue also covers fixes in other integrations and the platform, so it stays open)

With ccache and `base_dir` set, `__FILE__` is relative to the directory the
compiler ran in. `get_path_relative_to_workspace` resolved it against the
directory the benchmark runs in instead, so benchmark URIs started with
`../../../` and pointed outside the repository.

CMake now gives every target that links codspeed a `CODSPEED_COMPILE_DIR`
definition: the top build directory with Ninja, the target's build directory
with other generators. `CUR_FILE` passes it to
`get_path_relative_to_workspace`, which joins it to a relative path before
making it relative to the workspace. Absolute paths, Bazel builds and build
systems that don't set the definition behave as before.

Benchmark URIs of projects built with ccache `base_dir` change, so their
history restarts.

Closes COD-4223
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codspeed

codspeed Bot commented Nov 25, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

2 warnings

⚠️ Unable to measure the execution of 40 benchmarks

These benchmarks measured no execution time, so their results are not comparable and count as unchanged. This usually happens when the compiler removes the code under test.

Prevent compiler optimizations

See affected benchmarks

⚠️ 20 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 460 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing fix/resolve-relative-file-against-compile-dir (c6d14b7) with main (493bce0)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant