1#![allow(clippy::disallowed_methods, reason = "build scripts are exempt")]
 2use std::process::Command;
 3
 4const ZED_MANIFEST: &str = include_str!("../zed/Cargo.toml");
 5
 6fn main() {
 7    let zed_cargo_toml: cargo_toml::Manifest =
 8        toml::from_str(ZED_MANIFEST).expect("failed to parse zed Cargo.toml");
 9    println!(
10        "cargo:rustc-env=ZED_PKG_VERSION={}",
11        zed_cargo_toml.package.unwrap().version.unwrap()
12    );
13    println!(
14        "cargo:rustc-env=TARGET={}",
15        std::env::var("TARGET").unwrap()
16    );
17
18    // Populate git sha environment variable if git is available
19    println!("cargo:rerun-if-changed=../../.git/logs/HEAD");
20    if let Some(output) = Command::new("git")
21        .args(["rev-parse", "HEAD"])
22        .output()
23        .ok()
24        .filter(|output| output.status.success())
25    {
26        let git_sha = String::from_utf8_lossy(&output.stdout);
27        let git_sha = git_sha.trim();
28
29        println!("cargo:rustc-env=ZED_COMMIT_SHA={git_sha}");
30    }
31}