Skip to content

Commit

Permalink
nix: send the Git date to build.rs
Browse files Browse the repository at this point in the history
Thanks to @thoughtpolice for providing the original version of the nix code; I
edited it a bit.
  • Loading branch information
ilyagr committed Oct 27, 2023
1 parent 2c43031 commit 745dd71
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
17 changes: 12 additions & 5 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,18 @@ fn timestamp_to_date(ts_str: &str) -> Option<DateTime<Utc>> {

/// Return the UTC committer date (maybe) and the git hash
fn get_git_timestamp_and_hash() -> Option<(Option<DateTime<Utc>>, String)> {
if let Some(nix_hash) = std::env::var("NIX_JJ_GIT_HASH")
.ok()
.filter(|s| !s.is_empty())
{
return Some((None, nix_hash));
if let (Ok(nix_hash), maybe_nix_timestamp) = (
std::env::var("NIX_JJ_GIT_HASH"),
std::env::var("NIX_JJ_GIT_TIMESTAMP"),
) {
if !nix_hash.is_empty() {
return Some((
maybe_nix_timestamp
.ok()
.and_then(|ts_str| timestamp_to_date(&ts_str)),
nix_hash,
));
}
}

fn parse_timestamp_vbar_hash(bytes: &[u8]) -> (Option<DateTime<Utc>>, String) {
Expand Down
10 changes: 9 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
} //
(flake-utils.lib.eachDefaultSystem (system:
let
# TODO(aseipp): Use dirtyRev and dirtyShortRev to record dirty checkout
# when we update `build.rs` to understand dirty checkouts.
gitRev = self.rev or "";
gitTimestamp = self.lastModified or "";

pkgs = import nixpkgs {
inherit system;
overlays = [
Expand Down Expand Up @@ -76,7 +81,8 @@

ZSTD_SYS_USE_PKG_CONFIG = "1";
LIBSSH2_SYS_USE_PKG_CONFIG = "1";
NIX_JJ_GIT_HASH = self.rev or "";
NIX_JJ_GIT_HASH = gitRev;
NIX_JJ_GIT_TIMESTAMP = gitTimestamp;
CARGO_INCREMENTAL = "0";

preCheck = "export RUST_BACKTRACE=1";
Expand Down Expand Up @@ -132,6 +138,8 @@
export RUST_BACKTRACE=1
export ZSTD_SYS_USE_PKG_CONFIG=1
export LIBSSH2_SYS_USE_PKG_CONFIG=1
export NIX_JJ_GIT_HASH="${gitRev}"
export NIX_JJ_GIT_TIMESTAMP="${gitTimestamp};
'';
};
}));
Expand Down

0 comments on commit 745dd71

Please sign in to comment.