-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
30 lines (24 loc) · 937 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
29
30
use std::env::var;
use std::fs::{read_to_string, File};
use std::io::Write;
use std::path::Path;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=purin.dockerfile");
let manifest_dir = var("CARGO_MANIFEST_DIR").unwrap();
let src_path = Path::new(&manifest_dir).join("purin.dockerfile");
let content = read_to_string(src_path).unwrap();
let mut sharp_marks: String = content
.chars()
.filter_map(|c| if c == '#' { Some('#') } else { None })
.collect();
sharp_marks.push('#');
let constant_value = format!(
"pub const DOCKER_FILE: &str = r{}\"{}\"{};\n",
&sharp_marks, content, &sharp_marks
);
let out_dir = var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("docker_file.rs");
let mut source = File::create(dest_path).unwrap();
source.write_all(constant_value.as_bytes()).unwrap();
}