-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.rs
71 lines (60 loc) · 2.83 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use bindgen::Formatter;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::process::Command;
use std::{env, fs};
fn main() {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let build_profile_name = out_path.to_str().unwrap().split(std::path::MAIN_SEPARATOR).nth_back(3).unwrap();
let build_profile_name_file = out_path.join("build_profile_name");
File::create(build_profile_name_file).unwrap().write_all(build_profile_name.as_bytes()).unwrap();
let target = env::var("TARGET").unwrap();
if target != "armv7-sony-vita-newlibeabihf" {
// Running IDE on anything other than linux will fail, so ignore compile error
let _ = cc::Build::new().file("builtins/cache.c").try_compile("cache").ok();
return;
}
let num_jobs = env::var("NUM_JOBS").unwrap();
let vitasdk_path = PathBuf::from(env::var("VITASDK").unwrap());
let vitasdk_include_path = vitasdk_path.join("arm-vita-eabi").join("include");
let vitasdk_lib_path = vitasdk_path.join("arm-vita-eabi").join("lib");
let bindings_file = out_path.join("imgui_bindings.rs");
const IMGUI_HEADERS: [&str; 3] = ["imgui.h", "imgui_internal.h", "imgui_impl_vitagl.h"];
let mut bindings = bindgen::Builder::default()
.clang_args(["-I", vitasdk_include_path.to_str().unwrap()])
.clang_args(["-x", "c++"])
.clang_args(["-std=c++17"])
.clang_args(["-target", "armv7a-none-eabihf"])
.formatter(Formatter::Prettyplease);
for header in IMGUI_HEADERS {
let header_path = vitasdk_include_path.join(header);
println!("cargo:rerun-if-changed={header_path:?}");
bindings = bindings.header(header_path.to_str().unwrap());
}
bindings.rust_target(bindgen::RustTarget::Nightly).generate().unwrap().write_to_file(bindings_file).unwrap();
println!("cargo:rustc-link-search=native={vitasdk_lib_path:?}");
println!("cargo:rustc-link-lib=static=imgui");
let vita_gl_path = PathBuf::from("vitaGL");
let vita_gl_lib_path = vita_gl_path.join("libvitaGL.a");
let vita_gl_lib_new_path = vita_gl_path.join("libvitaGL_dsvita.a");
Command::new("make")
.current_dir("vitaGL")
.args(["-j", &num_jobs])
.envs([
("HAVE_UNFLIPPED_FBOS", "1"),
("NO_TEX_COMBINER", "1"),
("NO_DEBUG", "1"),
("SHADER_COMPILER_SPEEDHACK", "1"),
("MATH_SPEEDHACK", "1"),
("HAVE_SHADER_CACHE", "1"),
// ("HAVE_SHARK_LOG", "1"),
// ("LOG_ERRORS", "1"),
// ("HAVE_RAZOR", "1"),
])
.status()
.unwrap();
fs::rename(vita_gl_lib_path, vita_gl_lib_new_path).unwrap();
println!("cargo:rustc-link-search=native={}", fs::canonicalize(vita_gl_path).unwrap().to_str().unwrap());
println!("cargo:rustc-link-lib=static=vitaGL_dsvita");
}