forked from esp-rs/std-training
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
24 lines (19 loc) · 676 Bytes
/
build.rs
File metadata and controls
24 lines (19 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::{fs::File, io::Write};
use uuid::Uuid;
fn main() -> anyhow::Result<()> {
if let Ok(_already_exists) = File::open("uuid.toml") {
return Ok(());
}
let mut uuid_file = File::create("uuid.toml")?;
uuid_file.write_all("[get-uuid]\n".as_bytes())?;
let uuid_val = Uuid::new_v4().to_string();
uuid_file.write_fmt(format_args!("uuid = \"{}\"\n", uuid_val))?;
let package_root = env!("CARGO_MANIFEST_DIR");
let uuid_rs = format!("{}/_uuid.rs", package_root);
let mut uuid_file = File::create(uuid_rs)?;
uuid_file.write_fmt(format_args!(
"const UUID: &'static str = \"{}\";\n",
uuid_val
))?;
Ok(())
}