Debian Codegraph @

third_party/dawn/BUILD.gn

raw
1 # Copyright 2025 Google LLC.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 # These rules invoke Python scripts to build Tint and Dawn using CMake. We use
6 # CMake instead of the GN rules because Dawn/Tint's GN rules require Chromium's
7 # toolchain, which we, Skia, do not want to have a dependency on.
8 # The result is a single static library that can be linked into Skia.
9
10 import("//third_party/dawn/args.gni")
11
12 if (is_win) {
13 # On Windows, the normal cc/cxx variables are just "clang" and "clang++"
14 # which are not found in the path. CMake needs the full path.
15 if (is_clang) {
16 assert(clang_win != "",
17 "clang_win must be set when is_clang is true on Windows")
18 _cc = "$clang_win/bin/clang-cl.exe"
19 _cxx = "$clang_win/bin/clang-cl.exe"
20 } else {
21 _cc = "$win_vc/Tools/MSVC/$win_toolchain_version/bin/HostX64/$target_cpu/cl.exe"
22 _cxx = "$win_vc/Tools/MSVC/$win_toolchain_version/bin/HostX64/$target_cpu/cl.exe"
23 }
24 _dawn_lib_name = "dawn_combined.lib"
25 _tint_lib_name = "tint_combined.lib"
26 } else {
27 _cc = cc
28 _cxx = cxx
29 _dawn_lib_name = "libdawn_combined.a"
30 _tint_lib_name = "libtint_combined.a"
31 }
32
33 config("tint_api_config") {
34 if (!is_wasm) {
35 include_dirs = [
36 "../externals/dawn",
37 "../externals/dawn/include",
38 ]
39 } else {
40 # Emscripten includes its own WebGPU headers.
41 include_dirs = []
42 }
43
44 defines = [
45 "TINT_BUILD_WGSL_READER=1",
46 "TINT_BUILD_WGSL_WRITER=1",
47 ]
48
49 # The build script produces a static library for tint in the root output directory.
50 libs = [ "$root_out_dir/$_tint_lib_name" ]
51 }
52
53 # This version of tint is used by skslc, which is used to compile our sksl tests.
54 # Thus, we do *not* want to pass in the sanitizer args to this target. When
55 # we build the dawn target below, that will build a new version of tint which
56 # does use the passed in sanitizer flags.
57 action("tint_cmake") {
58 script = "build_tint.py"
59
60 sources = [
61 "build_tint.py",
62 "cmake_utils.py",
63 ]
64
65 # The script will place the final library in this location.
66 outputs = [ "$root_out_dir/${_tint_lib_name}" ]
67
68 # The script also generates a depfile that lists all of Tint's sources. This
69 # allows Ninja to know when to re-run the build script.
70 depfile = "$target_gen_dir/${_tint_lib_name}.d"
71
72 if (get_label_info(current_toolchain, "name") == host_toolchain) {
73 _tint_build_dir = "cmake_tint_host"
74 } else {
75 _tint_build_dir = "cmake_tint"
76 }
77 args = [
78 "--cc=" + _cc,
79 "--cxx=" + _cxx,
80 "--output_path=" + rebase_path(outputs[0], root_build_dir),
81 "--depfile_path=" + rebase_path(depfile, root_build_dir),
82 "--target_os=" + host_os,
83 "--target_cpu=" + host_cpu,
84 "--build_dir=" + _tint_build_dir,
85 ]
86 if (is_clang) {
87 args += [ "--is_clang" ]
88 }
89
90 if (is_debug && !is_win) {
91 # Skia's GN toolchain for Windows doesn't set build_type to be Debug
92 # and if Dawn does, that is a mismatch of _ITERATOR_DEBUG_LEVEL
93 args += [
94 "--build_type=Debug",
95
96 # For performance, set O1 optimization.
97 "--cxx_flags=-O1",
98 ]
99 } else {
100 args += [ "--build_type=Release" ]
101 }
102 if (is_win) {
103 args += [
104 "--win_sdk=" + win_sdk,
105 "--win_sdk_version=" + win_sdk_version,
106 "--win_vc=" + win_vc,
107 "--win_toolchain_version=" + win_toolchain_version,
108 ]
109 }
110
111 # While we don't need to build tint with our sanitizers, we do need to adjust our target version
112 # of tint to be built with libc++ if we have set the rest of Skia to be using that.
113 if (get_label_info(current_toolchain, "name") != host_toolchain) {
114 if (is_linux && sanitize != "") {
115 args += [
116 "--cxx_flags=-stdlib=libc++",
117 "--ld_flags=-stdlib=libc++",
118 ]
119 }
120 if (sanitize == "ASAN") {
121 # See Skia's GN config("no_rtti")
122 args += [ "--enable_rtti" ]
123 }
124 }
125 }
126
127 group("tint") {
128 deps = [ ":tint_cmake" ]
129
130 public_configs = [ ":tint_api_config" ]
131 }
132
133 config("dawn_api_config") {
134 if (!is_wasm) {
135 include_dirs = [
136 "../externals/dawn",
137 "../externals/dawn/include",
138 "$target_gen_dir/include",
139 ]
140 } else {
141 # Emscripten includes its own WebGPU headers.
142 include_dirs = []
143 }
144 if (is_win) {
145 ldflags = [ "/WHOLEARCHIVE:dawn_combined.lib" ]
146 libs = [
147 "onecore.lib",
148 "user32.lib",
149 "delayimp.lib",
150 "dxguid.lib",
151 "libcpmt.lib",
152 ]
153 } else {
154 libs = []
155 }
156 libs += [ "$root_out_dir/$_dawn_lib_name" ]
157
158 # https://dawn.googlesource.com/dawn/+/647c352f57aa8a4c2666258455158a36c0c385af/src/dawn/native/BUILD.gn#645
159 if (is_mac || is_ios) {
160 frameworks = [
161 "Foundation.framework",
162 "IOSurface.framework",
163 "IOKit.framework",
164 "Metal.framework",
165 "QuartzCore.framework",
166 "Cocoa.framework",
167 ]
168 }
169 }
170
171 sanitizer_args = []
172 if (sanitize != "") {
173 assert(is_clang, "Need to update GN rules to handle non-Clang Sanitizer")
174 sanitizers = ""
175 if (sanitize == "ASAN") {
176 sanitizers = "undefined,address,float-divide-by-zero"
177 if (is_android) {
178 sanitizers = "address"
179 }
180 if (!is_win) {
181 # See Skia's GN config("no_rtti")
182 sanitizer_args += [ "--enable_rtti" ]
183 }
184 } else if (sanitize == "TSAN") {
185 sanitizers = "thread"
186 } else {
187 assert(false, "Unsupported sanitizer option")
188 }
189
190 _suppressions = rebase_path("../../tools/xsan.supp")
191
192 cxx_flags = [
193 "-fsanitize=$sanitizers",
194 "-fno-sanitize-recover=$sanitizers",
195 "-fsanitize-blacklist=$_suppressions",
196 "-fno-omit-frame-pointer",
197 ]
198 ld_flags = [ "-fsanitize=$sanitizers" ]
199
200 if (is_linux) {
201 cxx_flags += [ "-stdlib=libc++" ]
202 ld_flags += [ "-stdlib=libc++" ]
203 }
204
205 foreach(flag, cxx_flags) {
206 sanitizer_args += [ "--cxx_flags=" + flag ]
207 }
208 foreach(flag, ld_flags) {
209 sanitizer_args += [ "--ld_flags=" + flag ]
210 }
211 }
212
213 action("dawn_cmake") {
214 script = "build_dawn.py"
215
216 sources = [
217 "build_dawn.py",
218 "cmake_utils.py",
219 ]
220
221 outputs = [ "$root_out_dir/${_dawn_lib_name}" ]
222
223 depfile = "$target_gen_dir/${_dawn_lib_name}.d"
224
225 args = [
226 "--cc=" + _cc,
227 "--cxx=" + _cxx,
228 "--output_path=" + rebase_path(outputs[0], root_build_dir),
229 "--depfile_path=" + rebase_path(depfile, root_build_dir),
230 "--gen_dir=" + rebase_path(target_gen_dir, root_build_dir),
231 "--target_os=" + target_os,
232 "--target_cpu=" + target_cpu,
233 "--build_dir=cmake_dawn",
234 ]
235 if (is_clang) {
236 args += [ "--is_clang" ]
237 }
238 if (is_debug && !is_win) {
239 args += [
240 "--build_type=Debug",
241
242 # For performance, set O1 optimization.
243 "--cxx_flags=-O1",
244 ]
245 } else {
246 args += [ "--build_type=Release" ]
247 }
248 if (is_win) {
249 args += [
250 "--win_sdk=" + win_sdk,
251 "--win_sdk_version=" + win_sdk_version,
252 "--win_vc=" + win_vc,
253 "--win_toolchain_version=" + win_toolchain_version,
254 ]
255 }
256 if (is_android) {
257 args += [
258 "--android_ndk_path=" + ndk,
259 "--android_platform=android-" + ndk_api,
260 ]
261 }
262
263 if (dawn_enable_d3d11) {
264 args += [ "--dawn_enable_d3d11=true" ]
265 } else {
266 args += [ "--dawn_enable_d3d11=false" ]
267 }
268 if (dawn_enable_d3d12) {
269 args += [ "--dawn_enable_d3d12=true" ]
270 } else {
271 args += [ "--dawn_enable_d3d12=false" ]
272 }
273 if (dawn_enable_opengles) {
274 args += [ "--dawn_enable_opengles=true" ]
275 } else {
276 args += [ "--dawn_enable_opengles=false" ]
277 }
278 if (dawn_enable_metal) {
279 args += [ "--dawn_enable_metal=true" ]
280 } else {
281 args += [ "--dawn_enable_metal=false" ]
282 }
283 if (dawn_enable_vulkan) {
284 args += [ "--dawn_enable_vulkan=true" ]
285 } else {
286 args += [ "--dawn_enable_vulkan=false" ]
287 }
288
289 args += sanitizer_args
290 }
291
292 group("dawn") {
293 public_deps = [ ":dawn_cmake" ]
294
295 public_configs = [ ":dawn_api_config" ]
296 }