mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 12:41:08 +08:00
Add BUILD_VERSION to lib.rs
In CMake this used a `version` file in the CARGO_MANIFEST_DIR, but relying on that is problematic due to change-detection, as if we add `cargo-rerun-if-changed:version`, cargo would rerun every time if the file does not exist, since cargo would expect the file to be generated by the build-script. We could generate it, but that relies on the output of `git describe`, whose dependencies we can only limit to anything in the `.git`-folder, again causing unnecessary build-script runs. Instead, this reads the `FISH_BUILD_VERSION`-env-variable at compile time instead of the `version`-file, and falls back to calling git-describe through the `git_version`-proc-macro. We thus do not need to deal with extraneous build-script running.
This commit is contained in:
parent
360ba46660
commit
e7f8fb04cc
29
Cargo.lock
generated
29
Cargo.lock
generated
|
@ -337,6 +337,7 @@ dependencies = [
|
|||
"cxx-gen",
|
||||
"errno 0.2.8",
|
||||
"fast-float",
|
||||
"git-version",
|
||||
"hexponent",
|
||||
"inventory",
|
||||
"lazy_static",
|
||||
|
@ -368,6 +369,28 @@ dependencies = [
|
|||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "git-version"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6b0decc02f4636b9ccad390dcbe77b722a77efedfa393caf8379a51d5c61899"
|
||||
dependencies = [
|
||||
"git-version-macro",
|
||||
"proc-macro-hack",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "git-version-macro"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe69f1cbdb6e28af2bac214e943b99ce8a0a06b447d15d3e61161b0423139f3f"
|
||||
dependencies = [
|
||||
"proc-macro-hack",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.1"
|
||||
|
@ -705,6 +728,12 @@ dependencies = [
|
|||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-hack"
|
||||
version = "0.5.20+deprecated"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.66"
|
||||
|
|
|
@ -60,6 +60,7 @@ rand = { version = "0.8.5", features = ["small_rng"] }
|
|||
unixstring = "0.2.7"
|
||||
widestring = "1.0.2"
|
||||
rand_pcg = "0.3.1"
|
||||
git-version = "0.3"
|
||||
|
||||
[build-dependencies]
|
||||
autocxx-build = "0.23.1"
|
||||
|
@ -80,4 +81,4 @@ fish-ffi-tests = ["inventory"]
|
|||
|
||||
# The following features are auto-detected by the build-script and should not be enabled manually.
|
||||
asan = []
|
||||
bsd = []
|
||||
bsd = []
|
||||
|
|
|
@ -14,7 +14,7 @@ fn main() {
|
|||
.file("fish-rust/src/compat.c")
|
||||
.compile("libcompat.a");
|
||||
|
||||
let rust_dir = std::env::var("CARGO_MANIFEST_DIR").expect("Env var CARGO_MANIFEST_DIR missing");
|
||||
let rust_dir = env!("CARGO_MANIFEST_DIR");
|
||||
let target_dir =
|
||||
std::env::var("FISH_RUST_TARGET_DIR").unwrap_or(format!("{}/{}", rust_dir, "target/"));
|
||||
let cpp_fish_src_dir = format!("{}/{}", rust_dir, "src/");
|
||||
|
|
|
@ -10,6 +10,11 @@
|
|||
#![allow(clippy::ptr_arg)]
|
||||
#![allow(clippy::field_reassign_with_default)]
|
||||
|
||||
pub const BUILD_VERSION: &str = match option_env!("FISH_BUILD_VERSION") {
|
||||
Some(v) => v,
|
||||
None => git_version::git_version!(args = ["--always", "--dirty=-dirty"], fallback = "unknown"),
|
||||
};
|
||||
|
||||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user