Isolate volatile build provenance from shared configuration (#33687)
### Description
<!-- Describe your changes. -->
Move `ORT_BUILD_INFO` from the widely included generated
`onnxruntime_config.h` into a private generated
`onnxruntime_build_info.h`. Explicitly include it in all four existing
consumers: the C API, inference Python bindings, training Python
bindings, and CUDA GEMM tactic cache.
String construction is unchanged: Git branch/commit, existing capability
flags (including INT4/FP8/FP4 settings), and build type retain their
existing semantics. No public API, dependency, kernel, or operator
changes.
### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
A real Git commit changes build provenance at the next configure.
Putting that value in the shared feature-config header invalidates
unrelated objects, even when feature flags and compiler commands are
unchanged. Keeping it private limits that invalidation to code that
actually reports or consumes build identity.
Based on current main `123752d361d2da8ff592b347772f31362e0966bd`;
signed-off head `3bb32435737be91ea76805473a2a27ea95a0e352`.
### Validation
Fresh isolated Linux x86-64 CPU build; no GPU used. Release
configuration with `-O0` to reduce validation compile cost; contrib and
ML operators disabled. Build/test artifacts and isolated Python
environment are under `R=/tmp/ort-build-info-7144cd59`. Commands below
ran from `$R/src`, except the gtest, which ran from `$R/build/Release`.
| Command | Result |
| --- | --- |
| `$R/venv/bin/python tools/ci_build/build.py --build_dir $R/build
--config Release --update --cmake_generator Ninja --build_shared_lib
--enable_pybind --disable_ml_ops --disable_contrib_ops --skip_tests
--compile_no_warning_as_error --cmake_extra_defines
CMAKE_CXX_FLAGS_RELEASE=-O0 CMAKE_C_FLAGS_RELEASE=-O0` | Passed after
installing initially missing NumPy into the isolated environment.
Original and patched generation at the same HEAD reported byte-identical
build-info strings. |
| `cmake --build $R/build/Release --target onnxruntime
onnxruntime_pybind11_state --parallel 4` | Passed: fresh C API/inference
Python build and final-commit incremental rebuild. |
| `cmake --compile-no-warning-as-error -S $R/src/cmake -B
$R/build/Release -Donnxruntime_USE_TELEMETRY=OFF` | Passed before and
after the real main-parent-to-patch commit transition. |
| `cmp $R/controlled-commands-before.txt
$R/controlled-commands-after.txt` | Passed: complete Ninja command lists
for both targets were identical. |
| `g++ $R/get_build_info.cc -I $R/src/include/onnxruntime/core/session
-L $R/build/Release -Wl,-rpath,$R/build/Release -lonnxruntime -o
$R/get_build_info` | Passed: C API probe linked against the newly built
shared library. |
| `$R/venv/bin/python $R/validate_identity.py after` | Passed: exact C
API/Python runtime equality and actual HEAD, unchanged feature-config
content/mtime, updated private header, exactly two recompiled
translation units. |
| `$R/venv/bin/python $R/check_build_info_matrix.py` | Passed all 5
generation cases: ordinary, every existing flag enabled, INT4 without
CUDA, Git unavailable, and minimal-build generation. Each private-header
string matched the original template's string. |
| `cmake --build $R/build/Release --target onnxruntime_shared_lib_test
--parallel 4` | Passed. |
| `./onnxruntime_shared_lib_test
--gtest_filter=CApiTest.get_build_info_string
--gtest_output=xml:$R/get-build-info-test.xml` | Passed: **1 test ran**,
0 failures; XML test count also asserted. |
| `$R/venv/bin/git-clang-format --binary $R/venv/bin/clang-format --diff
9f807084bed8431f7a2734116b4c9322c81a6e6a --
onnxruntime/core/session/onnxruntime_c_api.cc
onnxruntime/python/onnxruntime_pybind_module.cc
orttraining/orttraining/python/orttraining_python_module.cc
onnxruntime/contrib_ops/cuda/llm/gemm_tactic_cache.cc` | Passed with
repository-pinned clang-format 20.1.8: no changes needed. |
| `git diff --check HEAD^ HEAD` | Passed. |
The controlled transition used the actual main parent and actual patch
commit above. The validation clone's source tree was checked against the
real commit; only Git metadata advanced between measurements, with no
fabricated stamps or timestamp manipulation.
| Measured invariant | Result |
| --- | --- |
| Global `onnxruntime_config.h` SHA-256 |
`7050ac14554db17722928ba7cd404c733e622f16729e06746b45844e51812baf`,
unchanged |
| Global header `mtime_ns` | `1793205513366988156`, unchanged |
| Private header | Updated from the real parent identity to the real
patch identity |
| Recompiled translation units | Exactly `onnxruntime_c_api.cc` and
`onnxruntime_pybind_module.cc`; no unrelated ORT or dependency
compilation |
| Complete compiler/linker command-list SHA-256 |
`02dbebafbe13f39254fca0890cb20e957ab7333c2e4b3a48d3334d7b504c770c`,
unchanged |
Both newly built runtimes returned exactly:
```text
ORT Build Info: git-branch=justinchuby-isolate-build-info, git-commit-id=3bb3243, fp8-kv-cache=1, build type=Release
```
Telemetry was disabled consistently on both sides of the measured
transition because its vendored curl independently rewrites
`curl_config.h` on configure, even at unchanged HEAD. The initial
telemetry-enabled build also passed runtime/header invariants and
recompiled only the two expected ORT files, but additionally rebuilt
curl's 192 C files. That unrelated dependency churn is not changed by
this PR.
Training bindings and CUDA tactic-cache include paths were audited
through shared target configuration and CUDA plugin/test targets. Full
training, CUDA, and minimal-runtime builds were not run; the
minimal-build generation case is a CMake string-equivalence check, not a
minimal-runtime execution claim.
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>