cuprate/constants/build.rs
hinto-janai c817c3b889
Some checks failed
CI / fmt (push) Waiting to run
CI / typo (push) Waiting to run
CI / wasm-32-bit-support (cuprate-epee-encoding) (push) Waiting to run
CI / wasm-32-bit-support (cuprate-fixed-bytes) (push) Waiting to run
CI / wasm-32-bit-support (cuprate-rpc-types) (push) Waiting to run
CI / ci (macos-latest, stable, bash) (push) Waiting to run
CI / ci (ubuntu-latest, stable, bash) (push) Waiting to run
CI / ci (windows-latest, stable-x86_64-pc-windows-gnu, msys2 {0}) (push) Waiting to run
Doc / build (push) Waiting to run
Doc / deploy (push) Blocked by required conditions
Deny / audit (push) Has been cancelled
workspace: Rust 1.84 (#363)
* apply

* ci: use stable rust for rustfmt
2025-01-16 15:43:42 +00:00

30 lines
844 B
Rust

fn main() {
set_commit_env();
}
/// This sets the git `COMMIT` environment variable.
fn set_commit_env() {
const PATH: &str = "../.git/refs/heads/";
println!("cargo:rerun-if-changed={PATH}");
// FIXME: This could also be `std::fs::read({PATH}/{branch})`
// so the machine building doesn't need `git`, although:
// 1. Having `git` as a build dependency is probably ok
// 2. It causes issues on PRs that aren't the `main` branch
let output = std::process::Command::new("git")
.arg("rev-parse")
.arg("HEAD")
.output()
.unwrap();
let commit = std::str::from_utf8(&output.stdout)
.unwrap()
.trim()
.to_lowercase();
// Commit hash should always be 40 bytes long.
assert_eq!(commit.len(), 40);
println!("cargo:rustc-env=COMMIT={commit}");
}