feat(versioning): embed display version via tiny crate and remove dependence on CODE_VERSION env

- Generate  at build time from  (CI) or  (local)
- Replace all version lookups in CLI, TUI banners, exec output, MCP client/server, and core headers with
- Ensures sccache invalidates correctly when version changes, preventing stale binaries (e.g., 0.2.59 inside 0.2.62)

Validation: ./build-fast.sh passes with no warnings.
This commit is contained in:
James Peter
2025-09-05 22:27:34 +10:00
parent eeb8670ff0
commit 32f18333d5
3 changed files with 41 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "codex-version"
version = { workspace = true }
edition = { workspace = true }
build = "build.rs"
[lib]
path = "src/lib.rs"
+24
View File
@@ -0,0 +1,24 @@
use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
// Prefer an explicit CODE_VERSION provided by CI; fall back to the
// crate's package version to keep local builds sane.
let version = env::var("CODE_VERSION").unwrap_or_else(|_| env!("CARGO_PKG_VERSION").to_string());
// Emit a small Rust source file that bakes the version into the crate's
// compiled inputs so that cache systems like sccache invalidate when the
// version changes.
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR is set by Cargo"));
let dst = out_dir.join("code_version.rs");
// Use inlined formatting to avoid warnings per repo policy.
let contents = format!("pub const CODE_VERSION: &str = \"{}\";\n", version);
fs::write(&dst, contents).expect("write code_version.rs");
// Ensure dependent crates rebuild when CODE_VERSION changes even if the
// source graph stays the same.
println!("cargo:rerun-if-env-changed=CODE_VERSION");
}
+9
View File
@@ -0,0 +1,9 @@
// Generated at build time via build.rs; contains:
// pub const CODE_VERSION: &str = "x.y.z";
include!(concat!(env!("OUT_DIR"), "/code_version.rs"));
#[inline]
pub fn version() -> &'static str {
CODE_VERSION
}