xref: /cloud-hypervisor/build.rs (revision 5e52729453cb62edbe4fb3a4aa24f8cca31e667e)
1 // Copyright © 2020 Intel Corporation
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 
6 #[macro_use(crate_version)]
7 extern crate clap;
8 
9 use std::process::Command;
10 
11 fn main() {
12     let mut version = "v".to_owned() + crate_version!();
13 
14     if let Ok(git_out) = Command::new("git").args(["describe", "--dirty"]).output() {
15         if git_out.status.success() {
16             if let Ok(git_out_str) = String::from_utf8(git_out.stdout) {
17                 version = git_out_str;
18             }
19         }
20     }
21 
22     // This println!() has a special behavior, as it will set the environment
23     // variable BUILT_VERSION, so that it can be reused from the binary.
24     // Particularly, this is used from src/main.rs to display the exact
25     // version.
26     println!("cargo:rustc-env=BUILT_VERSION={version}");
27 }
28