xref: /cloud-hypervisor/build.rs (revision ebd83699dcfc0bf9df425a1c619462266411884d)
1*ebd83699SBo Chen // Copyright © 2020 Intel Corporation
2*ebd83699SBo Chen //
3*ebd83699SBo Chen // SPDX-License-Identifier: Apache-2.0
4*ebd83699SBo Chen //
5*ebd83699SBo Chen 
6*ebd83699SBo Chen use std::process::Command;
7*ebd83699SBo Chen 
8*ebd83699SBo Chen fn main() {
9*ebd83699SBo Chen     let git_out = Command::new("git")
10*ebd83699SBo Chen         .args(&["describe", "--dirty"])
11*ebd83699SBo Chen         .output()
12*ebd83699SBo Chen         .expect("Expect to get git describe output");
13*ebd83699SBo Chen 
14*ebd83699SBo Chen     // This println!() has a special behavior, as it will set the environment
15*ebd83699SBo Chen     // variable BUILT_VERSION, so that it can be reused from the binary.
16*ebd83699SBo Chen     // Particularly, this is used from src/main.rs to display the exact
17*ebd83699SBo Chen     // version.
18*ebd83699SBo Chen     println!(
19*ebd83699SBo Chen         "cargo:rustc-env=BUILT_VERSION={}",
20*ebd83699SBo Chen         String::from_utf8(git_out.stdout).unwrap()
21*ebd83699SBo Chen     );
22*ebd83699SBo Chen }
23