build: git format hook

This commit is contained in:
ardocrat
2026-05-21 00:04:22 +03:00
parent 242a3b9434
commit 15d1aa1a21
+27 -2
View File
@@ -1,9 +1,28 @@
use std::path::PathBuf;
use std::process::Command;
use std::{env, fs};
fn main() {
built::write_built_file().expect("Failed to acquire build-time information");
// Setting up git hooks in the project: rustfmt and so on.
let git_hooks = format!(
"git config core.hooksPath {}",
PathBuf::from("./.hooks").to_str().unwrap()
);
if cfg!(target_os = "windows") {
Command::new("cmd")
.args(&["/C", &git_hooks])
.output()
.expect("failed to execute git config for hooks");
} else {
Command::new("sh")
.args(&["-c", &git_hooks])
.output()
.expect("failed to execute git config for hooks");
}
let out_dir = env::var("OUT_DIR").unwrap();
let tor_out_dir = format!("{}/tor", out_dir);
let mut webtunnel_file = format!("{}/webtunnel", tor_out_dir);
@@ -16,6 +35,9 @@ fn main() {
let target = env::var("TARGET").unwrap();
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
if target_os == "ios" {
return;
}
let is_android = target_os == "android";
if is_android {
@@ -28,13 +50,16 @@ fn main() {
"x86_64"
};
let root = env::var("CARGO_MANIFEST_DIR").unwrap();
webtunnel_file = format!("{}/android/app/src/main/jniLibs/{}/libwebtunnel.so", root, arch);
webtunnel_file = format!(
"{}/android/app/src/main/jniLibs/{}/libwebtunnel.so",
root, arch
);
}
// Build if Webtunnel binary is empty or not exists.
let empty = match fs::File::open(&webtunnel_file) {
Ok(file) => file.metadata().unwrap().len() == 0,
Err(_) => true
Err(_) => true,
};
let build = !exists || empty;
if build {