chore(repo): a workspace of two crates

komorebi for KDE is built up as a Cargo workspace with one crate per concern,
the way komorebi and komorebi for Mac are. The first two crates are the
`komorebi` daemon, which does nothing yet but report its version, and `version`,
which owns the string every binary of the workspace reports.

`version` reads the commit from git when HEAD is on a branch, and from
COMMIT_HASH otherwise. A jj workspace leaves HEAD detached, so
`.cargo/config.toml` defaults the variable to `unknown` (nix will set the real
commit), and a plain `cargo build` in a jj checkout compiles.

The tooling files come from komorebi for Mac: the licence, deny.toml (trimmed to
the licences in use), rustfmt.toml and the toolchain file. `just check` runs the
formatting check, clippy and rustdoc with warnings denied, and the tests.
rustfmt.toml uses an unstable option, so formatting needs a nightly rustfmt. The
`rg` calls in `just lint` name a path because rg reads stdin when it is given
none and stdin is not a terminal.

The README and CONTRIBUTING.md say how to run, check and commit.
This commit is contained in:
LGUG2Z committed 2026-10-27 09:11:36 -07:00
commit 426409fcfc
17 files changed
+1443

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
[package]
name = "version"
edition = "2024"
version.workspace = true
[dependencies]
shadow-rs = { workspace = true }
[build-dependencies]
shadow-rs = { workspace = true }
+40
View File
@@ -0,0 +1,40 @@
use std::fs::File;
use std::io::Write;
use shadow_rs::SdResult;
use shadow_rs::ShadowBuilder;
fn main() {
let shadow_build = ShadowBuilder::builder().hook(raw_hook).build().unwrap();
let is_flake_build = shadow_build
.map
.get("BRANCH")
.map_or_else(|| true, |entry| entry.v.is_empty());
if is_flake_build {
ShadowBuilder::builder().hook(flake_hook).build().unwrap();
}
}
const RAW_VERSION_CONST: &str = r##"pub const LONG_VERSION:&str = shadow_rs::formatcp!(r#"{}
branch:{}
commit_hash:{}
build_env:{},{}"#,PKG_VERSION, BRANCH, COMMIT_HASH, RUST_VERSION, RUST_CHANNEL
);
"##;
fn raw_hook(mut file: &File) -> SdResult<()> {
writeln!(file, "{RAW_VERSION_CONST}")?;
Ok(())
}
const FLAKE_VERSION_CONST: &str = r##"pub const LONG_VERSION:&str = shadow_rs::formatcp!(r#"{}
commit_hash:{}
build_env:{},{}"#,PKG_VERSION, env!("COMMIT_HASH"), RUST_VERSION, RUST_CHANNEL
);"##;
fn flake_hook(mut file: &File) -> SdResult<()> {
writeln!(file, "{FLAKE_VERSION_CONST}")?;
Ok(())
}
+33
View File
@@ -0,0 +1,33 @@
//! The version string every komorebi binary reports.
//!
//! [`LONG_VERSION`] is the package version followed by the commit the binary
//! was built from and the Rust toolchain that built it. The binaries pass it to
//! their command line parsers, so `komorebi --version` and
//! `komorebic --version` report the same thing.
//!
//! # Where the commit comes from
//!
//! A build from a git checkout whose `HEAD` is on a branch asks git for the
//! branch and the commit. Any other build has nothing to ask: a detached `HEAD`
//! (which is what a jj workspace leaves), a source tree with no `.git`
//! directory, or a sandboxed nix build. Such a build reads the commit from the
//! `COMMIT_HASH` environment variable, and does not compile without it.
//! [`.cargo/config.toml`](https://github.com/LGUG2Z/komorebi-for-kde/blob/master/.cargo/config.toml)
//! defaults the variable to `unknown`, and nix sets it to the real commit.
shadow_rs::shadow!(build);
/// The package version, the commit and the toolchain of this build, one per
/// line.
///
/// The first line is the package version, which every crate in the workspace
/// shares.
///
/// # Example
///
/// ```rust
/// let first_line = version::LONG_VERSION.lines().next();
///
/// assert_eq!(first_line, Some(env!("CARGO_PKG_VERSION")));
/// ```
pub use build::LONG_VERSION;