diff --git a/build/logging.rs b/build/logging.rs index 4b228d1e..5184b2db 100644 --- a/build/logging.rs +++ b/build/logging.rs @@ -1,5 +1,30 @@ +use { + crate::open, + std::{fmt::Write as _, io::Write as _, process::Command}, +}; + pub fn main() -> anyhow::Result<()> { + create_bridge()?; + create_version()?; + Ok(()) +} + +fn create_bridge() -> anyhow::Result<()> { println!("cargo:rerun-if-changed=src/bridge.c"); cc::Build::new().file("src/bridge.c").compile("bridge"); Ok(()) } + +fn create_version() -> anyhow::Result<()> { + let mut version_string = env!("CARGO_PKG_VERSION").to_string(); + if let Ok(output) = Command::new("git").arg("rev-parse").arg("HEAD").output() { + if output.status.success() { + if let Ok(commit) = std::str::from_utf8(&output.stdout) { + write!(version_string, " ({})", commit.trim())?; + } + } + } + let mut f = open("version.rs")?; + writeln!(f, "pub const VERSION: &str = \"{}\";", version_string)?; + Ok(()) +} diff --git a/src/compositor.rs b/src/compositor.rs index 98e07650..068f281e 100644 --- a/src/compositor.rs +++ b/src/compositor.rs @@ -38,6 +38,7 @@ use { oserror::OsError, queue::AsyncQueue, refcounted::RefCounted, run_toplevel::RunToplevel, tri::Try, }, + version::VERSION, video::drm::wait_for_sync_obj::WaitForSyncObj, wheel::{Wheel, WheelError}, xkbcommon::XkbContext, @@ -122,6 +123,7 @@ fn start_compositor2( test_future: Option, ) -> Result<(), CompositorError> { log::info!("pid = {}", uapi::getpid()); + log::info!("version = {VERSION}"); init_fd_limit(); leaks::init(); clientmem::init()?; diff --git a/src/main.rs b/src/main.rs index e22cbc93..bdd39264 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,6 +87,7 @@ mod tree; mod udev; mod user_session; mod utils; +mod version; mod video; mod wheel; mod wire; diff --git a/src/portal.rs b/src/portal.rs index dc86725a..e196c9fb 100644 --- a/src/portal.rs +++ b/src/portal.rs @@ -31,6 +31,7 @@ use { run_toplevel::RunToplevel, xrd::xrd, }, + version::VERSION, video::dmabuf::DmaBufIds, wheel::Wheel, wire_dbus::org, @@ -226,6 +227,7 @@ async fn init_dbus_session(dbus: &Dbus, logger: Arc) -> Rc { Ok(r) if r.get().rv == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER => { log::info!("Acquired unique name {}", UNIQUE_NAME); logger.redirect("portal"); + log::info!("version = {VERSION}"); let fork = match fork_with_pidfd(false) { Ok(f) => f, Err(e) => fatal!("Could not fork: {}", ErrorFmt(e)), diff --git a/src/version.rs b/src/version.rs new file mode 100644 index 00000000..1a10d703 --- /dev/null +++ b/src/version.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/version.rs"));