build.rs

 1use std::process::Command;
 2
 3const ZED_MANIFEST: &str = include_str!("../zed/Cargo.toml");
 4
 5fn main() {
 6    let zed_cargo_toml: cargo_toml::Manifest =
 7        toml::from_str(ZED_MANIFEST).expect("failed to parse zed Cargo.toml");
 8    println!(
 9        "cargo:rustc-env=ZED_PKG_VERSION={}",
10        zed_cargo_toml.package.unwrap().version.unwrap()
11    );
12    println!(
13        "cargo:rustc-env=TARGET={}",
14        std::env::var("TARGET").unwrap()
15    );
16
17    // If we're building this for nightly, we want to set the ZED_COMMIT_SHA
18    if let Some(release_channel) = std::env::var("ZED_RELEASE_CHANNEL").ok() {
19        if release_channel.as_str() == "nightly" {
20            // Populate git sha environment variable if git is available
21            println!("cargo:rerun-if-changed=../../.git/logs/HEAD");
22            if let Some(output) = Command::new("git")
23                .args(["rev-parse", "HEAD"])
24                .output()
25                .ok()
26                .filter(|output| output.status.success())
27            {
28                let git_sha = String::from_utf8_lossy(&output.stdout);
29                let git_sha = git_sha.trim();
30
31                println!("cargo:rustc-env=ZED_COMMIT_SHA={git_sha}");
32            }
33        }
34    }
35}