From e892bf7d903d9efb7322f47d93c3ac6be5dd797e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20misaki=20masa?= Date: Sun, 31 May 2026 13:07:11 +0800 Subject: [PATCH] fix: decouple `yazi_boot` crate init from `yazi_term` init (#4011) --- .github/DISCUSSION_TEMPLATE/1-q-a.yml | 6 +- .github/ISSUE_TEMPLATE/bug.yml | 8 +- .github/ISSUE_TEMPLATE/feature.yml | 6 +- Cargo.lock | 91 +++++++++--------- scripts/validate-form/main.js | 4 +- yazi-binding/src/tty.rs | 4 +- yazi-boot/Cargo.toml | 17 ++-- yazi-boot/build.rs | 19 ---- yazi-boot/src/actions/actions.rs | 14 +-- yazi-boot/src/actions/mod.rs | 2 +- yazi-boot/src/actions/rustc.rs | 12 --- yazi-boot/src/actions/triple.rs | 12 --- yazi-boot/src/actions/version.rs | 14 --- yazi-boot/src/args.rs | 8 +- yazi-cli/Cargo.toml | 19 ++-- yazi-cli/build.rs | 11 --- yazi-cli/src/args.rs | 11 +++ .../src/cache/clear.rs | 10 +- yazi-cli/src/cache/mod.rs | 3 + yazi-cli/src/dds/shot.rs | 6 +- .../debug.rs => yazi-cli/src/env/env.rs | 94 +++++++++---------- yazi-cli/src/env/mod.rs | 3 + yazi-cli/src/main.rs | 28 ++++-- yazi-dds/Cargo.toml | 4 +- yazi-dds/build.rs | 13 --- yazi-dds/src/ember/hey.rs | 4 +- yazi-dds/src/ember/hi.rs | 6 +- yazi-fm/src/main.rs | 14 +-- yazi-runner/Cargo.toml | 2 +- yazi-runner/src/loader/chunk.rs | 2 +- yazi-runner/src/loader/loader.rs | 2 +- yazi-shim/src/mlua/string.rs | 2 +- yazi-term/src/event/keyboard.rs | 20 ++-- yazi-version/Cargo.toml | 16 ++++ yazi-version/README.md | 5 + yazi-version/build.rs | 25 +++++ yazi-version/src/lib.rs | 27 ++++++ 37 files changed, 285 insertions(+), 259 deletions(-) delete mode 100644 yazi-boot/src/actions/rustc.rs delete mode 100644 yazi-boot/src/actions/triple.rs delete mode 100644 yazi-boot/src/actions/version.rs rename yazi-boot/src/actions/clear_cache.rs => yazi-cli/src/cache/clear.rs (69%) create mode 100644 yazi-cli/src/cache/mod.rs rename yazi-boot/src/actions/debug.rs => yazi-cli/src/env/env.rs (65%) create mode 100644 yazi-cli/src/env/mod.rs delete mode 100644 yazi-dds/build.rs create mode 100644 yazi-version/Cargo.toml create mode 100644 yazi-version/README.md create mode 100644 yazi-version/build.rs create mode 100644 yazi-version/src/lib.rs diff --git a/.github/DISCUSSION_TEMPLATE/1-q-a.yml b/.github/DISCUSSION_TEMPLATE/1-q-a.yml index ab64c16e..394e0cf6 100644 --- a/.github/DISCUSSION_TEMPLATE/1-q-a.yml +++ b/.github/DISCUSSION_TEMPLATE/1-q-a.yml @@ -22,10 +22,10 @@ body: validations: required: true - type: textarea - id: debug + id: env attributes: - label: "`yazi --debug` output" - description: Please run `yazi --debug` and paste the debug information here. + label: "`ya env` output" + description: Run `ya env` and paste the environment information here. render: Shell validations: required: true diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index 8c33c266..157822ba 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -26,10 +26,10 @@ body: validations: required: true - type: textarea - id: debug + id: env attributes: - label: "`yazi --debug` output" - description: Please run `yazi --debug` and paste the debug information here. + label: "`ya env` output" + description: Run `ya env` and paste the environment information here. render: Shell validations: required: true @@ -65,6 +65,6 @@ body: options: - label: I tried the [latest nightly build](https://yazi-rs.github.io/docs/installation#binaries), and the issue is still reproducible required: true - - label: I updated the debug information (`yazi --debug`) input box to the nightly that I tried + - label: I updated the environment information (`ya env`) field to the nightly that I tried required: true - label: I can reproduce it after disabling all custom configs/plugins (`mv ~/.config/yazi ~/.config/yazi-backup`) diff --git a/.github/ISSUE_TEMPLATE/feature.yml b/.github/ISSUE_TEMPLATE/feature.yml index 26ab7706..647f0534 100644 --- a/.github/ISSUE_TEMPLATE/feature.yml +++ b/.github/ISSUE_TEMPLATE/feature.yml @@ -4,10 +4,10 @@ labels: [feature] assignees: [] body: - type: textarea - id: debug + id: env attributes: - label: "`yazi --debug` output" - description: Please run `yazi --debug` and paste the debug information here. + label: "`ya env` output" + description: Run `ya env` and paste the environment information here. render: Shell validations: required: true diff --git a/Cargo.lock b/Cargo.lock index 7478fae3..a8e9faab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -421,7 +421,7 @@ version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ - "generic-array 0.14.9", + "generic-array 0.14.7", ] [[package]] @@ -440,7 +440,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93" dependencies = [ - "generic-array 0.14.9", + "generic-array 0.14.7", ] [[package]] @@ -557,9 +557,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.62" +version = "1.2.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98" +checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f" dependencies = [ "find-msvc-tools", "jobserver", @@ -698,9 +698,9 @@ dependencies = [ [[package]] name = "cmov" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f88a43d011fc4a6876cb7344703e297c71dda42494fee094d5f7c76bf13f746" +checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" [[package]] name = "color_quant" @@ -908,11 +908,11 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" dependencies = [ - "generic-array 0.14.9", + "generic-array 0.14.7", "typenum", ] @@ -1196,7 +1196,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", - "crypto-common 0.1.6", + "crypto-common 0.1.7", ] [[package]] @@ -1637,9 +1637,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.9" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", @@ -1647,11 +1647,11 @@ dependencies = [ [[package]] name = "generic-array" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dab9e9188e97a93276e1fe7b56401b851e2b45a46d045ca658100c1303ada649" +checksum = "c2e55f16dcf0e9c00efbe2e655ffe45fc98e7066b52bc92f8a79e64060a79351" dependencies = [ - "generic-array 0.14.9", + "generic-array 0.14.7", "rustversion", "typenum", ] @@ -1971,7 +1971,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" dependencies = [ "block-padding 0.3.3", - "generic-array 0.14.9", + "generic-array 0.14.7", ] [[package]] @@ -2096,9 +2096,9 @@ dependencies = [ [[package]] name = "kqueue" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac30106d7dce88daf4a3fcb4879ea939476d5074a9b7ddd0fb97fa4bed5596a" +checksum = "273c0752728918e0ac4976f2b275b6fefb9ecd400585dec929419f3844cd87b5" dependencies = [ "kqueue-sys", "libc", @@ -2330,9 +2330,9 @@ dependencies = [ [[package]] name = "mio" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" +checksum = "02bd0af71c67b473010cbbc60715ee815645a4dc942899111f494b4b737d6fda" dependencies = [ "libc", "log", @@ -3619,7 +3619,7 @@ dependencies = [ "elliptic-curve", "enum_dispatch", "futures", - "generic-array 1.4.1", + "generic-array 1.4.3", "getrandom 0.2.17", "ghash", "hex-literal", @@ -4018,9 +4018,9 @@ dependencies = [ [[package]] name = "shlex" -version = "1.3.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" [[package]] name = "signal-hook" @@ -4126,9 +4126,9 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "socket2" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +checksum = "52d1cfed4120b4d927bf7c0f86d2087a4a7d6027c906d9f9d525a80573b9be51" dependencies = [ "libc", "windows-sys 0.61.2", @@ -4750,9 +4750,9 @@ checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c" [[package]] name = "typenum" -version = "1.20.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "ucd-trie" @@ -4836,9 +4836,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.23.1" +version = "1.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddd74a9687298c6858e9b88ec8935ec45d22e8fd5e6394fa1bd4e99a87789c76" +checksum = "d258b83ceec21034727ecee8c382cfa6c3e133699b0742c64571814fb420c9f7" dependencies = [ "atomic", "getrandom 0.4.2", @@ -5730,16 +5730,11 @@ dependencies = [ "clap_complete_nushell", "futures", "hashbrown 0.17.1", - "regex", - "vergen-gitcl", - "yazi-adapter", - "yazi-config", - "yazi-emulator", "yazi-fs", "yazi-macro", "yazi-shared", "yazi-shim", - "yazi-term", + "yazi-version", "yazi-vfs", ] @@ -5761,18 +5756,23 @@ dependencies = [ "clap_complete_fig", "clap_complete_nushell", "hashbrown 0.17.1", + "regex", "serde", "serde_json", "tokio", "toml", "twox-hash", - "vergen-gitcl", + "yazi-adapter", "yazi-boot", + "yazi-config", "yazi-dds", + "yazi-emulator", "yazi-fs", "yazi-macro", "yazi-shared", "yazi-term", + "yazi-tty", + "yazi-version", ] [[package]] @@ -5865,13 +5865,13 @@ dependencies = [ "tokio-stream", "tracing", "uds_windows", - "vergen-gitcl", "yazi-binding", "yazi-boot", "yazi-fs", "yazi-macro", "yazi-shared", "yazi-shim", + "yazi-version", ] [[package]] @@ -6086,13 +6086,13 @@ dependencies = [ "tokio-util", "tracing", "yazi-binding", - "yazi-boot", "yazi-config", "yazi-dds", "yazi-fs", "yazi-macro", "yazi-shared", "yazi-shim", + "yazi-version", ] [[package]] @@ -6231,6 +6231,13 @@ dependencies = [ "yazi-tty", ] +[[package]] +name = "yazi-version" +version = "26.5.6" +dependencies = [ + "vergen-gitcl", +] + [[package]] name = "yazi-vfs" version = "26.5.6" @@ -6299,18 +6306,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.49" +version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bce33a6288fa3f072a8c2c7d0f2fdbb90e28298f0135c1f99b96c3db2efcc60b" +checksum = "3b065d4f0e55f82fae73202e189638116a87c55ab6b8e6c2721e13dd9d854ad1" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.49" +version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fd425244944f4ab65ccff928e7323354c5a018c75838362fdce749dfad2ee1e" +checksum = "0b631b19d36a892ab55420c92dbc83ccd79274f25be714855d3074aa71cab639" dependencies = [ "proc-macro2", "quote", diff --git a/scripts/validate-form/main.js b/scripts/validate-form/main.js index 925b4e16..bd3fddb8 100644 --- a/scripts/validate-form/main.js +++ b/scripts/validate-form/main.js @@ -13,7 +13,7 @@ function bugReportBody(creator, content, hash) { I noticed that you did not correctly follow the issue template. Please ensure that: - The bug can still be reproduced on the [newest nightly build](https://yazi-rs.github.io/docs/installation/#binaries). -- The debug information (\`yazi --debug\`) is updated for the newest nightly. +- The environment info (\`ya env\`) is updated for the newest nightly. - The non-optional items in the checklist are checked. Issues with \`${LABEL_NAME}\` will be marked ready once edited with the proper content, or closed after 2 days of inactivity. @@ -32,7 +32,7 @@ function featureRequestBody(creator, content) { I noticed that you did not correctly follow the issue template. Please ensure that: - The requested feature does not exist in the [newest nightly build](https://yazi-rs.github.io/docs/installation/#binaries). -- The debug information (\`yazi --debug\`) is updated for the newest nightly. +- The environment info (\`ya env\`) is updated for the newest nightly. - The non-optional items in the checklist are checked. Issues with \`${LABEL_NAME}\` will be marked ready once edited with the proper content, or closed after 2 days of inactivity. diff --git a/yazi-binding/src/tty.rs b/yazi-binding/src/tty.rs index 39f52e74..272133f6 100644 --- a/yazi-binding/src/tty.rs +++ b/yazi-binding/src/tty.rs @@ -55,8 +55,8 @@ impl Tty { }; match result { - Ok(()) => true.into_lua_multi(&lua), - Err(e) => (false, Error::Io(e)).into_lua_multi(&lua), + Ok(()) => true.into_lua_multi(lua), + Err(e) => (false, Error::Io(e)).into_lua_multi(lua), } } } diff --git a/yazi-boot/Cargo.toml b/yazi-boot/Cargo.toml index e226fade..4cc27b8e 100644 --- a/yazi-boot/Cargo.toml +++ b/yazi-boot/Cargo.toml @@ -13,21 +13,17 @@ rust-version.workspace = true workspace = true [dependencies] -yazi-adapter = { path = "../yazi-adapter", version = "26.5.6" } -yazi-config = { path = "../yazi-config", version = "26.5.6" } -yazi-emulator = { path = "../yazi-emulator", version = "26.5.6" } -yazi-fs = { path = "../yazi-fs", version = "26.5.6" } -yazi-macro = { path = "../yazi-macro", version = "26.5.6" } -yazi-shared = { path = "../yazi-shared", version = "26.5.6" } -yazi-shim = { path = "../yazi-shim", version = "26.5.6" } -yazi-term = { path = "../yazi-term", version = "26.5.6" } -yazi-vfs = { path = "../yazi-vfs", version = "26.5.6" } +yazi-fs = { path = "../yazi-fs", version = "26.5.6" } +yazi-macro = { path = "../yazi-macro", version = "26.5.6" } +yazi-shared = { path = "../yazi-shared", version = "26.5.6" } +yazi-shim = { path = "../yazi-shim", version = "26.5.6" } +yazi-version = { path = "../yazi-version", version = "26.5.6" } +yazi-vfs = { path = "../yazi-vfs", version = "26.5.6" } # External dependencies clap = { workspace = true } futures = { workspace = true } hashbrown = { workspace = true } -regex = { workspace = true } [build-dependencies] yazi-shared = { path = "../yazi-shared", version = "26.5.6" } @@ -37,4 +33,3 @@ clap = { workspace = true } clap_complete = "4.6.5" clap_complete_fig = "4.5.2" clap_complete_nushell = "4.6.0" -vergen-gitcl = { version = "9.1.0", features = [ "build", "rustc" ] } diff --git a/yazi-boot/build.rs b/yazi-boot/build.rs index 93ea359e..597e6a00 100644 --- a/yazi-boot/build.rs +++ b/yazi-boot/build.rs @@ -5,27 +5,8 @@ use std::{env, error::Error}; use clap::CommandFactory; use clap_complete::{Shell, generate_to}; -use vergen_gitcl::{BuildBuilder, Emitter, GitclBuilder, RustcBuilder}; fn main() -> Result<(), Box> { - Emitter::default() - .add_instructions(&BuildBuilder::default().build_date(true).build()?)? - .add_instructions( - &RustcBuilder::default() - .commit_date(true) - .commit_hash(true) - .host_triple(true) - .semver(true) - .build()?, - )? - .emit()?; - - if env::var_os("YAZI_NO_GITCL").is_none() { - Emitter::default().add_instructions(&GitclBuilder::default().sha(true).build()?)?.emit()?; - } else { - println!("cargo:rustc-env=VERGEN_GIT_SHA=no-gitcl"); - } - if env::var_os("YAZI_GEN_COMPLETIONS").is_none() { return Ok(()); } diff --git a/yazi-boot/src/actions/actions.rs b/yazi-boot/src/actions/actions.rs index d4d120fa..1849be81 100644 --- a/yazi-boot/src/actions/actions.rs +++ b/yazi-boot/src/actions/actions.rs @@ -5,17 +5,17 @@ pub struct Actions; impl Actions { pub(crate) fn act(args: &crate::Args) { if args.debug { - println!("{}", Self::debug().unwrap()); - process::exit(0); - } - - if args.version { - println!("Yazi {}", Self::version()); + println!("`yazi --debug` has been deprecated, use `ya env` instead."); process::exit(0); } if args.clear_cache { - Self::clear_cache(); + println!("`yazi --clear-cache` has been deprecated, use `ya cache clear` instead."); + process::exit(0); + } + + if args.version { + println!("Yazi\n{}", yazi_version::version_full()); process::exit(0); } } diff --git a/yazi-boot/src/actions/mod.rs b/yazi-boot/src/actions/mod.rs index 651f0ab6..239b7755 100644 --- a/yazi-boot/src/actions/mod.rs +++ b/yazi-boot/src/actions/mod.rs @@ -1 +1 @@ -yazi_macro::mod_flat!(actions clear_cache debug rustc triple version); +yazi_macro::mod_flat!(actions); diff --git a/yazi-boot/src/actions/rustc.rs b/yazi-boot/src/actions/rustc.rs deleted file mode 100644 index 834ba6e5..00000000 --- a/yazi-boot/src/actions/rustc.rs +++ /dev/null @@ -1,12 +0,0 @@ -use super::Actions; - -impl Actions { - pub(super) fn rustc() -> String { - format!( - "{} ({} {})", - env!("VERGEN_RUSTC_SEMVER"), - &env!("VERGEN_RUSTC_COMMIT_HASH")[..8], - env!("VERGEN_RUSTC_COMMIT_DATE") - ) - } -} diff --git a/yazi-boot/src/actions/triple.rs b/yazi-boot/src/actions/triple.rs deleted file mode 100644 index 04dafcfc..00000000 --- a/yazi-boot/src/actions/triple.rs +++ /dev/null @@ -1,12 +0,0 @@ -use super::Actions; - -impl Actions { - pub(super) fn triple() -> String { - format!( - "{} ({}-{})", - env!("VERGEN_RUSTC_HOST_TRIPLE"), - std::env::consts::OS, - std::env::consts::ARCH - ) - } -} diff --git a/yazi-boot/src/actions/version.rs b/yazi-boot/src/actions/version.rs deleted file mode 100644 index 84906dac..00000000 --- a/yazi-boot/src/actions/version.rs +++ /dev/null @@ -1,14 +0,0 @@ -use super::Actions; - -impl Actions { - pub fn version() -> &'static str { - concat!( - env!("CARGO_PKG_VERSION"), - " (", - env!("VERGEN_GIT_SHA"), - " ", - env!("VERGEN_BUILD_DATE"), - ")" - ) - } -} diff --git a/yazi-boot/src/args.rs b/yazi-boot/src/args.rs index 76c50936..187de0f5 100644 --- a/yazi-boot/src/args.rs +++ b/yazi-boot/src/args.rs @@ -18,9 +18,9 @@ pub struct Args { #[arg(long)] pub chooser_file: Option, - /// Clear the cache directory + /// Clear the cache directory (deprecated, use `ya cache clear`) #[arg(long)] - pub clear_cache: bool, + pub clear_cache: bool, // TODO: remove /// Use the specified client ID, must be a globally unique number #[arg(long)] @@ -32,9 +32,9 @@ pub struct Args { #[arg(long)] pub remote_events: Option, - /// Print debug information + /// Print debug information (deprecated, use `ya env`) #[arg(long)] - pub debug: bool, + pub debug: bool, // TODO: remove /// Print version #[arg(short = 'V', long)] diff --git a/yazi-cli/Cargo.toml b/yazi-cli/Cargo.toml index 8c628d0f..09e86f9b 100644 --- a/yazi-cli/Cargo.toml +++ b/yazi-cli/Cargo.toml @@ -13,17 +13,23 @@ rust-version.workspace = true workspace = true [dependencies] -yazi-boot = { path = "../yazi-boot", version = "26.5.6" } -yazi-dds = { path = "../yazi-dds", version = "26.5.6" } -yazi-fs = { path = "../yazi-fs", version = "26.5.6" } -yazi-macro = { path = "../yazi-macro", version = "26.5.6" } -yazi-shared = { path = "../yazi-shared", version = "26.5.6" } -yazi-term = { path = "../yazi-term", version = "26.5.6" } +yazi-adapter = { path = "../yazi-adapter", version = "26.5.6" } +yazi-boot = { path = "../yazi-boot", version = "26.5.6" } +yazi-config = { path = "../yazi-config", version = "26.5.6" } +yazi-dds = { path = "../yazi-dds", version = "26.5.6" } +yazi-emulator = { path = "../yazi-emulator", version = "26.5.6" } +yazi-fs = { path = "../yazi-fs", version = "26.5.6" } +yazi-macro = { path = "../yazi-macro", version = "26.5.6" } +yazi-shared = { path = "../yazi-shared", version = "26.5.6" } +yazi-term = { path = "../yazi-term", version = "26.5.6" } +yazi-tty = { path = "../yazi-tty", version = "26.5.6" } +yazi-version = { path = "../yazi-version", version = "26.5.6" } # External dependencies anyhow = { workspace = true } clap = { workspace = true } hashbrown = { workspace = true } +regex = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } @@ -41,7 +47,6 @@ clap_complete_fig = "4.5.2" clap_complete_nushell = "4.6.0" serde = { workspace = true } serde_json = { workspace = true } -vergen-gitcl = { version = "9.1.0", features = [ "build" ] } [[bin]] name = "ya" diff --git a/yazi-cli/build.rs b/yazi-cli/build.rs index 8d596f34..7c5edb0f 100644 --- a/yazi-cli/build.rs +++ b/yazi-cli/build.rs @@ -5,7 +5,6 @@ use std::{env, error::Error}; use clap::CommandFactory; use clap_complete::{Shell, generate_to}; -use vergen_gitcl::{BuildBuilder, Emitter, GitclBuilder}; fn main() -> Result<(), Box> { let manifest = env::var_os("CARGO_MANIFEST_DIR").unwrap().to_string_lossy().replace(r"\", "/"); @@ -21,16 +20,6 @@ fn main() -> Result<(), Box> { } fn generate() -> Result<(), Box> { - Emitter::default() - .add_instructions(&BuildBuilder::default().build_date(true).build()?)? - .emit()?; - - if env::var_os("YAZI_NO_GITCL").is_none() { - Emitter::default().add_instructions(&GitclBuilder::default().sha(true).build()?)?.emit()?; - } else { - println!("cargo:rustc-env=VERGEN_GIT_SHA=no-gitcl"); - } - if env::var_os("YAZI_GEN_COMPLETIONS").is_none() { return Ok(()); } diff --git a/yazi-cli/src/args.rs b/yazi-cli/src/args.rs index 17b75040..de2b5560 100644 --- a/yazi-cli/src/args.rs +++ b/yazi-cli/src/args.rs @@ -32,6 +32,11 @@ pub(super) enum Command { PubTo(CommandPubTo), /// Subscribe to messages from all remote instances. Sub(CommandSub), + /// Manage the cache. + #[command(subcommand)] + Cache(CommandCache), + /// Print environment and configuration information. + Env, } #[derive(clap::Args)] @@ -154,6 +159,12 @@ pub(super) struct CommandSub { pub(super) kinds: String, } +#[derive(Subcommand)] +pub(super) enum CommandCache { + /// Clear the cache directory. + Clear, +} + // --- Macros macro_rules! impl_emit_body { ($name:ident) => { diff --git a/yazi-boot/src/actions/clear_cache.rs b/yazi-cli/src/cache/clear.rs similarity index 69% rename from yazi-boot/src/actions/clear_cache.rs rename to yazi-cli/src/cache/clear.rs index b2c2d488..68348834 100644 --- a/yazi-boot/src/actions/clear_cache.rs +++ b/yazi-cli/src/cache/clear.rs @@ -1,18 +1,20 @@ use yazi_config::YAZI; use yazi_fs::Xdg; -use super::Actions; +use crate::cache::Cache; -impl Actions { - pub(super) fn clear_cache() { +impl Cache { + pub(crate) fn clear() -> anyhow::Result<()> { if YAZI.preview.cache_dir == *Xdg::temp_dir() { println!("Clearing cache directory: \n{:?}", YAZI.preview.cache_dir); - std::fs::remove_dir_all(&YAZI.preview.cache_dir).unwrap(); + std::fs::remove_dir_all(&YAZI.preview.cache_dir)?; } else { println!( "You've changed the default cache directory, for your data's safety, please clear it manually: \n{:?}", YAZI.preview.cache_dir ); } + + Ok(()) } } diff --git a/yazi-cli/src/cache/mod.rs b/yazi-cli/src/cache/mod.rs new file mode 100644 index 00000000..77e6daec --- /dev/null +++ b/yazi-cli/src/cache/mod.rs @@ -0,0 +1,3 @@ +yazi_macro::mod_flat!(clear); + +pub(crate) struct Cache; diff --git a/yazi-cli/src/dds/shot.rs b/yazi-cli/src/dds/shot.rs index ed039ed0..4cd767ae 100644 --- a/yazi-cli/src/dds/shot.rs +++ b/yazi-cli/src/dds/shot.rs @@ -44,10 +44,10 @@ impl Dds { } pub(super) fn ensure_version(version: Option<&str>) -> Result<()> { - if version != Some(EmberHi::version()) { + if version != Some(yazi_version::version()) { bail!( - "Incompatible version (Ya {}, Yazi {}). Restart all `ya` and `yazi` processes if you upgrade either one.", - EmberHi::version(), + "Incompatible version (Ya {}, Yazi {}). Restart all `ya` and `yazi` processes if you upgraded either.", + yazi_version::version(), version.unwrap_or("Unknown") ); } diff --git a/yazi-boot/src/actions/debug.rs b/yazi-cli/src/env/env.rs similarity index 65% rename from yazi-boot/src/actions/debug.rs rename to yazi-cli/src/env/env.rs index 26228335..4144a5b1 100644 --- a/yazi-boot/src/actions/debug.rs +++ b/yazi-cli/src/env/env.rs @@ -1,4 +1,4 @@ -use std::{env, ffi::OsStr, fmt::Write, path::Path}; +use std::{env, ffi::OsStr, fmt::Write, path::Path, process::Command}; use regex::Regex; use yazi_config::{THEME, YAZI}; @@ -7,22 +7,17 @@ use yazi_fs::Xdg; use yazi_shared::timestamp_us; use yazi_term::TERM; -use super::Actions; +use crate::env::Env; -impl Actions { - pub(super) fn debug() -> Result { +impl Env { + pub(crate) fn print() -> Result { let mut s = String::new(); - writeln!(s, "\nYazi")?; - writeln!(s, " Version : {}", Self::version())?; - writeln!(s, " Debug : {}", cfg!(debug_assertions))?; - writeln!(s, " Triple : {}", Self::triple())?; - writeln!(s, " Rustc : {}", Self::rustc())?; + writeln!(s, "Yazi\n{}", Self::yazi_version())?; writeln!(s, " Backtrace: {:?}", env::var_os("RUST_BACKTRACE"))?; - writeln!(s, "\nYa")?; - writeln!(s, " Version: {}", Self::process_output("ya", "--version"))?; + writeln!(s, "\nYa\n{}", yazi_version::version_full())?; - writeln!(s, "\nConfig")?; + writeln!(s, "Config")?; writeln!(s, " Init : {}", Self::config_state("init.lua"))?; writeln!(s, " Yazi : {}", Self::config_state("yazi.toml"))?; writeln!(s, " Keymap : {}", Self::config_state("keymap.toml"))?; @@ -88,47 +83,55 @@ impl Actions { writeln!(s, "\nMultiplexers")?; writeln!(s, " TMUX : {}", yazi_emulator::TMUX)?; - writeln!(s, " tmux version : {}", Self::process_output("tmux", "-V"))?; + writeln!(s, " tmux version : {}", Self::dep_version("tmux", "-V"))?; writeln!(s, " tmux build flags : enable-sixel={}", Mux::tmux_sixel_flag())?; writeln!(s, " ZELLIJ_SESSION_NAME: {:?}", env::var_os("ZELLIJ_SESSION_NAME"))?; - writeln!(s, " Zellij version : {}", Self::process_output("zellij", "--version"))?; + writeln!(s, " Zellij version : {}", Self::dep_version("zellij", "--version"))?; writeln!(s, "\nDependencies")?; #[rustfmt::skip] - writeln!(s, " file : {}", Self::process_output(env::var_os("YAZI_FILE_ONE").unwrap_or("file".into()), "--version"))?; - writeln!(s, " ueberzugpp : {}", Self::process_output("ueberzugpp", "--version"))?; + writeln!(s, " file : {}", Self::dep_version(env::var_os("YAZI_FILE_ONE").unwrap_or("file".into()), "--version"))?; + writeln!(s, " ueberzugpp : {}", Self::dep_version("ueberzugpp", "--version"))?; #[rustfmt::skip] - writeln!(s, " ffmpeg/ffprobe: {} / {}", Self::process_output("ffmpeg", "-version"), Self::process_output("ffprobe", "-version"))?; - writeln!(s, " pdftoppm : {}", Self::process_output("pdftoppm", "--help"))?; - writeln!(s, " magick : {}", Self::process_output("magick", "--version"))?; - writeln!(s, " fzf : {}", Self::process_output("fzf", "--version"))?; + writeln!(s, " ffmpeg/ffprobe: {} / {}", Self::dep_version("ffmpeg", "-version"), Self::dep_version("ffprobe", "-version"))?; + writeln!(s, " pdftoppm : {}", Self::dep_version("pdftoppm", "--help"))?; + writeln!(s, " magick : {}", Self::dep_version("magick", "--version"))?; + writeln!(s, " fzf : {}", Self::dep_version("fzf", "--version"))?; #[rustfmt::skip] - writeln!(s, " fd/fdfind : {} / {}", Self::process_output("fd", "--version"), Self::process_output("fdfind", "--version"))?; - writeln!(s, " rg : {}", Self::process_output("rg", "--version"))?; - writeln!(s, " chafa : {}", Self::process_output("chafa", "--version"))?; - writeln!(s, " zoxide : {}", Self::process_output("zoxide", "--version"))?; + writeln!(s, " fd/fdfind : {} / {}", Self::dep_version("fd", "--version"), Self::dep_version("fdfind", "--version"))?; + writeln!(s, " rg : {}", Self::dep_version("rg", "--version"))?; + writeln!(s, " chafa : {}", Self::dep_version("chafa", "--version"))?; + writeln!(s, " zoxide : {}", Self::dep_version("zoxide", "--version"))?; #[rustfmt::skip] - writeln!(s, " 7zz/7z : {} / {}", Self::process_output("7zz", "i"), Self::process_output("7z", "i"))?; - writeln!(s, " resvg : {}", Self::process_output("resvg", "--version"))?; - writeln!(s, " jq : {}", Self::process_output("jq", "--version"))?; + writeln!(s, " 7zz/7z : {} / {}", Self::dep_version("7zz", "i"), Self::dep_version("7z", "i"))?; + writeln!(s, " resvg : {}", Self::dep_version("resvg", "--version"))?; + writeln!(s, " jq : {}", Self::dep_version("jq", "--version"))?; writeln!(s, "\nClipboard")?; #[rustfmt::skip] - writeln!(s, " wl-copy/paste: {} / {}", Self::process_output("wl-copy", "--version"), Self::process_output("wl-paste", "--version"))?; - writeln!(s, " xclip : {}", Self::process_output("xclip", "-version"))?; - writeln!(s, " xsel : {}", Self::process_output("xsel", "--version"))?; + writeln!(s, " wl-copy/paste: {} / {}", Self::dep_version("wl-copy", "--version"), Self::dep_version("wl-paste", "--version"))?; + writeln!(s, " xclip : {}", Self::dep_version("xclip", "-version"))?; + writeln!(s, " xsel : {}", Self::dep_version("xsel", "--version"))?; writeln!(s, "\nRoutine")?; writeln!(s, " `file -bL --mime-type`: {}", Self::file1_output())?; - writeln!( - s, - "\n\nSee https://yazi-rs.github.io/docs/plugins/overview#debugging on how to enable logging or debug runtime errors." - )?; - Ok(s) } + fn yazi_version() -> String { + match Command::new("yazi").arg("--version").output() { + Ok(out) if out.status.success() => { + let s = if out.stdout.is_empty() { out.stderr } else { out.stdout }; + let s = String::from_utf8_lossy(&s); + let s = s.trim(); + s.strip_prefix("Yazi\n").unwrap_or(s).to_owned() + } + Ok(out) => format!("{:?}, {:?}", out.status, String::from_utf8_lossy(&out.stderr)), + Err(e) => format!("{e}"), + } + } + fn config_state(name: &str) -> String { let p = Xdg::config_dir().join(name); match std::fs::read_to_string(&p) { @@ -139,8 +142,8 @@ impl Actions { } } - fn process_output(name: impl AsRef, arg: impl AsRef) -> String { - match std::process::Command::new(&name).arg(arg).output() { + fn dep_version(name: impl AsRef, arg: &str) -> String { + match Command::new(&name).arg(arg).output() { Ok(out) if out.status.success() => { let line = String::from_utf8_lossy(&if out.stdout.is_empty() { out.stderr } else { out.stdout }) @@ -149,15 +152,12 @@ impl Actions { .next() .unwrap_or_default() .to_owned(); - if name.as_ref() == "ya" { - line.trim_start_matches("Ya ").to_owned() - } else { - Regex::new(r"\d+\.\d+(\.\d+-\d+|\.\d+|\b)") - .unwrap() - .find(&line) - .map(|m| m.as_str().to_owned()) - .unwrap_or(line) - } + + Regex::new(r"\d+\.\d+(\.\d+-\d+|\.\d+|\b)") + .unwrap() + .find(&line) + .map(|m| m.as_str().to_owned()) + .unwrap_or(line) } Ok(out) => format!("{:?}, {:?}", out.status, String::from_utf8_lossy(&out.stderr)), Err(e) => format!("{e}"), @@ -171,7 +171,7 @@ impl Actions { std::fs::File::create_new(&p).map(|mut f| f.write_all(b"Hello, World!")).ok(); let program = env::var_os("YAZI_FILE_ONE").unwrap_or("file".into()); - match std::process::Command::new(program).args(["-bL", "--mime-type"]).arg(&p).output() { + match Command::new(program).args(["-bL", "--mime-type"]).arg(&p).output() { Ok(out) => { String::from_utf8_lossy(&out.stdout).trim().lines().next().unwrap_or_default().to_owned() } diff --git a/yazi-cli/src/env/mod.rs b/yazi-cli/src/env/mod.rs new file mode 100644 index 00000000..055b1aa4 --- /dev/null +++ b/yazi-cli/src/env/mod.rs @@ -0,0 +1,3 @@ +yazi_macro::mod_flat!(env); + +pub(crate) struct Env; diff --git a/yazi-cli/src/main.rs b/yazi-cli/src/main.rs index b971ab9f..df189d6b 100644 --- a/yazi-cli/src/main.rs +++ b/yazi-cli/src/main.rs @@ -1,4 +1,4 @@ -yazi_macro::mod_pub!(dds package shared); +yazi_macro::mod_pub!(cache dds env package shared); yazi_macro::mod_flat!(args); @@ -31,12 +31,7 @@ async fn main() -> ExitCode { async fn run() -> anyhow::Result<()> { if std::env::args_os().nth(1).is_some_and(|s| s == "-V" || s == "--version") { - outln!( - "Ya {} ({} {})", - env!("CARGO_PKG_VERSION"), - env!("VERGEN_GIT_SHA"), - env!("VERGEN_BUILD_DATE") - )?; + outln!("Ya\n{}", yazi_version::version_full())?; return Ok(()); } @@ -110,6 +105,25 @@ async fn run() -> anyhow::Result<()> { tokio::signal::ctrl_c().await?; } + + Command::Cache(cmd) => { + yazi_tty::init(); + yazi_config::init()?; + + match cmd { + CommandCache::Clear => { + cache::Cache::clear()?; + } + } + } + + Command::Env => { + yazi_tty::init(); + yazi_term::init()?; + yazi_config::init()?; + yazi_adapter::init()?; + outln!("{}", env::Env::print()?)?; + } } Ok(()) diff --git a/yazi-dds/Cargo.toml b/yazi-dds/Cargo.toml index cd4a81e5..5ee95c22 100644 --- a/yazi-dds/Cargo.toml +++ b/yazi-dds/Cargo.toml @@ -23,6 +23,7 @@ yazi-fs = { path = "../yazi-fs", version = "26.5.6" } yazi-macro = { path = "../yazi-macro", version = "26.5.6" } yazi-shared = { path = "../yazi-shared", version = "26.5.6" } yazi-shim = { path = "../yazi-shim", version = "26.5.6" } +yazi-version = { path = "../yazi-version", version = "26.5.6" } # External dependencies anyhow = { workspace = true } @@ -38,8 +39,5 @@ tokio = { workspace = true } tokio-stream = { workspace = true } tracing = { workspace = true } -[build-dependencies] -vergen-gitcl = { version = "9.1.0", features = [ "build" ] } - [target.'cfg(windows)'.dependencies] uds_windows = "1.2.1" diff --git a/yazi-dds/build.rs b/yazi-dds/build.rs deleted file mode 100644 index 48fffb89..00000000 --- a/yazi-dds/build.rs +++ /dev/null @@ -1,13 +0,0 @@ -use std::{env, error::Error}; - -use vergen_gitcl::{Emitter, GitclBuilder}; - -fn main() -> Result<(), Box> { - if env::var_os("YAZI_NO_GITCL").is_none() { - Emitter::default().add_instructions(&GitclBuilder::default().sha(true).build()?)?.emit()?; - } else { - println!("cargo:rustc-env=VERGEN_GIT_SHA=no-gitcl"); - } - - Ok(()) -} diff --git a/yazi-dds/src/ember/hey.rs b/yazi-dds/src/ember/hey.rs index 299cbcd6..db1a78db 100644 --- a/yazi-dds/src/ember/hey.rs +++ b/yazi-dds/src/ember/hey.rs @@ -3,7 +3,7 @@ use mlua::{IntoLua, Lua, Value}; use serde::{Deserialize, Serialize}; use yazi_shared::{Id, SStr}; -use super::{Ember, EmberHi}; +use super::Ember; use crate::Peer; /// Server handshake @@ -15,7 +15,7 @@ pub struct EmberHey { impl EmberHey { pub fn owned(peers: HashMap) -> Ember<'static> { - Self { peers, version: EmberHi::version().into() }.into() + Self { peers, version: yazi_version::version().into() }.into() } } diff --git a/yazi-dds/src/ember/hi.rs b/yazi-dds/src/ember/hi.rs index f8b1149b..346a8898 100644 --- a/yazi-dds/src/ember/hi.rs +++ b/yazi-dds/src/ember/hi.rs @@ -22,14 +22,10 @@ impl<'a> EmberHi<'a> { { Self { abilities: abilities.into_iter().map(Into::into).collect(), - version: Self::version().into(), + version: yazi_version::version().into(), } .into() } - - pub fn version() -> &'static str { - concat!(env!("CARGO_PKG_VERSION"), " ", env!("VERGEN_GIT_SHA")) - } } impl<'a> From> for Ember<'a> { diff --git a/yazi-fm/src/main.rs b/yazi-fm/src/main.rs index c3ea749e..e9babc5c 100644 --- a/yazi-fm/src/main.rs +++ b/yazi-fm/src/main.rs @@ -14,20 +14,20 @@ async fn main() -> anyhow::Result<()> { Logs::start()?; _ = fdlimit::raise_fd_limit(); - yazi_tty::init(); - - yazi_term::init()?; - yazi_fs::init(); - yazi_config::init()?; - yazi_vfs::init(); - yazi_adapter::init()?; + yazi_tty::init(); + + yazi_config::init()?; yazi_boot::init(); + yazi_term::init()?; + + yazi_adapter::init()?; + yazi_dds::init(); yazi_widgets::init(); diff --git a/yazi-runner/Cargo.toml b/yazi-runner/Cargo.toml index 97434127..18a4eb21 100644 --- a/yazi-runner/Cargo.toml +++ b/yazi-runner/Cargo.toml @@ -18,13 +18,13 @@ vendored-lua = [ "mlua/vendored" ] [dependencies] yazi-binding = { path = "../yazi-binding", version = "26.5.6" } -yazi-boot = { path = "../yazi-boot", version = "26.5.6" } yazi-config = { path = "../yazi-config", version = "26.5.6" } yazi-dds = { path = "../yazi-dds", version = "26.5.6" } yazi-fs = { path = "../yazi-fs", version = "26.5.6" } yazi-macro = { path = "../yazi-macro", version = "26.5.6" } yazi-shared = { path = "../yazi-shared", version = "26.5.6" } yazi-shim = { path = "../yazi-shim", version = "26.5.6" } +yazi-version = { path = "../yazi-version", version = "26.5.6" } # External dependencies anyhow = { workspace = true } diff --git a/yazi-runner/src/loader/chunk.rs b/yazi-runner/src/loader/chunk.rs index 3fbfad08..33cff2b9 100644 --- a/yazi-runner/src/loader/chunk.rs +++ b/yazi-runner/src/loader/chunk.rs @@ -13,7 +13,7 @@ pub struct Chunk { impl Chunk { pub fn compatible(&self) -> bool { - let s = yazi_boot::actions::Actions::version(); + let s = yazi_version::version(); natsort(s.as_bytes(), self.since.as_bytes(), false) != std::cmp::Ordering::Less } diff --git a/yazi-runner/src/loader/loader.rs b/yazi-runner/src/loader/loader.rs index 5dc41e14..07a2b237 100644 --- a/yazi-runner/src/loader/loader.rs +++ b/yazi-runner/src/loader/loader.rs @@ -170,7 +170,7 @@ impl Loader { bail!( "Plugin `{id}` requires at least Yazi {}, but your current version is Yazi {}.", chunk.since, - yazi_boot::actions::Actions::version() + yazi_version::version_long() ); } diff --git a/yazi-shim/src/mlua/string.rs b/yazi-shim/src/mlua/string.rs index 861e9d84..176ecb79 100644 --- a/yazi-shim/src/mlua/string.rs +++ b/yazi-shim/src/mlua/string.rs @@ -17,7 +17,7 @@ impl fmt::Display for ByteString { impl FromLua for ByteString { fn from_lua(value: Value, lua: &Lua) -> mlua::Result { - Ok(ByteString(mlua::String::from_lua(value, lua)?)) + Ok(Self(mlua::String::from_lua(value, lua)?)) } } diff --git a/yazi-term/src/event/keyboard.rs b/yazi-term/src/event/keyboard.rs index 7836230f..5781e756 100644 --- a/yazi-term/src/event/keyboard.rs +++ b/yazi-term/src/event/keyboard.rs @@ -104,16 +104,16 @@ pub enum KeyCode { impl KeyCode { pub(crate) fn from_xterm_modifier(r#final: u8) -> Result { Ok(match r#final { - b'A' => KeyCode::Up, - b'B' => KeyCode::Down, - b'C' => KeyCode::Right, - b'D' => KeyCode::Left, - b'F' => KeyCode::End, - b'H' => KeyCode::Home, - b'P' => KeyCode::Fn(1), - b'Q' => KeyCode::Fn(2), - b'R' => KeyCode::Fn(3), - b'S' => KeyCode::Fn(4), + b'A' => Self::Up, + b'B' => Self::Down, + b'C' => Self::Right, + b'D' => Self::Left, + b'F' => Self::End, + b'H' => Self::Home, + b'P' => Self::Fn(1), + b'Q' => Self::Fn(2), + b'R' => Self::Fn(3), + b'S' => Self::Fn(4), _ => bail!(), }) } diff --git a/yazi-version/Cargo.toml b/yazi-version/Cargo.toml new file mode 100644 index 00000000..93f04a85 --- /dev/null +++ b/yazi-version/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "yazi-version" +description = "Yazi version information" +version.workspace = true +edition.workspace = true +license.workspace = true +authors.workspace = true +homepage.workspace = true +repository.workspace = true +rust-version.workspace = true + +[lints] +workspace = true + +[build-dependencies] +vergen-gitcl = { version = "9.1.0", features = [ "build", "rustc" ] } diff --git a/yazi-version/README.md b/yazi-version/README.md new file mode 100644 index 00000000..21384463 --- /dev/null +++ b/yazi-version/README.md @@ -0,0 +1,5 @@ +# yazi-version + +This crate is part of [Yazi][source], and it is not supposed to be used outside, as there are no guarantees about the stability of its API. + +[source]: https://github.com/sxyazi/yazi diff --git a/yazi-version/build.rs b/yazi-version/build.rs new file mode 100644 index 00000000..2be047c1 --- /dev/null +++ b/yazi-version/build.rs @@ -0,0 +1,25 @@ +use std::{env, error::Error}; + +use vergen_gitcl::{BuildBuilder, Emitter, GitclBuilder, RustcBuilder}; + +fn main() -> Result<(), Box> { + Emitter::default() + .add_instructions(&BuildBuilder::default().build_date(true).build()?)? + .add_instructions( + &RustcBuilder::default() + .commit_date(true) + .commit_hash(true) + .host_triple(true) + .semver(true) + .build()?, + )? + .emit()?; + + if env::var_os("YAZI_NO_GITCL").is_none() { + Emitter::default().add_instructions(&GitclBuilder::default().sha(true).build()?)?.emit()?; + } else { + println!("cargo:rustc-env=VERGEN_GIT_SHA=no-gitcl"); + } + + Ok(()) +} diff --git a/yazi-version/src/lib.rs b/yazi-version/src/lib.rs new file mode 100644 index 00000000..a7bce380 --- /dev/null +++ b/yazi-version/src/lib.rs @@ -0,0 +1,27 @@ +use std::{env::consts::{ARCH, OS}, fmt::Write}; + +pub fn version() -> &'static str { concat!(env!("CARGO_PKG_VERSION"), " ", env!("VERGEN_GIT_SHA")) } + +pub fn version_long() -> &'static str { + concat!( + env!("CARGO_PKG_VERSION"), + " (", + env!("VERGEN_GIT_SHA"), + " ", + env!("VERGEN_BUILD_DATE"), + ")" + ) +} + +pub fn version_full() -> String { + let mut s = String::new(); + + writeln!(s, " Version: {}", version_long()).ok(); + writeln!(s, " Debug : {}", cfg!(debug_assertions)).ok(); + #[rustfmt::skip] + writeln!(s, " Triple : {} ({OS}-{ARCH})", env!("VERGEN_RUSTC_HOST_TRIPLE")).ok(); + #[rustfmt::skip] + writeln!(s, " Rustc : {} ({} {})", env!("VERGEN_RUSTC_SEMVER"), &env!("VERGEN_RUSTC_COMMIT_HASH")[..8], env!("VERGEN_RUSTC_COMMIT_DATE")).ok(); + + s +}