forked from hankjordan/bevy_save
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
41 lines (36 loc) · 1.03 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
#![allow(clippy::uninlined_format_args)]
use std::{
env,
fs,
path::Path,
};
fn main() {
let workspace = env::var("OUT_DIR")
.ok()
.map(|v| Path::new(&v).to_path_buf())
.and_then(|path| {
for ancestor in path.ancestors() {
if let Some(last) = ancestor.file_name() {
if last == "target" {
return ancestor
.parent()
.and_then(|p| p.file_name())
.and_then(|p| p.to_str())
.map(|p| p.to_owned());
}
}
}
None
})
.expect("Could not find parent workspace.");
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest = Path::new(&out_dir).join("workspace.rs");
fs::write(
dest,
format!(
"/// The name of the project's workspace.\npub const WORKSPACE: &str = {:?};",
workspace
),
)
.unwrap();
}