-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.toml
95 lines (79 loc) · 2.12 KB
/
Makefile.toml
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
[config]
skip_core_tasks = true
default_to_workspace = false
[tasks.default]
dependencies = ["make-dev-dirs", "run"]
[tasks.run]
dependencies = ["make-dev-dirs", "copy-assets"]
command = "cargo"
args = ["run", "--bin", "apex-client"]
cwd = "./debug/"
env = { "RUST_LOG" = "apex_client=debug, apex_framework=debug" }
[tasks.build]
command = "cargo"
args = ["build", "--bin", "apex-client", "${@}"]
[tasks.run-opt]
dependencies = ["make-dev-dirs", "copy-assets"]
command = "cargo"
args = ["run", "--bin", "apex-client", "--release", "--", "-C", "target-cpu=native"]
cwd = "./debug/"
env = { "RUST_LOG" = "apex_client=debug, apex_framework=debug" }
[tasks.make-dev-dirs]
script = '''
#!@duckscript
if not is_path_exists ./debug
mkdir ./debug
end
'''
[tasks.copy-assets]
condition_script = [
'''
#!@rust
//! ```cargo
//! [dependencies]
//! anyhow = "1.0.86"
//! walkdir = "2.5.0"
//! crc32fast = "1.4.2"
//! ```
use std::env;
use std::path::PathBuf;
use crc32fast::Hasher;
use walkdir::{WalkDir, DirEntry};
fn is_valid(entry: &DirEntry) -> bool {
let is_hidden = entry.file_name()
.to_str()
.map(|s| s.starts_with("."))
.unwrap_or(false);
return !is_hidden;
}
fn main() -> anyhow::Result<()> {
let mut hasher = Hasher::new();
let walker = WalkDir::new("./assets").into_iter();
for entry in walker.filter_entry(is_valid) {
let Ok(entry) = entry else { continue };
if entry.file_type().is_dir() { continue }
let data = std::fs::read(entry.path())?;
hasher.update(&data);
let path = entry.path().as_os_str();
hasher.update(&path.as_encoded_bytes());
}
let target_dir = env!("CARGO_MAKE_CRATE_TARGET_DIRECTORY");
let hash_path = PathBuf::from(target_dir).join("_apex_last_assets_hash");
let old_hash = std::fs::read_to_string(&hash_path).unwrap_or_default();
let new_hash = hasher.finalize().to_string();
if old_hash != new_hash || !PathBuf::from(target_dir).join("assets").exists() {
std::fs::write(hash_path, new_hash)?;
return Ok(());
}
std::process::exit(-1);
}
'''
]
script = '''
#!@duckscript
rm -r ./debug/assets
cp ./assets ./debug
'''
[tasks.clean]
command = "cargo"
args = ["clean"]