-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbuild.rs
28 lines (25 loc) · 988 Bytes
/
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
//! 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=RUN_TIME_CLOSURE");
println!("cargo:rerun-if-changed=build.rs");
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#"
/// 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}";
"#,
runtime_closure = env::var("RUN_TIME_CLOSURE")
.expect("RUN_TIME_CLOSURE not set, please reload nix-shell"),
)
.as_bytes(),
)
.unwrap();
}