-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.rs
43 lines (35 loc) · 1.02 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
use std::path::Path;
use serde::Deserialize;
#[derive(Deserialize)]
struct CargoToml {
package: Package,
}
#[derive(Deserialize)]
struct Package {
name: String,
version: String,
authors: Vec<String>,
description: String,
}
fn main() {
println!("Thank you for installing and using GRC! [by @sdttttt]");
println!("cargo:rerun-if-changed=Cargo.toml");
let cargo_toml_str =
std::fs::read_to_string(Path::new("Cargo.toml")).expect("Cargo.toml read failed.");
let cargo_toml = toml::from_str::<CargoToml>(&cargo_toml_str).expect("toml parse failed.");
let version_file_rs = Path::new("src/version.rs");
let version_file_str = format!(
r#"
// auto generated by build.rs
pub const NAME: &str = "{}";
pub const VERSION: &str = "{}";
pub const AUTHOR: &str = "{}";
pub const DESCRIPTION: &str = "{}";
"#,
cargo_toml.package.name,
cargo_toml.package.version,
cargo_toml.package.authors.join(", "),
cargo_toml.package.description
);
std::fs::write(version_file_rs, version_file_str).expect("version.rs wirte failed.");
}