xref: /cloud-hypervisor/build.rs (revision f32487f8e8958be7e7b9e696caa484383fc570bb)
1ebd83699SBo Chen // Copyright © 2020 Intel Corporation
2ebd83699SBo Chen //
3ebd83699SBo Chen // SPDX-License-Identifier: Apache-2.0
4ebd83699SBo Chen //
5ebd83699SBo Chen 
6559d1840SBo Chen #[macro_use(crate_version)]
7559d1840SBo Chen extern crate clap;
8559d1840SBo Chen 
9ebd83699SBo Chen use std::process::Command;
10ebd83699SBo Chen 
11ebd83699SBo Chen fn main() {
12cd1c2ed3SBo Chen     let mut version = "v".to_owned() + crate_version!();
13559d1840SBo Chen 
14*f32487f8SRob Bradford     if let Ok(git_out) = Command::new("git").args(["describe", "--dirty"]).output() {
15559d1840SBo Chen         if git_out.status.success() {
16559d1840SBo Chen             if let Ok(git_out_str) = String::from_utf8(git_out.stdout) {
17559d1840SBo Chen                 version = git_out_str;
18559d1840SBo Chen             }
19559d1840SBo Chen         }
20559d1840SBo Chen     }
21ebd83699SBo Chen 
22ebd83699SBo Chen     // This println!() has a special behavior, as it will set the environment
23ebd83699SBo Chen     // variable BUILT_VERSION, so that it can be reused from the binary.
24ebd83699SBo Chen     // Particularly, this is used from src/main.rs to display the exact
25ebd83699SBo Chen     // version.
26559d1840SBo Chen     println!("cargo:rustc-env=BUILT_VERSION={}", version);
27ebd83699SBo Chen }
28