OXYGENHUB
◆ v0.9.11 oxygenhub / crates / hub / build.rs
1.2 KiB · Rust · last changed ci: one build identity for CI states, so cached targets stay fresh (refs andymccall/oxygenflow#52) 23 days ago source blame history raw
e9bfea8e Andy McCall ↶ 1
//! The build's identity, for the version it reports: `OXY_BUILD` when a release or
2
//! an install sets it (from `oxy describe`), else the heads a Flow job is
3
//! building, else "local build".
4
fn main() {
5
    println!("cargo:rerun-if-env-changed=OXY_BUILD");
3a01077d Andy McCall ↶ 6
    // The heads name the build only when OXY_BUILD does not: a CI job that
7
    // sets it stays fresh from one state to the next (oxygenflow#52).
8
    if !std::env::var("OXY_BUILD").is_ok_and(|b| !b.trim().is_empty()) {
9
        println!("cargo:rerun-if-env-changed=FLOW_HEADS");
10
    }
745d225d Andy McCall ↶ 11
    // The migrations `sqlx::migrate!` embeds.
12
    println!("cargo:rerun-if-changed=migrations");
e9bfea8e Andy McCall ↶ 13
    let build = std::env::var("OXY_BUILD")
14
        .ok()
15
        .map(|b| b.trim().to_string())
16
        .filter(|b| !b.is_empty())
17
        .or_else(|| {
18
            std::env::var("FLOW_HEADS")
19
                .ok()
20
                .and_then(|h| h.split('+').next().map(|x| format!("flow #{}", &x[..12.min(x.len())])))
21
                .filter(|b| b.len() > "flow #".len())
22
        })
23
        .unwrap_or_else(|| "local build".into());
24
    println!("cargo:rustc-env=OXY_BUILD_ID={build}");
25
    println!("cargo:rustc-env=OXY_VERSION_LONG={} ({build})", std::env::var("CARGO_PKG_VERSION").unwrap());
26
}