OXYGENHUB
◆ main spectra / build.rs
1.2 KiB · Rust · last changed Project skeleton in Oxygen's shape: workspace, deps/oxygen pinned, make check, version, deps-check (#1) 2 days ago source blame history raw
1
//! The build's identity, for `spectra --version`: `SPECTRA_BUILD` when a release or
2
//! an install sets it (from `oxy describe` in this checkout), else the heads a Flow job is
3
//! building, else "local build".
4
fn main() {
5
    println!("cargo:rerun-if-env-changed=SPECTRA_BUILD");
6
    // The heads name the build only when SPECTRA_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("SPECTRA_BUILD").is_ok_and(|b| !b.trim().is_empty()) {
9
        println!("cargo:rerun-if-env-changed=FLOW_HEADS");
10
    }
11
    let build = std::env::var("SPECTRA_BUILD")
12
        .ok()
13
        .map(|b| b.trim().to_string())
14
        .filter(|b| !b.is_empty())
15
        .or_else(|| {
16
            std::env::var("FLOW_HEADS")
17
                .ok()
18
                .and_then(|h| h.split('+').next().map(|x| format!("flow #{}", &x[..12.min(x.len())])))
19
                .filter(|b| b.len() > "flow #".len())
20
        })
21
        .unwrap_or_else(|| "local build".into());
22
    println!("cargo:rustc-env=SPECTRA_BUILD_ID={build}");
23
    println!("cargo:rustc-env=SPECTRA_VERSION_LONG={} ({build})", std::env::var("CARGO_PKG_VERSION").unwrap());
24
}