// Copyright (C) 2026-2099 The crate authors. // // This program is free software: you can redistribute it and/or modify it // under the terms of the GNU Affero General Public License as published by the // Free Software Foundation, either version 3 of the License, or (at your // option) any later version. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License // for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . use std::env; use std::fs; use std::path::Path; use git2::Repository; fn main() { let oid = { match Repository::open(".") { Ok(repo) => { let head = repo.head().unwrap(); format!("{}", repo.refname_to_id(head.name().unwrap()).unwrap()) } Err(e) => { println!("cargo::warning={}", e); String::new() } } }; let out_dir = env::var_os("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir).join("GIT_COMMIT"); fs::write(&dest_path, oid).unwrap(); println!("cargo::rerun-if-changed=build.rs"); }