mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-18 14:48:34 +01:00
build(nix): pull git rev info from flake inputs
This commit adds a new workspace crate, version, which is consumed by komorebi and komorebic. If either of those binaries are being built by the Nix Flake, the git rev info will be pulled from inputs.self.rev instead of querying the git repo, because the git files are not passed to the derivation. The build.rs for the version crate decides if the build is happening by querying the shadow-rs build output for BRANCH, which will always be empty when a "nix build" is running. Cargo builds will use the standard git information retrieval mechanisms in shadow-rs. The information in both cases is exposed as version::LONG_VERSION, and passed to clap as the string to return when either binary is called with the --version flag.
This commit is contained in:
1 parent
909b8b5df0
commit
db8cf858ff
17 files changed
+112
-63
No files matched your search
Generated
+9
@@ -2967,6 +2967,7 @@ dependencies = [
|
||||
"tracing-appender",
|
||||
"tracing-subscriber",
|
||||
"uuid",
|
||||
"version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3050,6 +3051,7 @@ dependencies = [
|
||||
"serde_json_lenient",
|
||||
"shadow-rs",
|
||||
"sysinfo",
|
||||
"version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6479,6 +6481,13 @@ version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"shadow-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "version-compare"
|
||||
version = "0.2.0"
|
||||
|
||||
+7
-1
@@ -1,7 +1,13 @@
|
||||
[workspace]
|
||||
|
||||
resolver = "2"
|
||||
members = ["komorebi", "komorebi-bar", "komorebi-client", "komorebic"]
|
||||
members = [
|
||||
"komorebi",
|
||||
"komorebi-bar",
|
||||
"komorebi-client",
|
||||
"komorebic",
|
||||
"version",
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -62,6 +62,11 @@ crate = "komorebi-themes"
|
||||
expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
[[licenses.clarify]]
|
||||
crate = "version"
|
||||
expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
[[licenses.clarify]]
|
||||
crate = "base16-egui-themes"
|
||||
expression = "MIT"
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
crane,
|
||||
flake-utils,
|
||||
@@ -35,60 +36,50 @@
|
||||
|| (builtins.match ".*/docs/.*" path != null);
|
||||
};
|
||||
|
||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||
|
||||
commonArgs = {
|
||||
inherit src version cargoArtifacts;
|
||||
inherit src version;
|
||||
strictDeps = true;
|
||||
|
||||
COMMIT_HASH = self.rev or (lib.removeSuffix "-dirty" self.dirtyRev);
|
||||
|
||||
buildInputs = [
|
||||
pkgs.gcc
|
||||
pkgs.libiconv
|
||||
];
|
||||
};
|
||||
|
||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||
|
||||
individualCrateArgs =
|
||||
commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
doCheck = false;
|
||||
doDoc = false;
|
||||
};
|
||||
|
||||
packages = {
|
||||
komorebi = craneLib.buildPackage (
|
||||
packages = let
|
||||
fullBuild = craneLib.buildPackage (
|
||||
individualCrateArgs
|
||||
// {
|
||||
inherit version;
|
||||
pname = "komorebi";
|
||||
cargoExtraArgs = "-p komorebi";
|
||||
pname = "komorebi-workspace";
|
||||
}
|
||||
);
|
||||
|
||||
komorebic = craneLib.buildPackage (
|
||||
individualCrateArgs
|
||||
// {
|
||||
inherit version;
|
||||
pname = "komorebic";
|
||||
cargoExtraArgs = "-p komorebic";
|
||||
extractBinary = binaryName:
|
||||
pkgs.runCommand "komorebi-${binaryName}"
|
||||
{
|
||||
meta = fullBuild.meta // {};
|
||||
}
|
||||
);
|
||||
|
||||
komorebi-bar = craneLib.buildPackage (
|
||||
individualCrateArgs
|
||||
// {
|
||||
inherit version;
|
||||
pname = "komorebi-bar";
|
||||
cargoExtraArgs = "-p komorebi-bar";
|
||||
}
|
||||
);
|
||||
|
||||
komorebi-full = craneLib.buildPackage (
|
||||
individualCrateArgs
|
||||
// {
|
||||
inherit version;
|
||||
pname = "komorebi-full";
|
||||
cargoExtraArgs = "-p komorebi -p komorebic -p komorebi-bar";
|
||||
}
|
||||
);
|
||||
''
|
||||
mkdir -p $out/bin
|
||||
cp ${fullBuild}/bin/${binaryName} $out/bin/
|
||||
'';
|
||||
in {
|
||||
komorebi-full = fullBuild;
|
||||
komorebi = extractBinary "komorebi";
|
||||
komorebic = extractBinary "komorebic";
|
||||
komorebi-bar = extractBinary "komorebi-bar";
|
||||
};
|
||||
in
|
||||
packages
|
||||
@@ -108,23 +99,18 @@
|
||||
buildResult = komorebiBuild system;
|
||||
inherit
|
||||
(buildResult)
|
||||
individualCrateArgs
|
||||
komorebi
|
||||
komorebic
|
||||
komorebi-bar
|
||||
komorebi-full
|
||||
pkgs
|
||||
craneLib
|
||||
commonArgs
|
||||
src
|
||||
;
|
||||
in {
|
||||
checks = {
|
||||
komorebi-workspace-clippy = craneLib.cargoClippy (
|
||||
commonArgs
|
||||
// {
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
}
|
||||
);
|
||||
komorebi-workspace-clippy = craneLib.cargoClippy individualCrateArgs;
|
||||
|
||||
komorebi-workspace-fmt = craneLib.cargoFmt {
|
||||
inherit src;
|
||||
@@ -138,7 +124,7 @@
|
||||
inherit src;
|
||||
};
|
||||
|
||||
komorebi-workspace-nextest = craneLib.cargoNextest commonArgs;
|
||||
komorebi-workspace-nextest = craneLib.cargoNextest individualCrateArgs;
|
||||
};
|
||||
|
||||
packages = {
|
||||
|
||||
@@ -4,6 +4,7 @@ fmt:
|
||||
test -z "$(rg 'eyre!' --type rust)" || (echo "eyre! macro not allowed"; false)
|
||||
test -z "$(rg 'dbg!' --type rust)" || (echo "dbg! macro not allowed"; false)
|
||||
test -z "$(rg 'println!' --type rust ./komorebi)" || (echo "println! macro not allowed"; false)
|
||||
taplo fmt Cargo.toml */Cargo.toml
|
||||
cargo +nightly fmt
|
||||
cargo +stable clippy
|
||||
alejandra .
|
||||
@@ -56,4 +57,4 @@ depgen:
|
||||
|
||||
push:
|
||||
git push origin master
|
||||
git push komocorp master
|
||||
git push komocorp master
|
||||
+1
-3
@@ -7,6 +7,7 @@ edition = "2024"
|
||||
[dependencies]
|
||||
komorebi-themes = { workspace = true }
|
||||
quickxml_to_serde = { git = "https://github.com/LGUG2Z/quickxml_to_serde.git", version = "0.6.1" }
|
||||
version = { path = "../version" }
|
||||
|
||||
base64 = "0.21"
|
||||
block2 = "0.6"
|
||||
@@ -50,9 +51,6 @@ tracing = { workspace = true }
|
||||
tracing-appender = { workspace = true }
|
||||
tracing-subscriber = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
shadow-rs = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
use shadow_rs::ShadowBuilder;
|
||||
|
||||
fn main() {
|
||||
ShadowBuilder::builder().build().unwrap();
|
||||
}
|
||||
@@ -149,8 +149,6 @@ lazy_static! {
|
||||
static ref UNMANAGED_WINDOW_IDS: Arc<Mutex<Vec<u32>>> = Arc::new(Mutex::new(vec![]));
|
||||
}
|
||||
|
||||
shadow_rs::shadow!(build);
|
||||
|
||||
pub static DEFAULT_WORKSPACE_PADDING: AtomicI32 = AtomicI32::new(5);
|
||||
pub static DEFAULT_CONTAINER_PADDING: AtomicI32 = AtomicI32::new(5);
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ enum LogLevel {
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(author, about, version = komorebi::build::CLAP_LONG_VERSION)]
|
||||
#[clap(author, about, version = version::LONG_VERSION)]
|
||||
struct Opts {
|
||||
/// Path to a static configuration JSON file
|
||||
#[clap(short, long)]
|
||||
|
||||
@@ -12,7 +12,6 @@ use crate::WORKSPACE_MATCHING_RULES;
|
||||
use crate::accessibility::AccessibilityApi;
|
||||
use crate::application::Application;
|
||||
use crate::border_manager;
|
||||
use crate::build;
|
||||
use crate::cf_array_as;
|
||||
use crate::core::ApplicationIdentifier;
|
||||
use crate::core::MoveBehaviour;
|
||||
@@ -64,6 +63,7 @@ use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
use version::build;
|
||||
|
||||
#[tracing::instrument]
|
||||
pub fn listen_for_commands(wm: Arc<Mutex<WindowManager>>) {
|
||||
|
||||
@@ -6,6 +6,7 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
komorebi-client = { path = "../komorebi-client", default-features = false }
|
||||
version = { path = "../version" }
|
||||
|
||||
clap = { workspace = true }
|
||||
clap_complete = "4"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use shadow_rs::ShadowBuilder;
|
||||
|
||||
fn main() {
|
||||
if std::fs::metadata("applications.json").is_err() {
|
||||
let applications_json = reqwest::blocking::get(
|
||||
@@ -7,6 +5,4 @@ fn main() {
|
||||
).unwrap().text().unwrap();
|
||||
std::fs::write("applications.json", applications_json).unwrap();
|
||||
}
|
||||
|
||||
ShadowBuilder::builder().build().unwrap();
|
||||
}
|
||||
@@ -61,8 +61,6 @@ lazy_static! {
|
||||
.join("komorebi");
|
||||
}
|
||||
|
||||
shadow_rs::shadow!(build);
|
||||
|
||||
#[derive(Copy, Clone, ValueEnum)]
|
||||
enum BooleanState {
|
||||
Enable,
|
||||
@@ -668,7 +666,7 @@ struct Splash {
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(author, about, version = build::CLAP_LONG_VERSION)]
|
||||
#[clap(author, about, version = version::LONG_VERSION)]
|
||||
struct Opts {
|
||||
#[clap(subcommand)]
|
||||
subcmd: SubCommand,
|
||||
|
||||
@@ -8,13 +8,14 @@ with pkgs;
|
||||
buildInputs = [
|
||||
alejandra
|
||||
cargo-deny
|
||||
cargo-udeps
|
||||
cargo-nextest
|
||||
cargo-udeps
|
||||
gcc
|
||||
jq
|
||||
just
|
||||
libiconv
|
||||
prettier
|
||||
taplo
|
||||
|
||||
python311Packages.mkdocs-material
|
||||
python311Packages.mkdocs-macros
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "version"
|
||||
edition = "2024"
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
shadow-rs = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
shadow-rs = { workspace = true }
|
||||
@@ -0,0 +1,42 @@
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
use shadow_rs::SdResult;
|
||||
use shadow_rs::ShadowBuilder;
|
||||
|
||||
fn main() {
|
||||
let is_flake_build = ShadowBuilder::builder()
|
||||
.build()
|
||||
.unwrap()
|
||||
.map
|
||||
.get("BRANCH")
|
||||
.map_or_else(|| true, |entry| entry.v.is_empty());
|
||||
|
||||
if is_flake_build {
|
||||
ShadowBuilder::builder().hook(flake_hook).build().unwrap();
|
||||
} else {
|
||||
ShadowBuilder::builder().hook(raw_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(())
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
shadow_rs::shadow!(build);
|
||||
|
||||
pub use build::LONG_VERSION;
|
||||
Reference in new issue
Block a user