From 09dedcec2fc79f8ebac3a1fc58f15ee008978235 Mon Sep 17 00:00:00 2001 From: Andreas Neuhaus Date: Sat, 10 Aug 2024 22:41:32 +0200 Subject: [PATCH] Show git short sha on splash screen --- firmware/Cargo.lock | 177 ++++++++++++++++++++++++++++++++++++++++ firmware/Cargo.toml | 3 + firmware/build.rs | 24 ++++++ firmware/src/display.rs | 9 +- 4 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 firmware/build.rs diff --git a/firmware/Cargo.lock b/firmware/Cargo.lock index 93db100..c47c1dc 100644 --- a/firmware/Cargo.lock +++ b/firmware/Cargo.lock @@ -83,6 +83,16 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "cc" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "504bdec147f2cc13c8b57ed9401fd8a147cc66b67ad5cb241394244f2c947549" +dependencies = [ + "jobserver", + "libc", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -640,6 +650,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "fugit" version = "0.3.7" @@ -682,6 +701,21 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d758ba1b47b00caf47f24925c0074ecb20d6dfcffe7f6d53395c0465674841a" +[[package]] +name = "git2" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724" +dependencies = [ + "bitflags", + "libc", + "libgit2-sys", + "log", + "openssl-probe", + "openssl-sys", + "url", +] + [[package]] name = "hash32" version = "0.3.1" @@ -726,6 +760,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indexmap" version = "2.3.0" @@ -736,18 +780,73 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "libgit2-sys" +version = "0.17.0+1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10472326a8a6477c3c20a64547b0059e4b0d086869eee31e6d7da728a8eb7224" +dependencies = [ + "cc", + "libc", + "libssh2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", +] + [[package]] name = "libm" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libssh2-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dc8a030b787e2119a731f1951d6a773e2280c660f8ec4b0f5e1505a386e71ee" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "libz-sys" +version = "1.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c15da26e5af7e25c90b37a2d75cdbf940cf4a55316de9d84c679c9b8bfabf82e" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linked_list_allocator" version = "0.10.5" @@ -831,12 +930,36 @@ dependencies = [ "autocfg", ] +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "paste" version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "pin-project-lite" version = "0.2.14" @@ -849,6 +972,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + [[package]] name = "portable-atomic" version = "1.7.0" @@ -1129,6 +1258,21 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "toml" version = "0.8.19" @@ -1205,23 +1349,56 @@ dependencies = [ "esp-hal-embassy", "esp-println", "esp-wifi", + "git2", "log", "ssd1306", "static_cell", ] +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "vcell" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" +[[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.5" diff --git a/firmware/Cargo.toml b/firmware/Cargo.toml index ade1e50..aecb5d3 100644 --- a/firmware/Cargo.toml +++ b/firmware/Cargo.toml @@ -34,6 +34,9 @@ lto = "fat" opt-level = "s" overflow-checks = false +[build-dependencies] +git2 = "0.19" + [dependencies] display-interface = "0.5" embassy-executor = { version = "0.5", features = ["log"] } diff --git a/firmware/build.rs b/firmware/build.rs new file mode 100644 index 0000000..76f88dd --- /dev/null +++ b/firmware/build.rs @@ -0,0 +1,24 @@ +use core::str; +use git2::{Repository, StatusOptions}; +use std::{env, error::Error}; + +fn main() -> Result<(), Box> { + // In contrast to git describe, we don't want to show a tag name, but always the short sha and + // dirty status as a useful addition to the version number in CARGO_PKG_VERSION. + let repo = Repository::discover(env::var("CARGO_MANIFEST_DIR")?)?; + let head_obj = repo.revparse_single("HEAD")?; + let short_sha_buf = head_obj.short_id()?; + let short_sha = str::from_utf8(&short_sha_buf)?; + let mut status_options = StatusOptions::default(); + // let _ = status_options.include_untracked(true); + let statuses = repo.statuses(Some(&mut status_options))?; + let dirty = statuses.iter().any(|st| !st.status().is_ignored()); + let dirty_str = if dirty { "+" } else { "" }; + println!("cargo::rustc-env=GIT_SHORT_SHA={}{}", short_sha, dirty_str); + + println!("cargo::rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=.git/"); + println!("cargo::rerun-if-changed=.git/HEAD"); + + Ok(()) +} diff --git a/firmware/src/display.rs b/firmware/src/display.rs index bd9d524..751b4b7 100644 --- a/firmware/src/display.rs +++ b/firmware/src/display.rs @@ -1,4 +1,4 @@ -use embedded_graphics::mono_font::ascii::{FONT_10X20, FONT_6X10, FONT_9X18_BOLD}; +use embedded_graphics::mono_font::ascii::{FONT_10X20, FONT_5X8, FONT_6X10, FONT_9X18_BOLD}; use embedded_graphics::mono_font::MonoTextStyle; use embedded_graphics::pixelcolor::BinaryColor; use embedded_graphics::prelude::*; @@ -65,6 +65,13 @@ impl Display { Alignment::Center, ) .draw(&mut self.driver)?; + Text::with_alignment( + env!("GIT_SHORT_SHA"), + Point::new(127, 63), + MonoTextStyle::new(&FONT_5X8, BinaryColor::On), + Alignment::Right, + ) + .draw(&mut self.driver)?; self.driver.flush()?; Ok(()) }