Switch to shadow-rs

Closes #58
This commit is contained in:
Nadja Reitzenstein 2022-05-18 17:01:03 +02:00
parent c435f76d08
commit 25df5bf5b2
6 changed files with 122 additions and 90 deletions

94
Cargo.lock generated
View File

@ -477,6 +477,9 @@ name = "cc"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
dependencies = [
"jobserver",
]
[[package]]
name = "cfg-if"
@ -543,6 +546,26 @@ dependencies = [
"cache-padded",
]
[[package]]
name = "const_format"
version = "0.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0936ffe6d0c8d6a51b3b0a73b2acbe925d786f346cf45bfddc8341d79fb7dc8a"
dependencies = [
"const_format_proc_macros",
]
[[package]]
name = "const_format_proc_macros"
version = "0.2.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef196d5d972878a48da7decb7686eded338b4858fbabeed513d63a7c98b2b82d"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "constant_time_eq"
version = "0.1.5"
@ -820,6 +843,7 @@ dependencies = [
"serde",
"serde_dhall",
"serde_json",
"shadow-rs",
"signal-hook",
"signal-hook-async-std",
"tempfile",
@ -1171,6 +1195,19 @@ dependencies = [
"syn",
]
[[package]]
name = "git2"
version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0155506aab710a86160ddb504a480d2964d7ab5b9e62419be69e0032bc5931c"
dependencies = [
"bitflags",
"libc",
"libgit2-sys",
"log",
"url",
]
[[package]]
name = "glob"
version = "0.3.0"
@ -1291,6 +1328,12 @@ dependencies = [
"syn",
]
[[package]]
name = "is_debug"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06d198e9919d9822d5f7083ba8530e04de87841eaf21ead9af8f2304efd57c89"
[[package]]
name = "itertools"
version = "0.9.0"
@ -1321,6 +1364,15 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]]
name = "jobserver"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa"
dependencies = [
"libc",
]
[[package]]
name = "js-sys"
version = "0.3.56"
@ -1364,6 +1416,30 @@ version = "0.2.120"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad5c14e80759d0939d013e6ca49930e59fc53dd8e5009132f76240c179380c09"
[[package]]
name = "libgit2-sys"
version = "0.13.4+1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0fa6563431ede25f5cc7f6d803c6afbc1c5d3ad3d4925d12c882bf2b526f5d1"
dependencies = [
"cc",
"libc",
"libz-sys",
"pkg-config",
]
[[package]]
name = "libz-sys"
version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92e7e15d7610cce1d9752e137625f14e61a28cd45929b6e12e47b50fe154ee2e"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "lightproc"
version = "0.3.0"
@ -2283,6 +2359,18 @@ dependencies = [
"opaque-debug 0.3.0",
]
[[package]]
name = "shadow-rs"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f47e98e36909e951f4da3908f4475f969bec92a41734dd92e883aaa11c10294b"
dependencies = [
"chrono",
"const_format",
"git2",
"is_debug",
]
[[package]]
name = "sharded-slab"
version = "0.1.4"
@ -2750,6 +2838,12 @@ dependencies = [
"version_check",
]
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version_check"
version = "0.9.4"

View File

@ -103,6 +103,8 @@ async-compat = "0.2.1"
url = "2.2.2"
rustls-native-certs = "0.6.1"
shadow-rs = "0.11"
[dependencies.rsasl]
git = "https://github.com/dequbed/rsasl.git"
rev = "0b5012d0"
@ -113,5 +115,8 @@ features = ["unstable_custom_mechanism", "provider", "registry_static", "plain"]
futures-test = "0.3.16"
tempfile = "3.2"
[build-dependencies]
shadow-rs = "0.11"
[workspace]
members = ["modules/*", "api"]

View File

@ -1,8 +0,0 @@
//! Information extracted from the (build) environment
//!
/// The BFFH version, as an UTF-8 string
///
/// This is of the format "<major>.<minor>.<patch>" if build as a normal release
/// or "<major> .<minor>.<patch>-<commit hash>" if built from source
pub const VERSION: &'static str = env!("BFFHD_VERSION_STRING");

View File

@ -31,7 +31,8 @@ pub mod capnp;
pub mod utils;
pub mod env;
// Store build information in the `env` module.
shadow_rs::shadow!(env);
mod audit;
mod keylog;

View File

