Skip to content

Commit

Permalink
Drop vergen dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
danhper committed Aug 4, 2024
1 parent e33ec36 commit b2873f3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 86 deletions.
40 changes: 1 addition & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ indexmap = "2.2.6"
lazy_static = "1.5.0"

[build-dependencies]
vergen = { version = "9.0.0", features = ["build"] }
git2-rs = { version = "0.19.0", package = "git2", default-features = false }
anyhow = { version = "^1.0.0" }
73 changes: 27 additions & 46 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,56 +1,37 @@
use anyhow::Result;
use git2_rs::Repository;
use std::collections::BTreeMap;

use vergen::{AddCustomEntries, CargoRerunIfChanged, CargoWarning, DefaultConfig, Emitter};

#[derive(Default)]
struct VersionEntryBuilder {}

impl AddCustomEntries<&str, String> for VersionEntryBuilder {
fn add_calculated_entries(
&self,
_idempotent: bool,
cargo_rustc_env_map: &mut BTreeMap<&str, String>,
_cargo_rerun_if_changed: &mut CargoRerunIfChanged,
cargo_warning: &mut CargoWarning,
) -> Result<()> {
let repo_dir = std::env::current_dir()?;
let repo = Repository::discover(repo_dir)?;
let ref_head = repo.revparse_single("HEAD")?;
let git_sha_buf = ref_head.short_id()?;
let git_sha = git_sha_buf.as_str();

let pkg_version = std::env::var("CARGO_PKG_VERSION")?;

let mut version = format!("Eclair v{}", pkg_version);

if pkg_version.contains("-dev") {
if let Some(git_short_sha) = git_sha {
version = format!("{} ({})", version, git_short_sha);
} else {
cargo_warning.push("Failed to get git short sha".to_string());
}
}

cargo_rustc_env_map.insert("ECLAIR_VERSION", version);
fn get_eclair_version() -> Result<(String, Vec<String>)> {
let mut warnings = vec![];

Ok(())
}
let repo_dir = std::env::current_dir()?;
let repo = Repository::discover(repo_dir)?;
let ref_head = repo.revparse_single("HEAD")?;
let git_sha_buf = ref_head.short_id()?;
let git_sha = git_sha_buf.as_str();

let pkg_version = std::env::var("CARGO_PKG_VERSION")?;

fn add_default_entries(
&self,
_config: &DefaultConfig,
_cargo_rustc_env_map: &mut BTreeMap<&str, String>,
_cargo_rerun_if_changed: &mut CargoRerunIfChanged,
_cargo_warning: &mut CargoWarning,
) -> Result<()> {
Ok(())
let mut version = format!("Eclair v{}", pkg_version);

if pkg_version.contains("-dev") {
if let Some(git_short_sha) = git_sha {
version = format!("{} ({})", version, git_short_sha);
} else {
warnings.push("Failed to get git short sha".to_string());
}
}
Ok((version, warnings))
}

fn main() -> Result<()> {
Emitter::default()
.add_custom_instructions(&VersionEntryBuilder::default())?
.emit()
let (version, warnings) = get_eclair_version()?;

for warning in warnings {
println!("cargo::warning={}", warning);
}

println!("cargo::rustc-env=ECLAIR_VERSION={}", version);

Ok(())
}

0 comments on commit b2873f3

Please sign in to comment.