Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 1 addition & 211 deletions Cargo.lock

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

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ env_logger = "0.9"
walkdir = "2.3"
itertools = "0.10"

[build-dependencies]
built = { version = "0.4", features = ["git2"] }

[profile.release]
lto = true
37 changes: 22 additions & 15 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
use std::path::{ Path, PathBuf };
use built::Options;
use std::process::Command;

fn main() {
let mut default: Options = Options::default();
let options = default
.set_compiler(true)
.set_cfg(true)
.set_ci(false)
.set_dependencies(false)
.set_git(true)
.set_env(true)
.set_features(true);
let target = std::env::var("TARGET").unwrap_or_else(|_| "unknown".to_string());
let profile = std::env::var("PROFILE").unwrap_or_else(|_| "unknown".to_string());
println!("cargo:rustc-env=BUILD_TARGET={target}");
println!("cargo:rustc-env=BUILD_PROFILE={profile}");

let src: PathBuf = std::env::var("CARGO_MANIFEST_DIR").unwrap().into();
let dst: PathBuf = Path::new(&std::env::var("OUT_DIR").unwrap()).join("built.rs");
let git_commit = Command::new("git")
.args(["describe", "--always", "--dirty"])
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
println!("cargo:rustc-env=BUILD_GIT_COMMIT={git_commit}");

built::write_built_file_with_opts(&options, &src, &dst).expect("Failed to acquire build-time information");
}
let rustc_version = Command::new("rustc")
.arg("--version")
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
println!("cargo:rustc-env=BUILD_RUSTC_VERSION={rustc_version}");
}
16 changes: 5 additions & 11 deletions src/dbg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ use structopt::clap::crate_version;

pub fn dbg_info() -> String {
format!(
"Crate version {}.\nBuilt from commit {} by {} for target {} with profile '{}' and features = {:?}.",
"Crate version {}.\nBuilt from commit {} by {} for target {} with profile '{}'.",
crate_version!(),
built_info::GIT_VERSION.unwrap(),
built_info::RUSTC_VERSION,
built_info::TARGET,
built_info::PROFILE,
built_info::FEATURES
env!("BUILD_GIT_COMMIT"),
env!("BUILD_RUSTC_VERSION"),
env!("BUILD_TARGET"),
env!("BUILD_PROFILE"),
)
}

#[allow(dead_code)]
mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}
Loading