-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.rs
70 lines (60 loc) · 2.14 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
use std::env;
use std::fs;
use std::path::Path;
fn main() {
// OUT_DIR is set by Cargo during a build.
let out_dir = env::var("OUT_DIR").unwrap();
println!("OUT_DIR = {}", out_dir);
// Root folder where we will build pixel game engine.
let root = Path::new(&out_dir);
// Copy C++ binding files into OUT_DIR to build a library.
fs::copy("cpp/olcPixelGameEngine.h", root.join("olcPixelGameEngine.h")).unwrap();
fs::copy("cpp/olcRustBindingApp.h", root.join("olcRustBindingApp.h")).unwrap();
fs::copy("cpp/olcRustBindingApp.cpp", root.join("olcRustBindingApp.cpp")).unwrap();
// Build Rust binding together with olcPixelGameEngine.h.
build_rust_binding(root);
}
#[cfg(target_os = "macos")]
fn build_rust_binding(root: &Path) {
cc::Build::new()
.cpp(true)
.include("/usr/X11/include")
.flag("-std=c++17")
.flag("-Wno-delete-non-virtual-dtor") // warnings from the olcPixelGameEngine, need to be fixed upstream
.file(root.join("olcRustBindingApp.cpp"))
.warnings(false)
.compile("olcRustBindingApp");
println!("cargo:rustc-link-search={}", "/usr/X11/lib");
println!("cargo:rustc-link-lib=X11");
println!("cargo:rustc-link-lib=GL");
println!("cargo:rustc-link-lib=png");
println!("cargo:rustc-link-lib=pthread");
}
#[cfg(target_os = "linux")]
fn build_rust_binding(root: &Path) {
cc::Build::new()
.cpp(true)
.file(root.join("olcRustBindingApp.cpp"))
.warnings(false)
.compile("olcRustBindingApp");
println!("cargo:rustc-link-lib=X11");
println!("cargo:rustc-link-lib=GL");
println!("cargo:rustc-link-lib=png");
println!("cargo:rustc-link-lib=pthread");
println!("cargo:rustc-link-lib=stdc++fs");
}
#[cfg(target_os = "windows")]
fn build_rust_binding(root: &Path) {
cc::Build::new()
.cpp(true)
.file(root.join("olcRustBindingApp.cpp"))
.flag("-std:c++17")
.flag("-permissive-")
.warnings(false)
.compile("olcRustBindingApp");
}
// macos:
// g++ -o olcExampleProgram olcExampleProgram.cpp -I/usr/X11/include -L/usr/X11/lib -lX11 -lGL -lpng -lpthread -std=c++17
//
// linux:
// g++ -o olcExampleProgram olcExampleProgram.cpp -lX11 -lGL -lpthread -lpng -lstdc++fs -std=c++17