Skip to content

Commit 3a0d696

Browse files
Merge pull request #254 from Luap99/build
Drop vergen dependency
2 parents 2e95ae3 + bdaef37 commit 3a0d696

File tree

5 files changed

+29
-143
lines changed

5 files changed

+29
-143
lines changed

Cargo.lock

Lines changed: 0 additions & 132 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,4 @@ sha2 = "0.10.1"
3838
netlink-packet-route = "0.11"
3939

4040
[build-dependencies]
41-
vergen = { version = "6.0.2", default-features = false, features = ["build", "rustc", "git"] }
42-
anyhow = "1.0"
41+
chrono = "*"

build.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
use anyhow::Result;
2-
use vergen::{vergen, Config};
1+
use chrono::Utc;
2+
use std::process::Command;
33

4-
fn main() -> Result<()> {
4+
fn main() {
55
// Generate the default 'cargo:' instruction output
6-
vergen(Config::default())
6+
println!("cargo:rerun-if-changed=build.rs");
7+
8+
// get timestamp
9+
let now = Utc::now();
10+
println!("cargo:rustc-env=BUILD_TIMESTAMP={}", now.to_rfc3339());
11+
12+
// get rust target triple from TARGET env
13+
println!(
14+
"cargo:rustc-env=BUILD_TARGET={}",
15+
std::env::var("TARGET").unwrap()
16+
);
17+
18+
// get git commit
19+
let command = Command::new("git").args(&["rev-parse", "HEAD"]).output();
20+
let commit = match command {
21+
Ok(output) => String::from_utf8(output.stdout).unwrap(),
22+
// if error, e.g. build from source with git repo, just show empty string
23+
Err(_) => "".to_string(),
24+
};
25+
println!("cargo:rustc-env=GIT_COMMIT={}", commit);
726
}

src/commands/version.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ struct Info {
1717
impl Version {
1818
pub fn exec(&self) -> Result<(), Box<dyn Error>> {
1919
let info = Info {
20-
version: env!("VERGEN_BUILD_SEMVER"),
21-
commit: env!("VERGEN_GIT_SHA"),
22-
build_time: env!("VERGEN_BUILD_TIMESTAMP"),
23-
target: env!("VERGEN_RUSTC_HOST_TRIPLE"),
20+
version: env!("CARGO_PKG_VERSION"),
21+
commit: env!("GIT_COMMIT"),
22+
build_time: env!("BUILD_TIMESTAMP"),
23+
target: env!("BUILD_TARGET"),
2424
};
2525

2626
let out = serde_json::to_string_pretty(&info)?;

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use netavark::commands::teardown;
55
use netavark::commands::version;
66

77
#[derive(Parser, Debug)]
8-
#[clap(version = env!("VERGEN_BUILD_SEMVER"))]
8+
#[clap(version = env!("CARGO_PKG_VERSION"))]
99
struct Opts {
1010
/// Instead of reading from STDIN, read the configuration to be applied from the given file.
1111
#[clap(short, long)]

0 commit comments

Comments
 (0)