diff options
author | Tim Oram <dev@mitmaro.ca> | 2024-02-11 10:57:35 -0330 |
---|---|---|
committer | Tim Oram <dev@mitmaro.ca> | 2024-02-15 20:27:06 -0330 |
commit | 892d974ad159db33accdea20757299e9a0666cd2 (patch) | |
tree | f821c344e78068176713a515c986e209f3d899f1 /build.rs | |
parent | 88ed84f466200af2c0536d04d85beaff96d165a5 (diff) |
Move core crate into root
Diffstat (limited to 'build.rs')
-rw-r--r-- | build.rs | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -1,3 +1,6 @@ +use std::{env, process}; + +use chrono::{TimeZone, Utc}; use rustc_version::{version_meta, Channel}; fn main() { @@ -5,6 +8,29 @@ fn main() { if let Ok(meta) = version_meta() { if meta.channel == Channel::Nightly { println!("cargo:rustc-cfg=allow_unknown_lints"); + println!("cargo:rustc-cfg=include_nightly_lints"); } } + + // Make the current git hash available to the build + if let Some(rev) = git_revision_hash() { + println!("cargo:rustc-env=GIRT_BUILD_GIT_HASH={rev}"); + } + + // Use provided SOURCE_DATE_EPOCH to make builds reproducible + let build_date = match env::var("SOURCE_DATE_EPOCH") { + Ok(val) => Utc.timestamp_opt(val.parse::<i64>().unwrap(), 0).unwrap(), + Err(_) => Utc::now(), + }; + println!("cargo:rustc-env=GIRT_BUILD_DATE={}", build_date.format("%Y-%m-%d")); +} + +fn git_revision_hash() -> Option<String> { + let result = process::Command::new("git") + .args(["rev-parse", "--short=10", "HEAD"]) + .output(); + result.ok().and_then(|output| { + let v = String::from_utf8_lossy(&output.stdout).trim().to_string(); + if v.is_empty() { None } else { Some(v) } + }) } |