Skip to content

Commit

Permalink
Add command line option to print build info
Browse files Browse the repository at this point in the history
Like commit sha1, rustc version used to build the app, host and target
triplets, etc.
  • Loading branch information
alcroito committed Jan 3, 2022
1 parent 125086d commit 2e89add
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ jobs:
command: build
args: --release --target=${{ matrix.rust_target_arch }}

- name: Run app with --build-info
uses: actions-rs/cargo@v1
if: matrix.cross == false
with:
use-cross: ${{ matrix.cross }}
command: run
args: --release --target=${{ matrix.rust_target_arch }} -- --build-info

- name: Create staging archive
id: create_staging_archive
uses: ./.github/actions/create_archive
Expand Down
183 changes: 183 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license = "MIT"
keywords = ["dyndns", "digitalocean"]
exclude = ["/ci/*", "/.github/*"]
publish = false
build = "build.rs"

[[bin]]
name = "do_ddns"
Expand All @@ -35,5 +36,9 @@ signal-hook = { version = "0.3", features = ["extended-siginfo"] }
toml = "0.5"
trust-dns-resolver = "0.20"

[build-dependencies]
anyhow = "1.0"
vergen = "6"

[dev-dependencies]
tempfile = "3"
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
* Add support for detecting systemd notify socket to remove timestamp from logs
* Deduplicate `from_x` code in ConfigValueBuilder
* Add systemd sample configuration
* Embed commit SHA1 into help text.
16 changes: 16 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use anyhow::Result;
use vergen::{vergen, Config, SemverKind, TimestampKind};

fn main() -> Result<()> {
let mut config = Config::default();
// Enable build date generation
*config.build_mut().kind_mut() = TimestampKind::All;

// Change the SEMVER output to the lightweight variant
*config.git_mut().semver_kind_mut() = SemverKind::Lightweight;
// Add a `-dirty` flag to the SEMVER output
*config.git_mut().semver_dirty_mut() = Some("-dirty");

// Generate the instructions
vergen(config)
}
62 changes: 62 additions & 0 deletions src/build_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use crate::config_consts::BUILD_INFO;
use clap::ArgMatches;

fn print_build_info() {
println!(
"
Build date: {}
Build timestamp: {}
Build version: {}
Commit SHA: {:?}
Commit timestamp: {:?}
Commit branch: {:?}
Commit SemVer: {:?}
Rust channel: {}
Rust commit date: {}
Rust commit SHA: {}
Rust host triple: {}
Rust llvm version: {}
Rust version: {}
Cargo target triple: {}
Cargo profile: {}
Cargo features: {}
Host platform: {}
Host OS: {}
Host memory: {}
Host CPU: {}
Host CPU core count: {}
Host CPU brand: {}
",
env!("VERGEN_BUILD_DATE"),
env!("VERGEN_BUILD_TIMESTAMP"),
env!("VERGEN_BUILD_SEMVER"),
option_env!("VERGEN_GIT_SHA"),
option_env!("VERGEN_GIT_COMMIT_TIMESTAMP"),
option_env!("VERGEN_GIT_BRANCH"),
option_env!("VERGEN_GIT_SEMVER_LIGHTWEIGHT"),
env!("VERGEN_RUSTC_CHANNEL"),
env!("VERGEN_RUSTC_COMMIT_DATE"),
env!("VERGEN_RUSTC_COMMIT_HASH"),
env!("VERGEN_RUSTC_HOST_TRIPLE"),
env!("VERGEN_RUSTC_LLVM_VERSION"),
env!("VERGEN_RUSTC_SEMVER"),
env!("VERGEN_CARGO_TARGET_TRIPLE"),
env!("VERGEN_CARGO_PROFILE"),
env!("VERGEN_CARGO_FEATURES"),
env!("VERGEN_SYSINFO_NAME"),
env!("VERGEN_SYSINFO_OS_VERSION"),
env!("VERGEN_SYSINFO_TOTAL_MEMORY"),
env!("VERGEN_SYSINFO_CPU_VENDOR"),
env!("VERGEN_SYSINFO_CPU_CORE_COUNT"),
env!("VERGEN_SYSINFO_CPU_BRAND"),
);
}

pub fn print_build_info_if_requested(clap_matches: &ArgMatches<'static>) -> bool {
if clap_matches.is_present(BUILD_INFO) {
print_build_info();
true
} else {
false
}
}
Loading

0 comments on commit 2e89add

Please sign in to comment.