diff --git a/Cargo.lock b/Cargo.lock
index 1080e631f..4177fb488 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1752,9 +1752,9 @@ dependencies = [
[[package]]
name = "once_cell"
-version = "1.17.2"
+version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b"
+checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "open"
diff --git a/VERSION b/VERSION
new file mode 100644
index 000000000..b10244299
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+2023.1-alpha1
diff --git a/assets/halloy.appdata.xml b/assets/halloy.appdata.xml
index 5ccdedcac..e8ab36818 100644
--- a/assets/halloy.appdata.xml
+++ b/assets/halloy.appdata.xml
@@ -30,6 +30,6 @@
The Squidowl Development Team
-
+
diff --git a/data/build.rs b/data/build.rs
new file mode 100644
index 000000000..b013712a1
--- /dev/null
+++ b/data/build.rs
@@ -0,0 +1,51 @@
+use std::path::Path;
+use std::process::Command;
+
+const VERSION: &str = include_str!("../VERSION");
+
+fn main() {
+ let git_hash = Command::new("git")
+ .args(["describe", "--always", "--dirty", "--exclude='*'"])
+ .output()
+ .ok()
+ .filter(|output| output.status.success())
+ .and_then(|x| String::from_utf8(x.stdout).ok());
+
+ println!("cargo:rerun-if-changed=../VERSION");
+ println!("cargo:rustc-env=VERSION={}", VERSION);
+
+ if let Some(hash) = git_hash.as_ref() {
+ println!("cargo:rustc-env=GIT_HASH={}", hash);
+ }
+
+ if git_hash.is_none() {
+ return;
+ }
+
+ let Some(git_dir): Option = Command::new("git")
+ .args(["rev-parse", "--git-dir"])
+ .output()
+ .ok()
+ .filter(|output| output.status.success())
+ .and_then(|x| String::from_utf8(x.stdout).ok())
+ else{ return; };
+ // If heads starts pointing at something else (different branch)
+ // we need to return
+ let head = Path::new(&git_dir).join("HEAD");
+ if head.exists() {
+ println!("cargo:rerun-if-changed={}", head.display());
+ }
+ // if the thing head points to (branch) itself changes
+ // we need to return
+ let Some(head_ref): Option = Command::new("git")
+ .args(["symbolic-ref", "HEAD"])
+ .output()
+ .ok()
+ .filter(|output| output.status.success())
+ .and_then(|x| String::from_utf8(x.stdout).ok())
+ else{ return; };
+ let head_ref = Path::new(&git_dir).join(head_ref);
+ if head_ref.exists() {
+ println!("cargo:rerun-if-changed={}", head_ref.display());
+ }
+}
diff --git a/data/src/environment.rs b/data/src/environment.rs
index 0811930c5..fa27a2dc3 100644
--- a/data/src/environment.rs
+++ b/data/src/environment.rs
@@ -1,7 +1,18 @@
use std::env;
use std::path::{Path, PathBuf};
-pub fn config_dir() -> Option {
+pub const VERSION: &str = env!("VERSION");
+pub const GIT_HASH: Option<&str> = option_env!("GIT_HASH");
+
+pub fn formatted_version() -> String {
+ let hash = GIT_HASH
+ .map(|hash| format!(" ({hash})"))
+ .unwrap_or_default();
+
+ format!("{}{hash}", VERSION)
+}
+
+pub(crate) fn config_dir() -> Option {
// HOST_* checked first for flatpak
#[cfg(target_os = "linux")]
{
@@ -18,7 +29,7 @@ pub fn config_dir() -> Option {
}
}
-pub fn data_dir() -> Option {
+pub(crate) fn data_dir() -> Option {
// HOST_* checked first for flatpak
#[cfg(target_os = "linux")]
{
diff --git a/data/src/lib.rs b/data/src/lib.rs
index eb90e67f1..61f636c48 100644
--- a/data/src/lib.rs
+++ b/data/src/lib.rs
@@ -15,7 +15,7 @@ pub mod client;
pub mod command;
mod compression;
pub mod config;
-mod environment;
+pub mod environment;
pub mod history;
pub mod input;
pub mod log;
diff --git a/src/main.rs b/src/main.rs
index 41dcdd8bc..35fd386d6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,6 +10,8 @@ mod screen;
mod theme;
mod widget;
+use std::env;
+
use data::config::{self, Config};
use data::stream;
use iced::widget::container;
@@ -21,16 +23,31 @@ use self::screen::dashboard;
pub use self::theme::Theme;
use self::widget::Element;
-pub const VERSION: &str = env!("CARGO_PKG_VERSION");
-
pub fn main() -> iced::Result {
+ let mut args = env::args();
+ args.next();
+
+ let version = args
+ .next()
+ .map(|s| s == "--version" || s == "-V")
+ .unwrap_or_default();
+
+ if version {
+ println!("halloy {}", data::environment::formatted_version());
+
+ return Ok(());
+ }
+
#[cfg(debug_assertions)]
let is_debug = true;
#[cfg(not(debug_assertions))]
let is_debug = false;
logger::setup(is_debug).expect("setup logging");
- log::info!("application ({}) has started", VERSION);
+ log::info!(
+ "halloy {} has started",
+ data::environment::formatted_version()
+ );
if let Err(error) = Halloy::run(settings()) {
log::error!("{}", error.to_string());