Skip to content

Commit

Permalink
Merge pull request #262 from Luap99/backport-build
Browse files Browse the repository at this point in the history
[v1.0.1-rhel] Backport "Drop vergen dependency"
  • Loading branch information
TomSweeneyRedHat committed Mar 24, 2022
2 parents 5810f9f + 6e74215 commit 93af394
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Expand Up @@ -5,7 +5,7 @@
# Main collection of env. vars to set for all tasks and scripts.
env:
# Actual|intended branch for this run
DEST_BRANCH: "main"
DEST_BRANCH: "v1.0.1-rhel"
# The default is 'sh' if unspecified
CIRRUS_SHELL: "/bin/bash"
# Location where source repo. will be cloned
Expand Down
132 changes: 0 additions & 132 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Expand Up @@ -38,5 +38,4 @@ sha2 = "0.10.1"
netlink-packet-route = "0.11"

[build-dependencies]
vergen = { version = "6.0.2", default-features = false, features = ["build", "rustc", "git"] }
anyhow = "1.0"
chrono = "*"
27 changes: 23 additions & 4 deletions build.rs
@@ -1,7 +1,26 @@
use anyhow::Result;
use vergen::{vergen, Config};
use chrono::Utc;
use std::process::Command;

fn main() -> Result<()> {
fn main() {
// Generate the default 'cargo:' instruction output
vergen(Config::default())
println!("cargo:rerun-if-changed=build.rs");

// get timestamp
let now = Utc::now();
println!("cargo:rustc-env=BUILD_TIMESTAMP={}", now.to_rfc3339());

// get rust target triple from TARGET env
println!(
"cargo:rustc-env=BUILD_TARGET={}",
std::env::var("TARGET").unwrap()
);

// get git commit
let command = Command::new("git").args(&["rev-parse", "HEAD"]).output();
let commit = match command {
Ok(output) => String::from_utf8(output.stdout).unwrap(),
// if error, e.g. build from source with git repo, just show empty string
Err(_) => "".to_string(),
};
println!("cargo:rustc-env=GIT_COMMIT={}", commit);
}
8 changes: 4 additions & 4 deletions src/commands/version.rs
Expand Up @@ -17,10 +17,10 @@ struct Info {
impl Version {
pub fn exec(&self) -> Result<(), Box<dyn Error>> {
let info = Info {
version: env!("VERGEN_BUILD_SEMVER"),
commit: env!("VERGEN_GIT_SHA"),
build_time: env!("VERGEN_BUILD_TIMESTAMP"),
target: env!("VERGEN_RUSTC_HOST_TRIPLE"),
version: env!("CARGO_PKG_VERSION"),
commit: env!("GIT_COMMIT"),
build_time: env!("BUILD_TIMESTAMP"),
target: env!("BUILD_TARGET"),
};

let out = serde_json::to_string_pretty(&info)?;
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Expand Up @@ -5,7 +5,7 @@ use netavark::commands::teardown;
use netavark::commands::version;

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

0 comments on commit 93af394

Please sign in to comment.