-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
43 lines (36 loc) · 1.32 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 ignore::WalkBuilder;
use std::{env, ffi::OsStr, fs::File, path::Path};
// https://doc.rust-lang.org/cargo/reference/build-scripts.html
macro_rules! instruction {
($($arg: tt)*) => {
println!($($arg)*)
}
}
// https://github.com/rust-lang/cargo/issues/985
// macro_rules! warning {
// ($($arg: tt)*) => {
// instruction!("cargo:warning={}", format!($($arg)*))
// }
// }
fn main() {
instruction!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap());
create_new_project_tar();
}
fn create_new_project_tar() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let file = File::create(Path::new(&out_dir).join("new_project.tar")).unwrap();
let mut tar_builder = tar::Builder::new(file);
let new_project_path = Path::new("new_project");
let extra_ignored_files = [OsStr::new("Makefile.toml"), OsStr::new("Cargo.lock")];
for entry in WalkBuilder::new(new_project_path).hidden(false).build() {
let path = entry.unwrap().into_path();
if path.is_dir() || extra_ignored_files.contains(&path.file_name().unwrap()) {
continue;
}
let tar_path = path.strip_prefix(new_project_path).unwrap();
tar_builder
.append_file(&tar_path, &mut File::open(&path).unwrap())
.unwrap();
}
tar_builder.finish().unwrap();
}