-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.rs
113 lines (96 loc) · 4.61 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
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
107
108
109
110
111
112
113
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();
}
let num_jobs = env::var("NUM_JOBS").unwrap();
let vitasdk_path = env::var("VITASDK").map(PathBuf::from);
if vitasdk_path.is_err() {
return;
}
let vitasdk_path = vitasdk_path.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 kubridge_path = PathBuf::from("kubridge");
{
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 bindings_file = out_path.join("kubridge_bindings.rs");
const KUBRIDGE_HEADERS: [&str; 1] = ["kubridge.h"];
let mut bindings = bindgen::Builder::default()
.clang_args(["-I", vitasdk_include_path.to_str().unwrap()])
.clang_args(["-I", kubridge_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 KUBRIDGE_HEADERS {
let header_path = kubridge_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();
}
if target != "armv7-sony-vita-newlibeabihf" {
return;
}
{
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");
}
{
let kubridge_dst_path = cmake::Config::new(&kubridge_path).build_target("libkubridge_stub.a").build().join("build");
let kubridge_lib_path = kubridge_dst_path.join("libkubridge_stub.a");
let kubridge_lib_new_path = kubridge_dst_path.join("libkubridge_stub_dsvita.a");
fs::rename(kubridge_lib_path, kubridge_lib_new_path).unwrap();
println!("cargo:rustc-link-search=native={}", fs::canonicalize(kubridge_dst_path).unwrap().to_str().unwrap());
println!("cargo:rustc-link-lib=static=kubridge_stub_dsvita");
}
}