mirror of
https://github.com/hanzoai/dev.git
synced 2026-10-25 03:32:32 +00:00
feat(code-rs): add forked workspace and dual build support
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "code-version"
|
||||
version = { workspace = true }
|
||||
edition = { workspace = true }
|
||||
build = "build.rs"
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user