Expand description
Shared build-script helpers for the codewhale-cli, codewhale-tui, and
codewhale-telemetry build scripts: rerun-condition declarations, the
embedded DEEPSEEK_BUILD_VERSION metadata, and the release-only build sha.
Only call these functions from a build script — they emit cargo:
directives on stdout.
Two different shas live here and they are not interchangeable.
DEEPSEEK_BUILD_VERSION/CODEWHALE_BUILD_COMMIT describe the build the
environment asked for (DEEPSEEK_BUILD_SHA/GITHUB_SHA); an unstamped
local build renders a (dev) marker instead.
CODEWHALE_RELEASE_BUILD_SHA describes a published binary and has no
fallback at all, because it leaves the machine.
§Why the stamp never reads the local checkout (#5245)
These helpers used to watch .git/HEAD/refs and fall back to
git rev-parse HEAD, so every local commit invalidated the two largest
compile units in the workspace (a ~14-minute release rebuild with zero
code changes). And the alternative — resolving the sha at runtime —
would lie: the binary runs inside users’ repositories, and a stale binary
would report whatever the checkout’s HEAD is now, which breaks the
dogfood-receipt identity scripts/release/install-dogfood.sh verifies.
So the contract is: a sha appears in the version string only when the
build environment supplied one (DEEPSEEK_BUILD_SHA wins over
GITHUB_SHA), the build script reruns only when those variables change,
and a build nobody stamped says (dev). CI and release builds are
byte-identical to the old behavior; dogfood builds pass the sha
explicitly (the install script prints the exact command).
Functions§
- declare_
release_ sha_ rerun - Declare the rerun conditions for
emit_release_build_shaalone: the two release-CI SHA variables, and nothing about the local checkout. - declare_
rerun_ conditions - Declare the rerun conditions for the build-metadata directives: the two
SHA-override environment variables, and deliberately nothing about the
local checkout — watching
.gitfiles is what made every local commit rebuild the whole crate (#5245). - emit_
build_ version - Emit
cargo:rustc-env=DEEPSEEK_BUILD_VERSION=...— the package version, suffixed with the short build SHA when the environment supplied one (DEEPSEEK_BUILD_SHA, thenGITHUB_SHA), or with the literaldevmarker when it did not.CODEWHALE_BUILD_COMMITis emitted only in the stamped case. - emit_
release_ build_ sha - Emit
cargo:rustc-env=CODEWHALE_RELEASE_BUILD_SHA=...— the first 12 hex characters of the build sha — only when the build environment supplied one. - release_
build_ sha - The decision behind
emit_release_build_sha, with the environment injected so it can be tested without mutating the process.