-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
34 lines (30 loc) · 894 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
31
32
33
34
use std::env;
use std::fs;
use std::fs::File;
use std::io::Write;
use std::path::Path;
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("hello.rs");
generate_file(&dest_path, b"
pub fn message() -> &'static str {
\"Hello, World!\"
}
");
let gen_dir = Path::new(&out_dir).join("gen");
if !gen_dir.exists() {
fs::create_dir(&gen_dir).unwrap();
}
let dest_path2 = gen_dir.join("hello2.rs");
generate_file(&dest_path2, b"
pub fn message2() -> &'static str {
\"Hello, World!\"
}
");
println!("cargo:rustc-env=GENERATED_ENV={}", gen_dir.display());
println!("cargo:rustc-cfg=has_generated_feature")
}
fn generate_file<P: AsRef<Path>>(path: P, text: &[u8]) {
let mut f = File::create(path).unwrap();
f.write_all(text).unwrap()
}