blob: 9aaa47b4f729fe4ac782ece817082f97bb81bb8e [file] [log] [blame]
Austin Engcc2516a2023-10-17 20:57:54 +00001# Copyright 2021 The Dawn & Tint Authors
Ryan Harrisondbc13af2022-02-21 15:19:07 +00002#
Austin Engcc2516a2023-10-17 20:57:54 +00003# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions are met:
Ryan Harrisondbc13af2022-02-21 15:19:07 +00005#
Austin Engcc2516a2023-10-17 20:57:54 +00006# 1. Redistributions of source code must retain the above copyright notice, this
7# list of conditions and the following disclaimer.
Ryan Harrisondbc13af2022-02-21 15:19:07 +00008#
Austin Engcc2516a2023-10-17 20:57:54 +00009# 2. Redistributions in binary form must reproduce the above copyright notice,
10# this list of conditions and the following disclaimer in the documentation
11# and/or other materials provided with the distribution.
12#
13# 3. Neither the name of the copyright holder nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Ryan Harrisondbc13af2022-02-21 15:19:07 +000027
Ben Clayton7d81e552023-08-17 12:01:50 +000028# GEN_BUILD:DO_NOT_GENERATE - Don't regenerate this file with `./tools run gen`
29
Ryan Harrisondbc13af2022-02-21 15:19:07 +000030import("//build_overrides/build.gni")
Dan Sinclair5ae03c22022-11-03 14:25:37 +000031
dan sinclair2fe7f192023-03-07 18:20:23 +000032import("../../scripts/dawn_overrides_with_defaults.gni")
Ben Clayton66630762023-08-18 08:29:51 +000033import("../../scripts/tint_overrides_with_defaults.gni")
Ryan Harrisondbc13af2022-02-21 15:19:07 +000034
dan sinclair77bf2332022-06-22 12:40:43 +000035if (tint_build_unittests) {
36 import("//testing/test.gni")
37}
38
Ben Clayton7d81e552023-08-17 12:01:50 +000039import("tint.gni")
40
Ryan Harrisondbc13af2022-02-21 15:19:07 +000041###############################################################################
42# Common - Configs, etc. shared across targets
43###############################################################################
44
Ben Clayton44a29b52023-12-04 14:55:01 +000045# tint_gen_dir is the relative path of tint_root_dir to '//', under root_gen_dir
46tint_gen_dir = "${root_gen_dir}/" + rebase_path("${tint_root_dir}", "//")
47
Ryan Harrisondbc13af2022-02-21 15:19:07 +000048config("tint_common_config") {
49 include_dirs = [
Ben Clayton44a29b52023-12-04 14:55:01 +000050 "${tint_root_dir}",
51 "${tint_gen_dir}",
Ryan Harrisondbc13af2022-02-21 15:19:07 +000052 ]
Arthur Sonzogni3aaa0a32024-05-31 14:01:04 +000053
54 # Some versions of MSVC ignores the [[noreturn]] on ~InternalCompilerError(),
55 # triggering a warning if it is the last statement on a function that has a
56 # return value.
57 if (!is_clang && is_win) {
58 cflags = [ "/wd4715" ]
59 }
Ryan Harrisondbc13af2022-02-21 15:19:07 +000060}
61
62config("tint_public_config") {
63 defines = []
64 if (tint_build_spv_reader) {
65 defines += [ "TINT_BUILD_SPV_READER=1" ]
66 } else {
67 defines += [ "TINT_BUILD_SPV_READER=0" ]
68 }
69
70 if (tint_build_spv_writer) {
71 defines += [ "TINT_BUILD_SPV_WRITER=1" ]
72 } else {
73 defines += [ "TINT_BUILD_SPV_WRITER=0" ]
74 }
75
76 if (tint_build_wgsl_reader) {
77 defines += [ "TINT_BUILD_WGSL_READER=1" ]
78 } else {
79 defines += [ "TINT_BUILD_WGSL_READER=0" ]
80 }
81
82 if (tint_build_wgsl_writer) {
83 defines += [ "TINT_BUILD_WGSL_WRITER=1" ]
84 } else {
85 defines += [ "TINT_BUILD_WGSL_WRITER=0" ]
86 }
87
88 if (tint_build_msl_writer) {
89 defines += [ "TINT_BUILD_MSL_WRITER=1" ]
90 } else {
91 defines += [ "TINT_BUILD_MSL_WRITER=0" ]
92 }
93
94 if (tint_build_hlsl_writer) {
95 defines += [ "TINT_BUILD_HLSL_WRITER=1" ]
96 } else {
97 defines += [ "TINT_BUILD_HLSL_WRITER=0" ]
98 }
99
100 if (tint_build_glsl_writer) {
101 defines += [ "TINT_BUILD_GLSL_WRITER=1" ]
102 } else {
103 defines += [ "TINT_BUILD_GLSL_WRITER=0" ]
104 }
105
Ben Claytonf1b8a012023-10-11 17:15:52 +0000106 if (tint_build_glsl_validator) {
107 defines += [ "TINT_BUILD_GLSL_VALIDATOR=1" ]
108 } else {
109 defines += [ "TINT_BUILD_GLSL_VALIDATOR=0" ]
110 }
111
dan sinclair0917fbb2023-03-07 18:28:38 +0000112 if (tint_build_syntax_tree_writer) {
113 defines += [ "TINT_BUILD_SYNTAX_TREE_WRITER=1" ]
114 } else {
115 defines += [ "TINT_BUILD_SYNTAX_TREE_WRITER=0" ]
116 }
117
Ryan Harrison724dd782024-05-16 16:27:48 +0000118 if (tint_build_ir_binary) {
119 defines += [ "TINT_BUILD_IR_BINARY=1" ]
120 } else {
121 defines += [ "TINT_BUILD_IR_BINARY=0" ]
122 }
123
Ben Clayton5e1a2a02024-06-05 21:34:28 +0000124 if (tint_build_ir_fuzzer) {
125 defines += [ "TINT_BUILD_IR_FUZZER=1" ]
126 } else {
127 defines += [ "TINT_BUILD_IR_FUZZER=0" ]
128 }
129
Ben Clayton5c69ff42023-11-23 13:32:36 +0000130 if (tint_build_is_win) {
131 defines += [ "TINT_BUILD_IS_WIN=1" ]
132 } else {
133 defines += [ "TINT_BUILD_IS_WIN=0" ]
134 }
135
136 if (tint_build_is_mac) {
137 defines += [ "TINT_BUILD_IS_MAC=1" ]
138 } else {
139 defines += [ "TINT_BUILD_IS_MAC=0" ]
140 }
141
142 if (tint_build_is_linux) {
143 defines += [ "TINT_BUILD_IS_LINUX=1" ]
144 } else {
145 defines += [ "TINT_BUILD_IS_LINUX=0" ]
146 }
147
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000148 include_dirs = [
149 "${tint_root_dir}/",
150 "${tint_root_dir}/include/",
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000151 ]
152}
153
154config("tint_config") {
155 include_dirs = []
156 if (tint_build_spv_reader || tint_build_spv_writer) {
157 include_dirs += [ "${tint_spirv_tools_dir}/include/" ]
158 }
159}
160
James Price5976efe2024-05-07 13:48:43 +0000161source_set("dl") {
162 # GN doesn't appear to need to depend on any dl libraries.
163}
164
Ben Clayton30b420d2023-08-22 10:30:58 +0000165source_set("thread") {
166 # GN doesn't appear to need to depend on any thread libraries.
167}
168
Ben Claytone977f542023-08-22 10:30:58 +0000169source_set("metal") {
170 frameworks = [
Ben Clayton89b98282023-09-05 16:28:13 +0000171 "CoreGraphics.framework",
Ben Claytone977f542023-08-22 10:30:58 +0000172 "Foundation.framework",
173 "Metal.framework",
174 ]
175}
176
Ben Clayton7d81e552023-08-17 12:01:50 +0000177config("tint_unittests_config") {
178 include_dirs = [
179 "${tint_googletest_dir}/googlemock/include",
180 "${tint_googletest_dir}/googletest/include",
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000181 ]
182
Ben Clayton7d81e552023-08-17 12:01:50 +0000183 configs = [
184 ":tint_common_config",
185 ":tint_public_config",
dan sinclair2da119a2023-01-25 18:39:00 +0000186 ]
187
Ben Clayton7d81e552023-08-17 12:01:50 +0000188 if (is_win && is_debug) {
189 # TODO(crbug.com/tint/1749): both msvc and clang builds stack overflow on debug builds.
190 # Increase the initial stack size to 4 MB (default is 1MB).
191 ldflags = [ "/STACK:4194304" ]
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000192 }
193}
dan sinclair889a4992022-06-17 13:01:59 +0000194
dan sinclair77bf2332022-06-22 12:40:43 +0000195if (tint_build_unittests) {
196 ###############################################################################
197 # Gtest Gmock - Handle building inside and outside of Chromium.
198 ###############################################################################
199 # When building outside of Chromium we need to define our own targets for GTest
200 # and GMock. However when compiling inside of Chromium we need to reuse the
201 # existing targets, both because Chromium has a special harness for swarming
202 # and because otherwise the "gn check" fails.
dan sinclair889a4992022-06-17 13:01:59 +0000203
Ben Clayton7d81e552023-08-17 12:01:50 +0000204 if (build_with_chromium) {
205 # When we are in Chromium we reuse its targets, and also add some deps that
206 # are needed to launch the test in swarming mode.
207 group("gmock_and_gtest") {
208 testonly = true
209 public_deps = [
210 "//base",
211 "//base/test:test_support",
212 "//testing/gmock",
213 "//testing/gtest",
214 "//third_party/googletest:gmock",
215 ]
216 }
217 } else {
dan sinclair77bf2332022-06-22 12:40:43 +0000218 # When we aren't in Chromium we define out own targets based on the location
219 # of the googletest repo.
220 config("gtest_config") {
221 include_dirs = [
222 "${tint_googletest_dir}/googletest",
223 "${tint_googletest_dir}/googletest/include",
224 ]
225 }
226 static_library("gtest") {
227 testonly = true
228 sources = [ "${tint_googletest_dir}/googletest/src/gtest-all.cc" ]
229 public_configs = [ ":gtest_config" ]
230 }
231
232 config("gmock_config") {
233 include_dirs = [
234 "${tint_googletest_dir}/googlemock",
235 "${tint_googletest_dir}/googlemock/include",
236 "${tint_googletest_dir}/googletest/include",
237 ]
238 }
239
240 static_library("gmock") {
241 testonly = true
242 sources = [ "${tint_googletest_dir}/googlemock/src/gmock-all.cc" ]
243 public_configs = [ ":gmock_config" ]
244 }
245
246 group("gmock_and_gtest") {
247 testonly = true
248 public_deps = [
249 ":gmock",
250 ":gtest",
251 ]
252 }
dan sinclair889a4992022-06-17 13:01:59 +0000253 }
Ben Clayton7d81e552023-08-17 12:01:50 +0000254}
dan sinclair77bf2332022-06-22 12:40:43 +0000255
Ben Clayton9d1b6102023-09-29 12:12:48 +0000256if (tint_build_benchmarks) {
257 group("google_benchmark") {
258 testonly = true
Ben Clayton089347a2023-09-30 04:19:28 +0000259 public_deps = [ "//third_party/google_benchmark" ]
Ben Clayton9d1b6102023-09-29 12:12:48 +0000260 }
James Priceb7b04632024-08-28 15:19:21 +0000261 action("generate_benchmark_inputs") {
262 generated_header_relpath = "gen/src/tint/cmd/bench/benchmark_inputs.h"
263 generated_header_abspath = "${root_build_dir}/${generated_header_relpath}"
264 outputs = [ generated_header_abspath ]
265 script = "${tint_src_dir}/cmd/bench/generate_benchmark_inputs.py"
266 depfile = "${generated_header_abspath}.d"
267 args = [
268 "header",
269 rebase_path(root_build_dir, root_build_dir),
270 generated_header_relpath,
271 ]
272 }
Ben Clayton9d1b6102023-09-29 12:12:48 +0000273}
274
Ben Clayton7d81e552023-08-17 12:01:50 +0000275group("abseil") {
Geoff Langd32858a2024-05-10 19:30:23 +0000276 # When building within Chromium or ANGLE we need to include "//third_party/abseil-cpp:absl" while
Ben Clayton7d81e552023-08-17 12:01:50 +0000277 # it's beneficial to be more specific with standalone Dawn, especially when it comes to
278 # including it as a dependency in other projects (such as Skia).
Geoff Langd32858a2024-05-10 19:30:23 +0000279 if (build_with_chromium || build_with_angle) {
Ben Clayton7d81e552023-08-17 12:01:50 +0000280 public_deps = [ "$dawn_abseil_dir:absl" ]
281 } else {
Geoff Langed672dd2024-04-29 14:26:28 +0000282 public_deps = [ "${dawn_root}/third_party/gn/abseil-cpp:strings" ]
dan sinclair77bf2332022-06-22 12:40:43 +0000283 }
Ben Clayton7d81e552023-08-17 12:01:50 +0000284}
dan sinclair77bf2332022-06-22 12:40:43 +0000285
dan sinclair46bd2e12023-08-21 20:47:36 +0000286source_set("winsock") {
287 libs = [ "ws2_32.lib" ]
288}
289
Antonio Maiorano4ac690d2024-05-01 17:56:33 +0000290config("dxc-include-config") {
291 include_dirs = [ "${dawn_dxc_dir}/include" ]
292}
293source_set("dxc-include") {
294 public_configs = [ ":dxc-include-config" ]
295}
296
Antonio Maiorano49be28e2024-06-19 02:11:43 +0000297source_set("dxcompiler-for-fuzzer") {
James Price92f1ed32024-06-21 17:58:59 +0000298 if (defined(use_libfuzzer) && use_libfuzzer &&
299 (is_win || is_linux || is_mac) && target_cpu != "x86") {
Antonio Maiorano49be28e2024-06-19 02:11:43 +0000300 public_deps = [ "${dawn_dxc_dir}/../gn/dxc:dxcompiler" ]
301 }
302}
303
Ben Clayton7d81e552023-08-17 12:01:50 +0000304###############################################################################
Ben Clayton6ab54622023-10-02 18:40:36 +0000305# Fuzzers
306###############################################################################
Jim Van Verthac724992023-10-06 17:21:52 +0000307if (tint_has_fuzzers) {
308 action("tint_generate_wgsl_corpus") {
309 script = "${tint_src_dir}/cmd/fuzz/wgsl/generate_wgsl_corpus.py"
Ryan Harrisonc7d42052024-05-22 04:38:49 +0000310 sources = [ "${script}" ]
Jim Van Verthac724992023-10-06 17:21:52 +0000311 args = [
312 "--stamp=" + rebase_path(fuzzer_corpus_wgsl_stamp, root_build_dir),
313 rebase_path("${tint_root_dir}/test", root_build_dir),
314 rebase_path(fuzzer_corpus_wgsl_dir, root_build_dir),
315 ]
316 outputs = [ fuzzer_corpus_wgsl_stamp ]
317 }
Ryan Harrisonc7d42052024-05-22 04:38:49 +0000318
Ben Clayton5e1a2a02024-06-05 21:34:28 +0000319 if (tint_build_ir_fuzzer) {
320 if (tint_build_cmds && tint_build_wgsl_reader && tint_build_ir_binary) {
Ryan Harrisonc7d42052024-05-22 04:38:49 +0000321 action("tint_generate_ir_corpus") {
Ryan Harrison7a53b7c2024-06-27 20:10:18 +0000322 script = "${tint_src_dir}/cmd/fuzz/ir/generate_ir_corpus.py"
Ryan Harrisonc7d42052024-05-22 04:38:49 +0000323 sources = [ "${script}" ]
Ryan Harrisonf57533d2024-06-26 02:01:24 +0000324 deps = [ "${tint_src_dir}/cmd/fuzz/ir/as" ]
Ryan Harrisonc7d42052024-05-22 04:38:49 +0000325 args = [
326 "--stamp=" + rebase_path(fuzzer_corpus_ir_stamp, root_build_dir),
Ryan Harrisonf57533d2024-06-26 02:01:24 +0000327 rebase_path("${root_build_dir}/ir_fuzz_as", root_build_dir),
Ryan Harrisonc7d42052024-05-22 04:38:49 +0000328 rebase_path("${tint_root_dir}/test", root_build_dir),
329 rebase_path(fuzzer_corpus_ir_dir, root_build_dir),
330 ]
331 outputs = [ fuzzer_corpus_ir_stamp ]
332 }
333 }
334 }
Ben Clayton6ab54622023-10-02 18:40:36 +0000335}
336
337###############################################################################
Ben Claytond283e952023-10-10 15:30:56 +0000338# Groups
339###############################################################################
340group("libs") {
341 deps = [ "${tint_src_dir}/api" ]
342}
343
344group("cmds") {
Ben Clayton49a564c2023-10-11 16:04:52 +0000345 deps = []
346 if (tint_build_cmds) {
347 deps += [
Ben Claytonb383cf02023-11-11 19:13:28 +0000348 "${tint_src_dir}/cmd/info",
Ben Clayton49a564c2023-10-11 16:04:52 +0000349 "${tint_src_dir}/cmd/remote_compile",
350 "${tint_src_dir}/cmd/tint",
351 ]
Ben Claytond283e952023-10-10 15:30:56 +0000352 }
Ben Claytonf9a5b712024-03-13 17:37:33 +0000353 if (tint_build_tintd) {
354 deps += [ "${tint_src_dir}/cmd/tintd" ]
355 }
Ryan Harrisonc020a0e2024-07-09 20:44:51 +0000356 if (tint_build_ir_fuzzer && tint_build_ir_binary) {
357 if (tint_build_wgsl_reader) {
358 deps += [ "${tint_src_dir}/cmd/fuzz/ir/as" ]
359 }
Ryan Harrisonde1a4802024-07-11 02:01:40 +0000360 if (tint_build_wgsl_writer && tint_build_spv_writer) {
Ryan Harrisonc020a0e2024-07-09 20:44:51 +0000361 deps += [ "${tint_src_dir}/cmd/fuzz/ir/dis" ]
362 }
363 }
Ben Claytond283e952023-10-10 15:30:56 +0000364}
365
366group("fuzzers") {
367 testonly = true
368 deps = []
369 if (tint_has_fuzzers) {
Ben Clayton2468be52024-04-29 15:26:16 +0000370 deps += [ "${tint_src_dir}/cmd/fuzz/wgsl" ]
Ben Claytond283e952023-10-10 15:30:56 +0000371 }
Ben Clayton5e1a2a02024-06-05 21:34:28 +0000372
Ryan Harrison88e0d752024-06-14 02:02:10 +0000373 if (tint_build_ir_fuzzer && (!is_asan || build_with_chromium)) {
Ben Clayton5e1a2a02024-06-05 21:34:28 +0000374 deps += [ "${tint_src_dir}/cmd/fuzz/ir" ]
375 }
Ben Claytond283e952023-10-10 15:30:56 +0000376}
377
378group("tests") {
379 testonly = true
380 deps = []
381 if (tint_build_unittests) {
382 deps += [ "${tint_src_dir}/cmd/test:test_cmd" ]
383 }
384}
385
386group("benchmarks") {
387 testonly = true
388 deps = []
James Priceb7b04632024-08-28 15:19:21 +0000389 if (tint_build_benchmarks && tint_build_wgsl_reader) {
Ben Claytond283e952023-10-10 15:30:56 +0000390 deps += [ "${tint_src_dir}/cmd/bench:bench_cmd" ]
391 }
392}
393
394###############################################################################
Ben Clayton6ab54622023-10-02 18:40:36 +0000395# Aliases
Ben Clayton7d81e552023-08-17 12:01:50 +0000396###############################################################################
Ben Claytond283e952023-10-10 15:30:56 +0000397group("tint_unittests") {
398 testonly = true
399 public_deps = [ ":tests" ]
dan sinclair889a4992022-06-17 13:01:59 +0000400}