-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
49 lines (44 loc) · 1.89 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
use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
if let Ok(package_name) = env::var("CARGO_PKG_NAME") {
if package_name == "jacs" {
let target_dir = PathBuf::from(
env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| "target".to_string()),
);
let release_dir = target_dir.join("release");
// Get the directories in the system's PATH
let path_dirs = env::var_os("PATH").unwrap_or_default();
let path_dirs = env::split_paths(&path_dirs).collect::<Vec<_>>();
// Find a suitable directory to install the binary
let install_dir = path_dirs.into_iter().find(|dir| dir.is_dir());
match install_dir {
Some(dir) => {
let bin_file = release_dir.join("jacs");
let install_file = dir.join("jacs");
// Check if the 'jacs' binary exists
if bin_file.exists() {
// Copy the 'jacs' binary to the installation directory
match fs::copy(&bin_file, &install_file) {
Ok(_) => println!("Installed 'jacs' to '{}'", install_file.display()),
Err(err) => println!(
"Warning: Failed to install 'jacs' to '{}': {}",
install_file.display(),
err
),
}
} else {
println!(
"Warning: 'jacs' binary not found at '{}'",
bin_file.display()
);
}
}
None => {
println!("Warning: No suitable directory found in PATH to install 'jacs'");
}
}
}
}
}