This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.rs
169 lines (142 loc) · 3.84 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
extern crate cc;
use std::env;
use cc::{Build, Tool};
fn build_new() -> (Build, Tool) {
let build = Build::new();
let tool = build.try_get_compiler().unwrap();
(build, tool)
}
fn select_sokol_gfx_renderer(build: &mut Build, is_msvc: bool, is_impl: bool) {
//
// select sokol_gfx renderer, defaults to:
// - Windows: D3D11 with MSVC, GLCORE33 otherwise
// - MacOS: Metal
// - Linux: GLCORE33
//
if cfg!(target_os = "windows") && is_msvc {
build.flag("-DSOKOL_D3D11");
} else if cfg!(target_os = "macos") {
build.flag("-DSOKOL_METAL");
} else {
build.flag("-DSOKOL_GLCORE33");
}
if is_impl {
if cfg!(target_os = "windows") && is_msvc {
println!("cargo:rustc-cfg=gfx=\"d3d11\"");
} else if cfg!(target_os = "macos") {
println!("cargo:rustc-cfg=gfx=\"metal\"");
} else {
println!("cargo:rustc-cfg=gfx=\"glcore33\"");
}
}
}
fn make_sokol() {
let (mut build, tool) = build_new();
let is_debug = env::var("DEBUG").ok().is_some();
let is_msvc = tool.is_like_msvc();
//
// include paths
//
build
.include("external/sokol");
//
// MacOS: need ARC, so compile sokol.m with -fobjc-arc
//
if cfg!(target_os = "macos") {
build
.flag("-fobjc-arc")
.file("src/sokol.m");
} else {
build
.file("src/sokol.c");
}
//
// select sokol_gfx renderer
//
select_sokol_gfx_renderer(&mut build, is_msvc, true);
//
// silence some warnings
//
build
.flag_if_supported("-Wno-unused-parameter");
//
// x86_64-pc-windows-gnu: additional compile/link flags
//
if cfg!(target_os = "windows") {
if !is_msvc {
build
.flag("-D_WIN32_WINNT=0x0601")
.flag_if_supported("-Wno-cast-function-type")
.flag_if_supported("-Wno-sign-compare")
.flag_if_supported("-Wno-unknown-pragmas");
println!("cargo:rustc-link-lib=dylib=gdi32");
println!("cargo:rustc-link-lib=dylib=ole32");
}
}
if is_debug {
build
.flag("-D_DEBUG")
.flag("-DSOKOL_DEBUG");
}
build
.compile("sokol-sys");
//
// MacOS: frameworks
//
if cfg!(target_os = "macos") {
println!("cargo:rustc-link-lib=framework=Cocoa");
println!("cargo:rustc-link-lib=framework=QuartzCore");
println!("cargo:rustc-link-lib=framework=Metal");
println!("cargo:rustc-link-lib=framework=MetalKit");
println!("cargo:rustc-link-lib=framework=AudioToolbox");
}
//
// Linux: libs
//
if cfg!(target_os = "linux") {
println!("cargo:rustc-link-lib=dylib=GL");
println!("cargo:rustc-link-lib=dylib=X11");
println!("cargo:rustc-link-lib=dylib=asound");
}
}
fn make_sokol_imgui() {
let (mut build, tool) = build_new();
let is_msvc = tool.is_like_msvc();
//
// include paths
//
build
.include("external/imgui")
.include("external/sokol")
.include("external/sokol/util");
//
// source files
//
build.files(&[
"src/imgui.cc",
"src/sokol_imgui.cc",
"external/imgui/imgui.cpp",
"external/imgui/imgui_demo.cpp",
"external/imgui/imgui_draw.cpp",
"external/imgui/imgui_tables.cpp",
"external/imgui/imgui_widgets.cpp"
]);
//
// select sokol_gfx renderer
//
select_sokol_gfx_renderer(&mut build, is_msvc, false);
//
// silence some warnings
//
build
.flag_if_supported("-Wno-unused-parameter");
build
.flag_if_supported("-std=c++11");
build
.cpp(true)
.compile("sokol-sys-imgui");
}
fn main() {
make_sokol();
make_sokol_imgui();
}