-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
36 lines (32 loc) · 991 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
35
36
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
fn main() {
// Read version from Cargo.toml
let version = env!("CARGO_PKG_VERSION");
// Split the version into major, minor, and patch
let version_parts: Vec<u32> = version
.split('.')
.map(|p| {
p.parse::<u32>().expect(&format!(
"Version part can't be parsed into a u32: \"{}\"",
p
))
})
.collect();
let (major, minor, patch) = match &version_parts[..] {
[major, minor, patch] => (major, minor, patch),
_ => panic!("Invalid version format"),
};
// Write the parsed version parts to a file that will be included in the build
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("version");
let mut f = File::create(&dest_path).unwrap();
writeln!(
f,
"({}, {}, {})",
major, minor, patch
)
.unwrap();
}