forked from agntcy/slim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
36 lines (32 loc) · 1007 Bytes
/
Copy pathbuild.rs
File metadata and controls
36 lines (32 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright AGNTCY Contributors (https://github.com/agntcy)
// SPDX-License-Identifier: Apache-2.0
use std::process::Command;
fn set_env(name: &str, cmd: &mut Command) {
let value = match cmd.output() {
Ok(output) => String::from_utf8(output.stdout)
.unwrap_or_default()
.trim()
.to_string(),
Err(err) => {
println!("cargo:warning={err}");
String::new()
}
};
println!("cargo:rustc-env={name}={value}");
}
pub fn main() {
set_env(
"GIT_SHA",
Command::new("git").args(["rev-parse", "--short", "HEAD"]),
);
set_env(
"BUILD_DATE",
Command::new("date").args(["-u", "+%Y-%m-%dT%H:%M:%SZ"]),
);
set_env(
"VERSION",
Command::new("git").args(["describe", "--tags", "--always", "--match", "slim-v*"]),
);
let profile = std::env::var("PROFILE").unwrap_or_else(|_| "unknown".to_string());
println!("cargo:rustc-env=PROFILE={profile}");
}