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
96
97
98
99
100
101
102
103
104
105
106
|
use std::{env, path::PathBuf, str::FromStr};
fn main() {
build_butck_ffi();
#[cfg(target_os = "windows")]
build_win32_gui();
}
fn build_butck_ffi() {
// Check if cbindgen is installed
let cbindgen_check = std::process::Command::new("cbindgen")
.arg("--version")
.output();
if let Err(e) = cbindgen_check {
if e.kind() == std::io::ErrorKind::NotFound {
eprintln!("Error: cbindgen is not installed. Please install it with:");
eprintln!(" cargo install cbindgen");
std::process::exit(1);
} else {
eprintln!("Error: Failed to check cbindgen installation: {}", e);
std::process::exit(1);
}
}
let target_dir = get_target_dir();
// Try to run cbindgen to generate C bindings
// > cbindgen --config cbindgen.toml ffi --output ffi/.temp/jvlib.h --quiet
let output = std::process::Command::new("cbindgen")
.args([
"--config",
"cbindgen.toml",
".",
"--output",
&format!("{}/lib_butck.h", target_dir.display()),
"--quiet",
])
.output();
match output {
Ok(output) if output.status.success() => {
// Successfully generated bindings
}
Ok(_) => {
eprintln!("cbindgen failed to generate bindings");
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
eprintln!("cbindgen not found, skipping C binding generation");
}
Err(e) => {
eprintln!("Failed to run cbindgen: {}", e);
}
}
}
fn build_win32_gui() {
use std::fs;
use std::path::Path;
use std::process::Command;
const EXE_NAME: &str = "butckg.exe";
let crate_root = env!("CARGO_MANIFEST_DIR");
let build_script = Path::new(crate_root).join("gui\\win32\\scripts\\build.ps1");
let status = Command::new("powershell")
.arg("-ExecutionPolicy")
.arg("Bypass")
.arg("-File")
.arg(&build_script)
.status()
.expect("Failed to execute build script");
if !status.success() {
panic!("Build script failed with exit code: {:?}", status.code());
}
let exe_path = Path::new(crate_root)
.join("gui\\win32\\build\\bin")
.join(EXE_NAME);
if exe_path.exists() {
let target_dir = get_target_dir();
let dest_path = target_dir.join(EXE_NAME);
if let Err(e) = fs::copy(&exe_path, &dest_path) {
panic!("Failed to copy executable to build directory: {}", e);
}
} else {
panic!("Executable not found at: {:?}", exe_path);
}
}
fn get_target_dir() -> PathBuf {
let out_dir = std::env::var("OUT_DIR").unwrap();
let out_dir_path = PathBuf::from_str(&out_dir).unwrap();
out_dir_path
.parent()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap()
.to_path_buf()
}
|