bazel: embed git version via workspace stamping#9586
bazel: embed git version via workspace stamping#9586maliberty merged 4 commits intoThe-OpenROAD-Project:masterfrom
Conversation
Use Bazel's --workspace_status_command mechanism to populate OPENROAD_VERSION and OPENROAD_GIT_DESCRIBE in the Version.hh header. With the default --nostamp (dev builds) STABLE_GIT_VERSION is empty, so the genrule output is deterministic and the Bazel cache is never invalidated on commits. With --stamp (or --config=release) the script runs `git describe` and embeds the real version string, e.g. 26Q1-1485-g51d4ea27c3, without requiring a full rebuild. Usage: # Development build (cache-safe, version shows "bazel-nostamp"): bazel build //... # Release build (real git version embedded, e.g. "26Q1-1485-g51d4ea27c3"): bazel build --config=release //:openroad # Check the embedded version at runtime: ./bazel-bin/openroad -version Fixes The-OpenROAD-Project#7140. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a good mechanism for embedding Git version information into the build using Bazel's workspace stamping feature. The implementation is sound and addresses the goal of having cache-safe development builds while embedding real version info for release builds. I have a couple of suggestions to improve the shell scripts for better readability and maintainability.
|
clang-tidy review says "All clean, LGTM! 👍" |
1 similar comment
|
clang-tidy review says "All clean, LGTM! 👍" |
|
@oharboe seems to work when I tried it. Seems like the version tag gets duplicated. Otherwise it works |
- Change stamp = True to stamp = -1 so the genrule only stamps with --config=release (--stamp), not on every build. This keeps dev builds deterministic and cache-safe. - Set OPENROAD_GIT_DESCRIBE to empty string instead of duplicating OPENROAD_VERSION (which caused "26Q1-... 26Q1-..." in the banner). - Remove OPENROAD_GIT_DESCRIBE from OPENROAD_DEFINES to avoid macro redefinition with the genrule-generated Version.hh. - Document version stamping in Bazel.md and Build.md. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
1 similar comment
|
clang-tidy review says "All clean, LGTM! 👍" |
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
|
@oharboe gave it a spin, it seems to work when I try it: |
|
I tried it with and without |
|
@maliberty pr-merge works, pr-head fails(CI problem, I presume). manual merge? |
|
@oharboe it seems it's an rmp test that is failing, so unrelated to these changes, I would think a manual merge would be needed and that test reviewed (@maliberty ) log copied in here: |
|
Question for the Bazel pros: will a .o built without stamping still generate a cache hit in a build with stamping or are they considered too different? I'm wondering if a single cache can be mostly shared between the modes (aside from the stamp itself and the final binary). |
Claude thinks this is what is needed: |
Use Bazel's --workspace_status_command mechanism to populate OPENROAD_VERSION and OPENROAD_GIT_DESCRIBE in the Version.hh header.
With the default --nostamp (dev builds) STABLE_GIT_VERSION is empty, so the genrule output is deterministic and the Bazel cache is never invalidated on commits. With --stamp (or --config=release) the script runs
git describeand embeds the real version string, e.g. 26Q1-1485-g51d4ea27c3, without requiring a full rebuild.Usage:
Development build (cache-safe, version shows "bazel-nostamp"):
bazel build //...
Release build (real git version embedded, e.g. "26Q1-1485-g51d4ea27c3"):
bazel build --config=release //:openroad
Check the embedded version at runtime:
./bazel-bin/openroad -version
Fixes #7140.