-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
53 lines (43 loc) · 1.67 KB
/
Copy pathbuild.rs
File metadata and controls
53 lines (43 loc) · 1.67 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
fn main() {
#[cfg(feature = "themes")]
themes();
//version (sha date)
let s = format!(r#""{} {}""#, clap::crate_version!(), version());
std::fs::write(outdir().join("version.rs"), s).unwrap();
}
/// git short sha1 and date stuff, only when wallust is at a unstable version
fn version() -> String {
use vergen_git2 as vergen;
let git2 = vergen::Git2Builder::default()
.describe(true, false, None)
.commit_date(true)
.sha(true)
.build().unwrap();
vergen::Emitter::default()
.add_instructions(&git2).unwrap()
.emit_and_set().unwrap();
let sha = std::env::var_os("VERGEN_GIT_SHA").unwrap();
let sha = sha.to_string_lossy();
let date = std::env::var_os("VERGEN_GIT_COMMIT_DATE").unwrap();
let date = date.to_string_lossy();
format!("({sha} {date})")
}
#[cfg(feature = "themes")]
/// This adds "random" to the COLS_KEY array such that it can be used as a clap constraint.
/// This is a "workaround" only while making assets. Shell completions benefit from this since clap
/// completions can put all the strings in the array into the completions itself.
fn themes() {
use wallust_themes::COLS_KEY;
println!("cargo:rerun-if-changed=build.rs");
let mut val = COLS_KEY.to_vec();
val.push("random");
val.push("list");
let mut val: Vec<_> = val.iter().map(|i| format!(r#""{i}","#)).collect(); //"string",
val.insert(0, "[".to_string()); //start of array
val.push("]".to_string());
std::fs::write(outdir().join("args.rs"), val.join("")).unwrap();
}
fn outdir() -> std::path::PathBuf {
let out = std::env::var_os("OUT_DIR").unwrap();
std::path::Path::new(&out).into()
}