-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.rs
166 lines (151 loc) · 5.85 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
fn main() {
let mut build = cc::Build::new();
let env = std::env::var("TARGET").unwrap();
// windows includes
if env.contains("windows") {
build.include("bx/include/compat/msvc");
build.include("bgfx/3rdparty/directx-headers/include/directx");
build.flag("/Zc:__cplusplus");
} else if env.contains("darwin") {
// macOS includes
build.include("bx/include/compat/osx");
build.flag("-std=c++14");
} else if env.contains("emscripten") {
build.flag("-std=c++14");
} else {
}
// add shared include dirs
build.include("bgfx/3rdparty/khronos");
build.include("bgfx/3rdparty");
build.include("bgfx/include");
build.include("bx/include");
build.include("bx/3rdparty");
build.include("bimg/include");
build.include("bimg/3rdparty");
build.include("bimg/3rdparty/iqa/include");
build.include("bimg/3rdparty/astc-encoder/include");
build.include("bimg/3rdparty/tinyexr/deps/miniz");
// defines - Currently not supporting WebGPU, GNM
// OS support:
// Windows - DX11
// macOS - Metal
// Posix - OpenGL
// Android - OpenGL/Vulkan
// Emscripten - OpenGLES
// In the future it would be good to make this configurable instead
build.define("BGFX_CONFIG_RENDERER_WEBGPU", "0");
build.define("BGFX_CONFIG_RENDERER_GNM", "0");
// Make it optional to enable bgfx debug setting
/*
#[cfg(feature = "bgfx-debug")]
{
build.define("BX_CONFIG_DEBUG", "1");
}
#[cfg(not(feature = "bgfx-debug"))]
{
build.define("BX_CONFIG_DEBUG", "0");
}
*/
build.define("BX_CONFIG_DEBUG", "0");
// Don't include decode of ASTC to reduce code size and is unlikely a common use-case.
build.define("BIMG_DECODE_ASTC", "0");
// Never use multi-threading in emscripten
if env.contains("emscripten") {
build.define("BGFX_CONFIG_MULTITHREADED", "0");
} else {
// Optionally disable multi-threading
#[cfg(feature = "bgfx-single-threaded")]
{
build.define("BGFX_CONFIG_MULTITHREADED", "0");
}
#[cfg(not(feature = "bgfx-single-threaded"))]
{
build.define("BGFX_CONFIG_MULTITHREADED", "1");
}
}
if env.contains("windows") {
build.define("BGFX_CONFIG_RENDERER_VULKAN", "1");
build.define("BGFX_CONFIG_RENDERER_DIRECT3D11", "1");
build.define("BGFX_CONFIG_RENDERER_DIRECT3D12", "1");
build.define("BGFX_CONFIG_RENDERER_OPENGL", "1");
build.define("_WIN32", None);
build.define("_HAS_EXCEPTIONS", "0");
build.define("_SCL_SECURE", "0");
build.define("_SECURE_SCL", "0");
build.define("__STDC_LIMIT_MACROS", None);
build.define("__STDC_FORMAT_MACROS", None);
build.define("__STDC_CONSTANT_MACROS", None);
build.define("_CRT_SECURE_NO_WARNINGS", None);
build.define("_CRT_SECURE_NO_DEPRECATE", None);
build.warnings(false);
} else if env.contains("darwin") {
build.define("BGFX_CONFIG_RENDERER_VULKAN", "0");
build.define("BGFX_CONFIG_RENDERER_METAL", "1");
} else if env.contains("android") {
build.define("BGFX_CONFIG_RENDERER_VULKAN", "1");
build.define("BGFX_CONFIG_RENDERER_OPENGLES", "1");
} else if env.contains("emscripten") {
build.define("BGFX_CONFIG_RENDERER_OPENGL", "0");
build.define("BGFX_CONFIG_RENDERER_OPENGLES", "1");
} else {
build.define("BGFX_CONFIG_RENDERER_VULKAN", "1");
build.define("BGFX_CONFIG_RENDERER_OPENGL", "1");
}
// sources
build.file("bx/src/amalgamated.cpp");
build.file("bimg/src/image.cpp");
build.file("bimg/src/image_cubemap_filter.cpp");
build.file("bimg/src/image_decode.cpp");
build.file("bimg/src/image_gnf.cpp");
build.file("bgfx/src/bgfx.cpp");
build.file("bgfx/src/vertexlayout.cpp");
build.file("bgfx/src/debug_renderdoc.cpp");
build.file("bgfx/src/topology.cpp");
build.file("bgfx/src/shader.cpp");
build.file("bgfx/src/shader_dxbc.cpp");
build.file("bgfx/src/renderer_agc.cpp");
build.file("bgfx/src/renderer_gnm.cpp");
build.file("bgfx/src/renderer_webgpu.cpp");
build.file("bgfx/src/renderer_nvn.cpp");
build.file("bgfx/src/renderer_gl.cpp");
build.file("bgfx/src/renderer_vk.cpp");
build.file("bgfx/src/renderer_noop.cpp");
build.file("bgfx/src/renderer_d3d9.cpp");
build.file("bgfx/src/renderer_d3d11.cpp");
build.file("bgfx/src/renderer_d3d12.cpp");
if env.contains("windows") {
build.file("bgfx/src/glcontext_wgl.cpp");
build.file("bgfx/src/nvapi.cpp");
build.file("bgfx/src/dxgi.cpp");
build.file("bgfx/src/shader_dx9bc.cpp");
build.file("bgfx/src/shader_spirv.cpp");
} else if env.contains("darwin") {
build.file("bgfx/src/renderer_mtl.mm");
} else if env.contains("android") {
build.file("bgfx/src/glcontext_egl.cpp");
} else if env.contains("emscripten") {
build.file("bgfx/src/glcontext_html5.cpp");
} else {
build.file("bgfx/src/glcontext_egl.cpp");
build.cpp_link_stdlib("stdc++");
}
build.compile("bgfx_sys");
// linker stuff
if env.contains("windows") {
// todo fixme
} else if env.contains("darwin") {
println!("cargo:rustc-link-lib=framework=Metal");
println!("cargo:rustc-link-lib=framework=MetalKit");
println!("cargo:rustc-link-lib=c++");
} else if env.contains("android") {
println!("cargo:rustc-link-lib=c++_shared");
println!("cargo:rustc-link-lib=GLESv1_CM");
println!("cargo:rustc-link-lib=GLESv2");
println!("cargo:rustc-link-lib=EGL");
} else {
println!("cargo:rustc-link-lib=pthread");
println!("cargo:rustc-link-lib=stdc++");
println!("cargo:rustc-link-lib=GL");
println!("cargo:rustc-link-lib=X11");
}
}