This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
/
build.rs
51 lines (45 loc) · 1.92 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! build.rs is used to generate code at build time, which is then
//! imported elsewhere. This file is understood and executed by cargo.
use std::env;
use std::fs;
use std::path::Path;
/// Write version information to $OUT_DIR/build_rev.rs, which is included in src/lib.rs.
fn main() {
println!("cargo:rerun-if-env-changed=BUILD_REV_COUNT");
println!("cargo:rerun-if-env-changed=RUN_TIME_CLOSURE");
println!("cargo:rerun-if-changed=build.rs");
let rev_count = env::var("BUILD_REV_COUNT")
.expect("BUILD_REV_COUNT not set, please reload nix-shell")
.parse::<usize>()
.expect("BUILD_REV_COUNT should be parseable as usize");
fs::write(
// cargo sets OUT_DIR: https://doc.rust-lang.org/cargo/reference/environment-variables.html
Path::new(&env::var("OUT_DIR").unwrap()).join("build_rev.rs"),
format!(
r#"
/// lorri version in MAJOR.MINOR format.
pub const LORRI_VERSION: &str = "{major}.{minor}";
/// Number of revisions in the Git tree.
pub const VERSION_BUILD_REV: usize = {rev_count};
/// Run-time closure parameters. This argument points to a file
/// generated by ./nix/runtime.nix in Lorri's source.
pub const RUN_TIME_CLOSURE: &str = "{runtime_closure}";
"#,
// cargo sets CARGO_PKG_VERSION_MAJOR and CARGO_PKG_VERSION_MINOR:
// https://doc.rust-lang.org/cargo/reference/environment-variables.html
major = env::var("CARGO_PKG_VERSION_MAJOR").unwrap(),
minor = env::var("CARGO_PKG_VERSION_MINOR").unwrap(),
rev_count = rev_count,
runtime_closure = env::var("RUN_TIME_CLOSURE")
.expect("RUN_TIME_CLOSURE not set, please reload nix-shell"),
)
.as_bytes(),
)
.unwrap();
for v in &[
"src/com.target.lorri.varlink",
"src/com.target.lorri.internal.varlink",
] {
varlink_generator::cargo_build_tosource(v, /*rustfmt */ true);
}
}