From 6616d1bfb105a2460155215df115967655bfb333 Mon Sep 17 00:00:00 2001 From: Timon Date: Thu, 15 Jan 2026 11:34:01 +0100 Subject: [PATCH] Desktop: Add commit info to binaries build with Nix (#3635) --- .nix/pkgs/graphite.nix | 15 ++++++++++++- editor/build.rs | 10 +++++---- editor/src/application.rs | 22 +++++++++---------- .../messages/dialog/dialog_message_handler.rs | 3 ++- .../portfolio/portfolio_message_handler.rs | 2 +- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.nix/pkgs/graphite.nix b/.nix/pkgs/graphite.nix index 58261f89..88faec4f 100644 --- a/.nix/pkgs/graphite.nix +++ b/.nix/pkgs/graphite.nix @@ -109,13 +109,20 @@ deps.crane.lib.buildPackage ( } else { } - ); + ) // { + GRAPHITE_GIT_COMMIT_HASH = inputs.self.rev or "unknown"; + GRAPHITE_GIT_COMMIT_DATE = inputs.self.lastModified or "unknown"; + }; postUnpack = '' mkdir ./branding cp -r ${branding}/* ./branding ''; + preBuild = if inputs.self ? rev then '' + export GRAPHITE_GIT_COMMIT_DATE="$(date -u -d "@$GRAPHITE_GIT_COMMIT_DATE" +"%Y-%m-%dT%H:%M:%SZ")" + '' else ""; + installPhase = '' mkdir -p $out/bin cp target/${if dev then "debug" else "release"}/graphite $out/bin/graphite @@ -125,6 +132,12 @@ deps.crane.lib.buildPackage ( mkdir -p $out/share/icons/hicolor/scalable/apps cp ${branding}/app-icons/graphite.svg $out/share/icons/hicolor/scalable/apps/art.graphite.Graphite.svg + mkdir -p $out/share/icons/hicolor/512x512/apps + cp ${branding}/app-icons/graphite-512.png $out/share/icons/hicolor/512x512/apps/art.graphite.Graphite.png + mkdir -p $out/share/icons/hicolor/256x256/apps + cp ${branding}/app-icons/graphite-256.png $out/share/icons/hicolor/256x256/apps/art.graphite.Graphite.png + mkdir -p $out/share/icons/hicolor/128x128/apps + cp ${branding}/app-icons/graphite-128.png $out/share/icons/hicolor/128x128/apps/art.graphite.Graphite.png ''; postFixup = '' diff --git a/editor/build.rs b/editor/build.rs index 8167eb7b..5abbb8a3 100644 --- a/editor/build.rs +++ b/editor/build.rs @@ -18,16 +18,18 @@ fn main() { if !gh.trim().is_empty() { gh.trim().to_string() } else { - git_or_unknown(&["rev-parse", "--abbrev-ref", "HEAD"]) + git(&["rev-parse", "--abbrev-ref", "HEAD"]).unwrap_or_default() } }); // Instruct Cargo to set environment variables for compile time. // They are accessed with the `env!("GRAPHITE_*")` macro in the codebase. - println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_DATE={commit_date}"); - println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_HASH={commit_hash}"); - println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_BRANCH={commit_branch}"); println!("cargo:rustc-env=GRAPHITE_RELEASE_SERIES={GRAPHITE_RELEASE_SERIES}"); + if !commit_branch.is_empty() { + println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_BRANCH={commit_branch}"); + } + println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_HASH={commit_hash}"); + println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_DATE={commit_date}"); } /// Get an environment variable, or if it is not set or empty, use the provided fallback function. Returns a string with trimmed whitespace. diff --git a/editor/src/application.rs b/editor/src/application.rs index e3c7c24d..34016c2f 100644 --- a/editor/src/application.rs +++ b/editor/src/application.rs @@ -39,19 +39,17 @@ impl Default for Editor { } pub const GRAPHITE_RELEASE_SERIES: &str = env!("GRAPHITE_RELEASE_SERIES"); -pub const GRAPHITE_GIT_COMMIT_DATE: &str = env!("GRAPHITE_GIT_COMMIT_DATE"); +pub const GRAPHITE_GIT_COMMIT_BRANCH: Option<&str> = option_env!("GRAPHITE_GIT_COMMIT_BRANCH"); pub const GRAPHITE_GIT_COMMIT_HASH: &str = env!("GRAPHITE_GIT_COMMIT_HASH"); -pub const GRAPHITE_GIT_COMMIT_BRANCH: &str = env!("GRAPHITE_GIT_COMMIT_BRANCH"); +pub const GRAPHITE_GIT_COMMIT_DATE: &str = env!("GRAPHITE_GIT_COMMIT_DATE"); pub fn commit_info_localized(localized_commit_date: &str) -> String { - format!( - "Release Series: {}\n\ - Branch: {}\n\ - Commit: {}\n\ - {}", - GRAPHITE_RELEASE_SERIES, - GRAPHITE_GIT_COMMIT_BRANCH, - GRAPHITE_GIT_COMMIT_HASH.get(..8).unwrap_or(GRAPHITE_GIT_COMMIT_HASH), - localized_commit_date - ) + let mut info = String::new(); + info.push_str(&format!("Release Series: {GRAPHITE_RELEASE_SERIES}\n")); + if let Some(branch) = GRAPHITE_GIT_COMMIT_BRANCH { + info.push_str(&format!("Branch: {branch}\n")); + } + info.push_str(&format!("Commit: {}\n", GRAPHITE_GIT_COMMIT_HASH.get(..8).unwrap_or(GRAPHITE_GIT_COMMIT_HASH))); + info.push_str(localized_commit_date); + info } diff --git a/editor/src/messages/dialog/dialog_message_handler.rs b/editor/src/messages/dialog/dialog_message_handler.rs index 59a57aff..7c1188a6 100644 --- a/editor/src/messages/dialog/dialog_message_handler.rs +++ b/editor/src/messages/dialog/dialog_message_handler.rs @@ -1,4 +1,5 @@ use super::simple_dialogs::{self, AboutGraphiteDialog, DemoArtworkDialog, LicensesDialog}; +use crate::application::GRAPHITE_GIT_COMMIT_DATE; use crate::messages::dialog::simple_dialogs::LicensesThirdPartyDialog; use crate::messages::layout::utility_types::widget_prelude::*; use crate::messages::prelude::*; @@ -48,7 +49,7 @@ impl MessageHandler> for DialogMessageHa } DialogMessage::RequestAboutGraphiteDialog => { responses.add(FrontendMessage::TriggerAboutGraphiteLocalizedCommitDate { - commit_date: env!("GRAPHITE_GIT_COMMIT_DATE").into(), + commit_date: GRAPHITE_GIT_COMMIT_DATE.into(), }); } DialogMessage::RequestAboutGraphiteDialogWithLocalizedCommitDate { diff --git a/editor/src/messages/portfolio/portfolio_message_handler.rs b/editor/src/messages/portfolio/portfolio_message_handler.rs index 7c25c694..2a704f49 100644 --- a/editor/src/messages/portfolio/portfolio_message_handler.rs +++ b/editor/src/messages/portfolio/portfolio_message_handler.rs @@ -964,7 +964,7 @@ impl MessageHandler> for Portfolio } PortfolioMessage::RequestStatusBarInfoLayout => { #[cfg(not(target_family = "wasm"))] - let widgets = vec![TextLabel::new("Graphite (beta) 1.0.0-RC2").disabled(true).widget_instance()]; + let widgets = vec![TextLabel::new("Graphite 1.0.0-RC2").disabled(true).widget_instance()]; #[cfg(target_family = "wasm")] let widgets = vec![];