forked from gwihlidal/meshopt-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
80 lines (69 loc) · 2.41 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
use std::env;
fn main() {
let mut build = cc::Build::new();
build.include("src");
// Add the files we build
let source_files = [
"vendor/src/allocator.cpp",
"vendor/src/clusterizer.cpp",
"vendor/src/indexcodec.cpp",
"vendor/src/indexgenerator.cpp",
"vendor/src/overdrawanalyzer.cpp",
"vendor/src/overdrawoptimizer.cpp",
"vendor/src/simplifier.cpp",
"vendor/src/spatialorder.cpp",
"vendor/src/stripifier.cpp",
"vendor/src/vcacheanalyzer.cpp",
"vendor/src/vcacheoptimizer.cpp",
"vendor/src/vertexcodec.cpp",
"vendor/src/vfetchanalyzer.cpp",
"vendor/src/vfetchoptimizer.cpp",
];
for source_file in &source_files {
build.file(source_file);
}
let target = env::var("TARGET").unwrap();
if target.contains("darwin") {
build
.flag("-std=c++11")
.cpp_link_stdlib("c++")
.cpp_set_stdlib("c++")
.cpp(true);
} else if target.contains("linux") || target.contains("windows-gnu") {
build.flag("-std=c++11").cpp_link_stdlib("stdc++").cpp(true);
}
if target.starts_with("wasm32") {
// In webassembly there's no stdlib, so we use
// our own stripped down headers to provide the few
// functions needed via LLVM intrinsics.
build.flag("-isystem").flag("include_wasm32");
// The Wasm backend needs a compatible ar
// which will most likely be available under
// this name on Windows, via manual LLVM install
let host = env::var("HOST").unwrap();
if host.contains("windows") {
build.archiver("llvm-ar");
}
}
build.compile("meshopt_cpp");
generate_bindings("gen/bindings.rs");
}
#[cfg(feature = "generate_bindings")]
fn generate_bindings(output_file: &str) {
let bindings = bindgen::Builder::default()
.header("vendor/src/meshoptimizer.h")
.derive_debug(true)
.impl_debug(true)
.blocklist_type("__darwin_.*")
.allowlist_function("meshopt.*")
.trust_clang_mangling(false)
.layout_tests(false)
.size_t_is_usize(true)
.generate()
.expect("Unable to generate bindings!");
bindings
.write_to_file(std::path::Path::new(output_file))
.expect("Unable to write bindings!");
}
#[cfg(not(feature = "generate_bindings"))]
fn generate_bindings(_: &str) {}