feat(code-rs): add forked workspace and dual build support

This commit is contained in:
James Peter
2025-10-05 04:27:49 +10:00
parent 0029ec4de5
commit c8111bbb03
1066 changed files with 233191 additions and 45 deletions
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "code-version"
version = { workspace = true }
edition = { workspace = true }
build = "build.rs"
[lib]
path = "src/lib.rs"
+15
View File
@@ -0,0 +1,15 @@
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 = std::env::var("CODE_VERSION")
.unwrap_or_else(|_| env!("CARGO_PKG_VERSION").to_string());
// Inject the version as a rustc env so it participates in the compiler
// invocation hash (sccache-friendly) and guarantees a cache miss when
// the version changes.
println!("cargo:rustc-env=CODE_VERSION={}", version);
// Ensure dependent crates rebuild when CODE_VERSION changes even if the
// source graph stays the same.
println!("cargo:rerun-if-env-changed=CODE_VERSION");
}
+14
View File
@@ -0,0 +1,14 @@
// Compile-time embedded version string.
// Prefer the CODE_VERSION provided by CI; fall back to the package
// version for local builds.
pub const CODE_VERSION: &str = {
match option_env!("CODE_VERSION") {
Some(v) => v,
None => env!("CARGO_PKG_VERSION"),
}
};
#[inline]
pub fn version() -> &'static str {
CODE_VERSION
}