-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
49 lines (41 loc) · 1.46 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
44
45
46
47
48
49
// Copyright 2018 Andrei Amatuni
// This file is part of turtl.
// tirtl is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// turtl is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with turtl. If not, see <http://www.gnu.org/licenses/>.
use std::fs;
use std::mem;
use std::process::Command;
fn git_hash() -> String {
let output = Command::new("git")
.arg("rev-parse")
.arg("HEAD")
.output()
.expect("failed to execute process");
let hash_str = String::from_utf8(output.stdout).unwrap();
return hash_str.replace("\n", "");
}
fn build_version_file(path: &str) {
let githash = git_hash();
let semver = env!("CARGO_PKG_VERSION");
let intsize = mem::size_of::<isize>();
let file_data = format!(
"
pub const GIT_HASH: &'static str = \"{}\";
pub const VERSION: &'static str = \"{}\";
pub const INTSIZE: i32 = {};
",
githash, semver, intsize
);
fs::write(path, file_data).expect("Unable to write file");
}
fn main() {
build_version_file("src/version.rs")
}