1ebd83699SBo Chen // Copyright © 2020 Intel Corporation 2ebd83699SBo Chen // 3ebd83699SBo Chen // SPDX-License-Identifier: Apache-2.0 4ebd83699SBo Chen // 5ebd83699SBo Chen 6ebd83699SBo Chen use std::process::Command; 7ebd83699SBo Chen 8ebd83699SBo Chen fn main() { 99e6301beSWei Liu let mut version = "v".to_owned() + env!("CARGO_PKG_VERSION"); 10559d1840SBo Chen 11f32487f8SRob Bradford if let Ok(git_out) = Command::new("git").args(["describe", "--dirty"]).output() { 12559d1840SBo Chen if git_out.status.success() { 13559d1840SBo Chen if let Ok(git_out_str) = String::from_utf8(git_out.stdout) { 14559d1840SBo Chen version = git_out_str; 15559d1840SBo Chen } 16559d1840SBo Chen } 17559d1840SBo Chen } 18ebd83699SBo Chen 19ebd83699SBo Chen // This println!() has a special behavior, as it will set the environment 20*59012cccSOmer Faruk Bayram // variable BUILD_VERSION, so that it can be reused from the binary. 21ebd83699SBo Chen // Particularly, this is used from src/main.rs to display the exact 22ebd83699SBo Chen // version. 23*59012cccSOmer Faruk Bayram println!("cargo:rustc-env=BUILD_VERSION={version}"); 24ebd83699SBo Chen } 25