-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
73 lines (62 loc) · 2.22 KB
/
build.rs
File metadata and controls
73 lines (62 loc) · 2.22 KB
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
use std::{vec, process::Command, fs, path::{PathBuf, Path}};
const UI_DIR: &str = "./ui";
const CPP_DIR: &str = "./cpp";
const UIC_LOC: &str = "/usr/lib/qt6/uic";
const MOC_LOC: &str = "/usr/lib/qt6/moc";
const QOBJECT_FILES: [&'static str; 1] = ["./cpp/mainwindow.h"];
fn main() {
println!("cargo:rerun-if-changed=./cpp/");
println!("cargo:rerun-if-changed=./ui/");
fs::create_dir_all("./target/ui").unwrap();
fs::create_dir_all("./target/moc").unwrap();
let qt_modules = vec!["Core", "Gui", "Widgets"]
.iter()
.map(|m|String::from(*m))
.collect();
let qtbuild = qt_build_utils::QtBuild::new(qt_modules).unwrap();
//run uic
for f in fs::read_dir(UI_DIR).unwrap(){
let f = f.unwrap();
Command::new(UIC_LOC)
.args([f.path().to_str().unwrap(), "-o", format!("./target/ui/ui_{}.h", f.path().file_stem().unwrap().to_str().unwrap()).as_str()])
.output()
.expect("failed to run uic");
}
let mut includes = vec![];
for b in qtbuild.include_paths(){
includes.push("I".to_string());
includes.push(b.to_string_lossy().to_string());
}
//run moc
let mut files = vec![];
for f in QOBJECT_FILES{
let f = Path::new(f);
let out_file = f.file_stem().unwrap().to_str().unwrap().to_string();
let out_file = format!("./target/moc/moc_{}.cpp", &out_file);
Command::new(MOC_LOC)
.args([f.to_str().unwrap(), "-o", out_file.as_str()])
.output()
.expect("failed to run uic");
files.push(out_file);
/*let f = std::fs::File::open(&out_file).unwrap();
if f.metadata().unwrap().len() == 0{
drop(f);
fs::remove_file(&out_file).unwrap_or_else(|_|{
println!("cargo:warning=不要なファイルの削除に失敗しました。");
()
});
}*/
}
cxx_build::bridge("src/main.rs")
.cpp(true)
.flag("-std=c++17")
.flag("-Wall")
.flag("-Wextra")
.flag("-v")
.flag("-g")
.includes(&includes)
.file("./cpp/lib.cpp")
.files(files)
.compile("cppqt");
qtbuild.cargo_link_libraries();
}