mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00

* Anki: Replace lazy_static with once_cell Unify to once_cell, lazy_static's replacement. The latter in unmaintained. * Anki: Replace once_cell with stabilized LazyCell / LazyLock as far as possible Since 1.80: https://github.com/rust-lang/rust/issues/109736 and https://github.com/rust-lang/rust/pull/98165 Non-Thread-Safe Lazy → std::cell::LazyCell https://doc.rust-lang.org/nightly/std/cell/struct.LazyCell.html Thread-safe SyncLazy → std::sync::LazyLock https://doc.rust-lang.org/nightly/std/sync/struct.LazyLock.html The compiler accepted LazyCell only in minilints. The final use in rslib/src/log.rs couldn't be replaced since get_or_try_init has not yet been standardized: https://github.com/rust-lang/rust/issues/109737 * Declare correct MSRV (dae) Some of our deps require newer Rust versions, so this was misleading. Updating the MSRV also allows us to use .inspect() on Option now
37 lines
1 KiB
Rust
37 lines
1 KiB
Rust
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
use std::env;
|
|
use std::sync::LazyLock;
|
|
|
|
pub fn version() -> &'static str {
|
|
include_str!("../../.version").trim()
|
|
}
|
|
|
|
pub fn buildhash() -> &'static str {
|
|
option_env!("BUILDHASH").unwrap_or("dev").trim()
|
|
}
|
|
|
|
pub(crate) fn sync_client_version() -> &'static str {
|
|
static VER: LazyLock<String> = LazyLock::new(|| {
|
|
format!(
|
|
"anki,{version} ({buildhash}),{platform}",
|
|
version = version(),
|
|
buildhash = buildhash(),
|
|
platform = env::var("PLATFORM").unwrap_or_else(|_| env::consts::OS.to_string())
|
|
)
|
|
});
|
|
&VER
|
|
}
|
|
|
|
pub(crate) fn sync_client_version_short() -> &'static str {
|
|
static VER: LazyLock<String> = LazyLock::new(|| {
|
|
format!(
|
|
"{version},{buildhash},{platform}",
|
|
version = version(),
|
|
buildhash = buildhash(),
|
|
platform = env::consts::OS
|
|
)
|
|
});
|
|
&VER
|
|
}
|