-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
30 lines (25 loc) · 1.08 KB
/
build.rs
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
use std::{env, fs, process::Command};
fn emit_version() {
let package_name = env::var("CARGO_PKG_NAME").unwrap();
let package_version = env::var("CARGO_PKG_VERSION").unwrap();
let mut git_commit_sha = env::var("TASKWORKER_GIT_REVISION").unwrap_or_default();
if git_commit_sha.is_empty() {
git_commit_sha = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.inspect_err(|_e| {
println!("cargo:warning=git rev-parse failure, unable to determine revision");
})
.map(|cmd| String::from_utf8(cmd.stdout).unwrap())
.unwrap_or("unknown-rev".to_string())
};
let release_name = format!("{}@{}+{}", package_name, package_version, git_commit_sha);
fs::write("src/.VERSION", &release_name).expect("Unable to write version");
println!("cargo:rustc-env=TASKWORKER_VERSION={}", &release_name);
}
// generated by `sqlx migrate build-script`
fn main() {
emit_version();
// trigger recompilation when a new migration is added
println!("cargo:rerun-if-changed=migrations");
}