@ -11,32 +11,33 @@ fn main() -> anyhow::Result<()> {
// values for the name, description and version are pulled from `Cargo.toml`.
let matches = Command::new(clap::crate_name!())
.version(clap::crate_version!())
.long_version(&*format!("Diflouroborane {version}
\t Implementing API {apiver}",
version=diflouroborane::env::VERSION,
apiver="0.3")
)
.long_version(&*format!("{version}\n\
FabAccess {apiver}\n\
\t[{build_kind} build built on {build_time}]\n\
\t {rustc_version}\n\t {cargo_version}",
version=diflouroborane::env::PKG_VERSION,
apiver="0.3",
rustc_version=diflouroborane::env::RUST_VERSION,
cargo_version=diflouroborane::env::CARGO_VERSION,
build_time=diflouroborane::env::BUILD_TIME_3339,
build_kind=diflouroborane::env::BUILD_RUST_CHANNEL))
.about(clap::crate_description!())
.arg(
Arg::new("config")
.arg(Arg::new("config")
.help("Path to the config file to use")
.long("config")
.short('c')
.takes_value(true),
)
.takes_value(true))
.arg(Arg::new("verbosity")
.help("Increase logging verbosity")
.long("verbose")
.short('v')
.multiple_occurrences(true)
.max_occurrences(3)
.conflicts_with("quiet")
)
.conflicts_with("quiet"))
.arg(Arg::new("quiet")
.help("Decrease logging verbosity")
.long("quiet")
.conflicts_with("verbosity")
)
.conflicts_with("verbosity"))
.arg(Arg::new("log format")
.help("Use an alternative log formatter. Available: Full, Compact, Pretty")
.long("log-format")
@ -50,26 +51,22 @@ fn main() -> anyhow::Result<()> {
.arg(
Arg::new("print default")
.help("Print a default config to stdout instead of running")
.long("print-default"),
)
.long("print-default"))
.arg(
Arg::new("check config")
.help("Check config for validity")
.long("check"),
)
.long("check"))
.arg(
Arg::new("dump")
.help("Dump all internal databases")
.long("dump")
.conflicts_with("load"),
)
.conflicts_with("load"))
.arg(
Arg::new("load")
.help("Load values into the internal databases")
.long("load")
.takes_value(true)
.conflicts_with("dump"),
)
.conflicts_with("dump"))
.arg(Arg::new("keylog")
.help("log TLS keys into PATH. If no path is specified the value of the envvar SSLKEYLOGFILE is used.")
.long("tls-key-log")
@ -77,8 +74,7 @@ fn main() -> anyhow::Result<()> {
.takes_value(true)
.max_values(1)
.min_values(0)
.default_missing_value("")
)
.default_missing_value(""))
.get_matches();
let configpath = matches

View File

@ -1,60 +1,4 @@
use std::process::Command;
fn main() {
println!(">>> Building version number...");
let rustc = std::env::var("RUSTC").unwrap();
let out = Command::new(rustc)
.arg("--version")
.output()
.expect("failed to run `rustc --version`");
let rustc_version =
String::from_utf8(out.stdout).expect("rustc --version returned invalid UTF-8");
let rustc_version = rustc_version.trim();
println!("cargo:rustc-env=CARGO_RUSTC_VERSION={}", rustc_version);
println!("cargo:rerun-if-env-changed=BFFHD_BUILD_TAGGED_RELEASE");
let tagged_release = option_env!("BFFHD_BUILD_TAGGED_RELEASE") == Some("1");
let version_string = if tagged_release {
format!(
"{version} [{rustc}]",
version = env!("CARGO_PKG_VERSION"),
rustc = rustc_version
)
} else {
// Build version number using the current git commit id
let out = Command::new("git")
.arg("rev-list")
.args(["HEAD", "-1"])
.output()
.expect("failed to run `git rev-list HEAD -1`");
let owned_gitrev =
String::from_utf8(out.stdout).expect("git rev-list output was not valid UTF8");
let gitrev = owned_gitrev.trim();
let abbrev = match gitrev.len() {
0 => "badsource",
_ => &gitrev[0..9],
};
let out = Command::new("git")
.arg("log")
.args(["-1", "--format=%as"])
.output()
.expect("failed to run `git log -1 --format=\"format:%as\"`");
let commit_date = String::from_utf8(out.stdout).expect("git log output was not valid UTF8");
let commit_date = commit_date.trim();
format!(
"{version} ({gitrev} {date}) [{rustc}]",
version = env!("CARGO_PKG_VERSION"),
gitrev = abbrev,
date = commit_date,
rustc = rustc_version
)
};
println!("cargo:rustc-env=BFFHD_VERSION_STRING={}", version_string);
println!(
"cargo:rustc-env=BFFHD_RELEASE_STRING=\"BFFH {}\"",
version_string
);
// Extract build-time information using the `shadow-rs` crate
shadow_rs::new();
}