-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
103 lines (91 loc) · 3.48 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
use std::path::Path;
use std::{env, fs};
fn main() {
let is_windows = env::var_os("CARGO_CFG_WINDOWS").is_some();
let is_unix = env::var_os("CARGO_CFG_UNIX").is_some();
let is_deterministic = env::var("CARGO_FEATURE_DETERMINISTIC").is_ok();
let is_debug_renderer = env::var("CARGO_FEATURE_DEBUG_RENDERER").is_ok();
let is_profile = env::var("CARGO_FEATURE_PROFILE").is_ok();
let mut rs_file = vec!["src/base.rs", "src/layer.rs", "src/shape.rs", "src/system.rs", "src/character.rs"];
if is_windows && is_debug_renderer {
rs_file.push("src/debug.rs");
}
let mut cpp_file = vec!["src/shape.cpp", "src/system.cpp", "src/character.cpp"];
if is_windows && is_debug_renderer {
cpp_file.push("src/debug.cpp");
}
let mut cxx = cxx_build::bridges(&rs_file);
cxx.cpp(true)
.std("c++17")
.static_crt(false)
.files(&cpp_file)
.include("./JoltPhysics")
.files(&list_source_files("./JoltPhysics/Jolt"))
.define("JPH_DISABLE_CUSTOM_ALLOCATOR", "1")
.define("NDEBUG", "1")
.define("JPH_USE_AVX2", "1")
.define("JPH_USE_AVX", "1")
.define("JPH_USE_SSE4_1", "1")
.define("JPH_USE_SSE4_2", "1")
.define("JPH_USE_LZCNT", "1")
.define("JPH_USE_TZCNT", "1")
.define("JPH_USE_F16C", "1")
.flag_if_supported("-march=native");
if is_deterministic {
cxx.flag_if_supported("/fp:precise")
.flag_if_supported("-ffp-model=precise")
.flag_if_supported("-ffp-contract=off")
.define("JPH_CROSS_PLATFORM_DETERMINISTIC", "1");
}
if is_profile {
cxx.define("JPH_PROFILE_ENABLED", "1");
}
if is_windows && is_debug_renderer {
cxx.include("./JoltPhysics/TestFramework")
.files(&list_source_files("./JoltPhysics/TestFramework"))
.define("JPH_DEBUG_RENDERER", "1");
}
if is_windows {
#[cfg(windows)]
cxx.includes(vcvars::Vcvars::new().get("INCLUDE").unwrap().split(';'))
.define("JPH_COMPILER_MSVC", "1")
.flag_if_supported("/arch:AVX512")
.flag_if_supported("/arch:AVX2")
.flag_if_supported("/arch:AVX");
println!("cargo:rustc-link-lib=User32");
println!("cargo:rustc-link-lib=gdi32");
println!("cargo:rustc-link-lib=Shcore");
println!("cargo:rustc-link-lib=DXGI");
println!("cargo:rustc-link-lib=D3D12");
println!("cargo:rustc-link-lib=d3dcompiler");
println!("cargo:rustc-link-lib=Dinput8");
println!("cargo:rustc-link-lib=dxguid");
}
if is_unix {
cxx.flag_if_supported("-mavx2")
.flag_if_supported("-mbmi")
.flag_if_supported("-mpopcnt")
.flag_if_supported("-mlzcnt")
.flag_if_supported("-mf16c")
.flag_if_supported("-msse4.2")
.flag_if_supported("-msse4.1")
.flag_if_supported("-msse2");
}
cxx.compile("jolt-physics-rs");
}
fn list_source_files<P: AsRef<Path>>(dir: P) -> Vec<String> {
let mut files = Vec::new();
for entry in fs::read_dir(dir).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
if path.is_file() {
let path = path.to_str().unwrap().to_string();
if path.ends_with(".cpp") || path.ends_with(".cc") {
files.push(path);
}
} else if path.is_dir() {
files.extend(list_source_files(path));
}
}
return files;
}