Skip to content

Commit 35cef7b

Browse files
committed
fix: app version
1 parent 509563e commit 35cef7b

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

cli/build.rs

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,54 @@
1-
use std::{borrow::Cow, process::Command};
1+
use std::{borrow::Cow, env, process::Command};
22

33
/// Generate the `cargo:` key output
44
pub fn generate_cargo_keys() {
5-
let commit = if let Ok(hash) = std::env::var("CLI_GIT_COMMIT_HASH") {
6-
Cow::from(hash.trim().to_owned())
7-
} else {
8-
// We deliberately set the length here to `11` to ensure that
9-
// the emitted hash is always of the same length; otherwise
10-
// it can (and will!) vary between different build environments.
11-
match Command::new("git")
12-
.args(["rev-parse", "--short=11", "HEAD"])
13-
.output()
14-
{
15-
Ok(o) if o.status.success() => {
16-
let sha = String::from_utf8_lossy(&o.stdout).trim().to_owned();
17-
Cow::from(sha)
18-
}
19-
Ok(o) => {
20-
let stderr = String::from_utf8_lossy(&o.stderr).trim().to_owned();
21-
println!(
22-
"cargo:warning=Git command failed with status '{}' with message: '{}'",
23-
o.status, stderr,
24-
);
25-
Cow::from("unknown")
26-
}
27-
Err(err) => {
28-
println!("cargo:warning=Failed to execute git command: {}", err);
29-
Cow::from("unknown")
30-
}
5+
let output = Command::new("git")
6+
.args(["rev-parse", "--short", "HEAD"])
7+
.output();
8+
9+
let commit = match output {
10+
Ok(o) if o.status.success() => {
11+
let sha = String::from_utf8_lossy(&o.stdout).trim().to_owned();
12+
Cow::from(sha)
13+
}
14+
Ok(o) => {
15+
println!("cargo:warning=Git command failed with status: {}", o.status);
16+
Cow::from("unknown")
17+
}
18+
Err(err) => {
19+
println!("cargo:warning=Failed to execute git command: {}", err);
20+
Cow::from("unknown")
3121
}
3222
};
3323

34-
println!("cargo:rustc-env=CLI_COMMIT_HASH={commit}");
35-
println!("cargo:rustc-env=CLI_IMPL_VERSION={}", get_version(&commit))
24+
println!("cargo:rustc-env=APP_VERSION={}", get_version(&commit))
25+
}
26+
27+
fn get_platform() -> String {
28+
let env_dash = if env::var("CARGO_CFG_TARGET_ENV").unwrap().is_empty() {
29+
""
30+
} else {
31+
"-"
32+
};
33+
34+
format!(
35+
"{}-{}{}{}",
36+
env::var("CARGO_CFG_TARGET_ARCH").unwrap(),
37+
env::var("CARGO_CFG_TARGET_OS").unwrap(),
38+
env_dash,
39+
env::var("CARGO_CFG_TARGET_ENV").unwrap_or(String::from("")),
40+
)
3641
}
3742

3843
fn get_version(impl_commit: &str) -> String {
3944
let commit_dash = if impl_commit.is_empty() { "" } else { "-" };
4045

4146
format!(
42-
"{}{}{}",
47+
"{}{}{}-{}",
4348
std::env::var("CARGO_PKG_VERSION").unwrap_or_default(),
4449
commit_dash,
45-
impl_commit
50+
impl_commit,
51+
get_platform(),
4652
)
4753
}
4854

cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct Args {
5959
async fn main() {
6060
let args = Args::parse();
6161
if args.version == true {
62-
println!(env!("CLI_IMPL_VERSION"));
62+
println!(env!("APP_VERSION"));
6363
return;
6464
}
6565
let options = match Options::new(args.config_path) {

0 commit comments

Comments
 (0)