Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

1.6 KB
Raw Blame
use std::{fs, path::Path, process::Command};
use vergen_gitcl::{Emitter, Gitcl};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let moli_manifest_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("../moli/Cargo.toml");
    println!("cargo:rerun-if-changed={}", moli_manifest_path.display());
    let moli_manifest: toml::Table = fs::read_to_string(moli_manifest_path)?.parse()?;
    let moli_version = moli_manifest
        .get("package")
        .and_then(|package| package.get("version"))
        .and_then(toml::Value::as_str)
        .ok_or("Moli's package.version must be a string")?;
    println!("cargo:rustc-env=MOLI_VERSION={moli_version}");

    let git = Gitcl::builder().sha(false).build();
    Emitter::default()
        .fail_on_error()
        .add_instructions(&git)?
        .emit()?;

    // vergen-gitcl 10.0.2 resolves `--git-dir` to the per-worktree directory,
    // then looks for the branch ref below it. Linked worktrees keep branch refs
    // in the common Git directory instead, so make that dependency explicit.
    let symbolic_ref = Command::new("git")
        .args(["symbolic-ref", "--quiet", "HEAD"])
        .output()?;
    if symbolic_ref.status.success() {
        let symbolic_ref = String::from_utf8(symbolic_ref.stdout)?;
        let ref_path = Command::new("git")
            .args(["rev-parse", "--git-path", symbolic_ref.trim()])
            .output()?;
        if !ref_path.status.success() {
            return Err("git rev-parse --git-path failed".into());
        }
        println!(
            "cargo:rerun-if-changed={}",
            String::from_utf8(ref_path.stdout)?.trim()
        );
    }
    Ok(())
}