Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
nix: Compile commit hash into program version
Michael Raitza committed 2 years ago
commit 4b1ca18d0ca0f951d926a5c048f0365d740420f1
parent fb13e5f970f7712fe904351ea2812253000d73c6
2 files changed +5 -1
modified build.rs
@@ -1,4 +1,5 @@
use std::process::Command;
+
use std::env;

fn main() {
    // Set a build-time `GIT_HEAD` env var which includes the commit id;
@@ -16,7 +17,7 @@ fn main() {
                None
            }
        })
-
        .unwrap_or_else(|| String::from("unknown"));
+
        .unwrap_or(env::var("GIT_HEAD").unwrap_or("unknown".into()));

    println!("cargo:rustc-env=GIT_HEAD={hash}");
    println!("cargo:rustc-rerun-if-changed=.git/HEAD");
modified flake.nix
@@ -89,6 +89,9 @@
            # Additional darwin specific inputs can be set here
            pkgs.libiconv
          ];
+
        preBuild = lib.optionalString (self.shortRev or null != null) ''
+
          export GIT_HEAD=${self.shortRev}
+
        '';
      };

      # Build *just* the cargo dependencies, so we can reuse