blob: b2031dede25bc6e49cf2f1ad83b7d5be7d15c649 [file] [log] [blame]
Ehsana03cd1f2019-09-24 15:56:59 -04001load(
2 ":build_defs.bzl",
3 "COMMON_COPTS",
4 "DEBUGINFO_GRAMMAR_JSON_FILE",
David Neto64f36ea2019-12-19 17:16:26 -05005 "CLDEBUGINFO100_GRAMMAR_JSON_FILE",
Greg Fischer1454c952021-09-15 12:38:53 -06006 "SHDEBUGINFO100_GRAMMAR_JSON_FILE",
Ehsana03cd1f2019-09-24 15:56:59 -04007 "TEST_COPTS",
8 "base_test",
9 "generate_core_tables",
10 "generate_enum_string_mapping",
11 "generate_extinst_lang_headers",
12 "generate_glsl_tables",
13 "generate_opencl_tables",
14 "generate_vendor_tables",
15 "link_test",
dong-ja706dc272021-08-06 13:03:59 -050016 "lint_test",
Ehsana03cd1f2019-09-24 15:56:59 -040017 "opt_test",
18 "reduce_test",
19 "util_test",
20 "val_test",
21)
22
23package(
24 default_visibility = ["//visibility:private"],
25)
26
27licenses(["notice"])
28
29exports_files([
30 "CHANGES",
31 "LICENSE",
32])
33
34py_binary(
35 name = "generate_grammar_tables",
36 srcs = ["utils/generate_grammar_tables.py"],
37)
38
39py_binary(
40 name = "generate_language_headers",
41 srcs = ["utils/generate_language_headers.py"],
42)
43
Ehsana03cd1f2019-09-24 15:56:59 -040044generate_core_tables("unified1")
45
46generate_enum_string_mapping("unified1")
47
48generate_opencl_tables("unified1")
49
50generate_glsl_tables("unified1")
51
52generate_vendor_tables("spv-amd-shader-explicit-vertex-parameter")
53
54generate_vendor_tables("spv-amd-shader-trinary-minmax")
55
56generate_vendor_tables("spv-amd-gcn-shader")
57
58generate_vendor_tables("spv-amd-shader-ballot")
59
60generate_vendor_tables("debuginfo")
61
David Neto64f36ea2019-12-19 17:16:26 -050062generate_vendor_tables("opencl.debuginfo.100", "CLDEBUG100_")
63
Greg Fischer1454c952021-09-15 12:38:53 -060064generate_vendor_tables("nonsemantic.shader.debuginfo.100", "SHDEBUG100_")
Greg Fischer3b6abf42021-07-12 03:51:08 -060065
alan-baker50300452020-07-30 12:08:53 -040066generate_vendor_tables("nonsemantic.clspvreflection")
67
Ehsana03cd1f2019-09-24 15:56:59 -040068generate_extinst_lang_headers("DebugInfo", DEBUGINFO_GRAMMAR_JSON_FILE)
69
David Neto64f36ea2019-12-19 17:16:26 -050070generate_extinst_lang_headers("OpenCLDebugInfo100", CLDEBUGINFO100_GRAMMAR_JSON_FILE)
71
Greg Fischer1454c952021-09-15 12:38:53 -060072generate_extinst_lang_headers("NonSemanticShaderDebugInfo100", SHDEBUGINFO100_GRAMMAR_JSON_FILE)
Greg Fischer3b6abf42021-07-12 03:51:08 -060073
Ehsana03cd1f2019-09-24 15:56:59 -040074py_binary(
75 name = "generate_registry_tables",
76 srcs = ["utils/generate_registry_tables.py"],
77)
78
79genrule(
80 name = "gen_registry_tables",
81 srcs = ["@spirv_headers//:spirv_xml_registry"],
82 outs = ["generators.inc"],
83 cmd = "$(location generate_registry_tables) --xml=$(location @spirv_headers//:spirv_xml_registry) --generator-output=$(location generators.inc)",
84 tools = [":generate_registry_tables"],
85)
86
87py_binary(
88 name = "update_build_version",
89 srcs = ["utils/update_build_version.py"],
90)
91
92genrule(
93 name = "gen_build_version",
94 srcs = ["CHANGES"],
95 outs = ["build-version.inc"],
96 cmd = "SOURCE_DATE_EPOCH=0 $(location update_build_version) $$(dirname $(location CHANGES)) $(location build-version.inc)",
97 tools = [":update_build_version"],
98)
99
100# Libraries
101
102cc_library(
103 name = "generated_headers",
104 hdrs = [
105 ":gen_build_version",
Ehsana03cd1f2019-09-24 15:56:59 -0400106 ":gen_core_tables_unified1",
107 ":gen_enum_string_mapping",
108 ":gen_extinst_lang_headers_DebugInfo",
David Neto64f36ea2019-12-19 17:16:26 -0500109 ":gen_extinst_lang_headers_OpenCLDebugInfo100",
Greg Fischer1454c952021-09-15 12:38:53 -0600110 ":gen_extinst_lang_headers_NonSemanticShaderDebugInfo100",
Ehsana03cd1f2019-09-24 15:56:59 -0400111 ":gen_glsl_tables_unified1",
112 ":gen_opencl_tables_unified1",
113 ":gen_registry_tables",
114 ":gen_vendor_tables_debuginfo",
alan-baker50300452020-07-30 12:08:53 -0400115 ":gen_vendor_tables_nonsemantic_clspvreflection",
David Neto64f36ea2019-12-19 17:16:26 -0500116 ":gen_vendor_tables_opencl_debuginfo_100",
Greg Fischer1454c952021-09-15 12:38:53 -0600117 ":gen_vendor_tables_nonsemantic_shader_debuginfo_100",
Ehsana03cd1f2019-09-24 15:56:59 -0400118 ":gen_vendor_tables_spv_amd_gcn_shader",
119 ":gen_vendor_tables_spv_amd_shader_ballot",
120 ":gen_vendor_tables_spv_amd_shader_explicit_vertex_parameter",
121 ":gen_vendor_tables_spv_amd_shader_trinary_minmax",
122 ],
123 copts = COMMON_COPTS,
124)
125
126cc_library(
127 name = "spirv_tools_headers",
128 hdrs = glob([
129 "include/spirv-tools/libspirv.h",
130 "include/spirv-tools/libspirv.hpp",
131 "source/*.h",
132 "source/util/*.h",
133 "source/val/*.h",
134 ]),
135 copts = COMMON_COPTS,
136 includes = ["source"],
137 deps = [
138 "@spirv_headers//:spirv_c_headers",
139 ],
140)
141
142cc_library(
143 name = "spirv_tools",
144 srcs = glob([
145 "source/*.cpp",
146 "source/util/*.cpp",
147 "source/val/*.cpp",
148 ]),
149 hdrs = [
150 "include/spirv-tools/libspirv.h",
151 "include/spirv-tools/libspirv.hpp",
152 ],
153 copts = COMMON_COPTS + select({
154 "@bazel_tools//src/conditions:windows": [""],
155 "//conditions:default": ["-Wno-implicit-fallthrough"],
156 }),
157 includes = ["include"],
158 linkstatic = 1,
159 visibility = ["//visibility:public"],
160 deps = [
161 ":generated_headers",
162 ":spirv_tools_headers",
163 "@spirv_headers//:spirv_c_headers",
164 "@spirv_headers//:spirv_common_headers",
165 ],
166)
167
168cc_library(
169 name = "spirv_tools_comp",
170 srcs = glob([
171 "source/comp/*.cpp",
172 "source/comp/*.h",
173 ]),
174 copts = COMMON_COPTS,
175 linkstatic = 1,
176 visibility = ["//visibility:public"],
177 deps = [
178 ":generated_headers",
179 ":spirv_tools",
180 ":spirv_tools_headers",
181 "@spirv_headers//:spirv_common_headers",
182 ],
183)
184
185cc_library(
186 name = "spirv_tools_opt_headers",
187 hdrs = glob(["source/opt/*.h"]),
188 copts = COMMON_COPTS,
189)
190
191cc_library(
192 name = "spirv_tools_opt",
193 srcs = glob(["source/opt/*.cpp"]),
194 hdrs = [
195 "include/spirv-tools/instrument.hpp",
196 "include/spirv-tools/optimizer.hpp",
197 ],
198 copts = COMMON_COPTS,
199 includes = ["include"],
200 linkstatic = 1,
201 visibility = ["//visibility:public"],
202 deps = [
203 ":spirv_tools",
204 ":spirv_tools_headers",
205 ":spirv_tools_opt_headers",
206 "@spirv_headers//:spirv_common_headers",
207 ],
208)
209
210cc_library(
211 name = "spirv_tools_reduce",
212 srcs = glob(["source/reduce/*.cpp"]),
213 hdrs = glob(["source/reduce/*.h"]),
214 copts = COMMON_COPTS,
215 linkstatic = 1,
216 visibility = ["//visibility:public"],
217 deps = [
218 ":spirv_tools",
219 ":spirv_tools_opt",
220 ],
221)
222
223cc_library(
224 name = "spirv_tools_link",
225 srcs = glob(["source/link/*.cpp"]),
226 hdrs = ["include/spirv-tools/linker.hpp"],
227 copts = COMMON_COPTS,
228 linkstatic = 1,
229 visibility = ["//visibility:public"],
230 deps = [
231 ":spirv_tools",
232 ":spirv_tools_opt",
233 ],
234)
235
236cc_library(
dong-ja706dc272021-08-06 13:03:59 -0500237 name = "spirv_tools_lint",
dong-ja937227c2021-08-23 16:03:28 -0500238 srcs = glob(["source/lint/*.cpp", "source/lint/*.h"]),
dong-ja706dc272021-08-06 13:03:59 -0500239 hdrs = ["include/spirv-tools/linter.hpp"],
240 copts = COMMON_COPTS,
241 linkstatic = 1,
242 visibility = ["//visibility:public"],
243 deps = [
244 ":spirv_tools",
245 ":spirv_tools_opt",
246 ],
247)
248
249cc_library(
Ehsana03cd1f2019-09-24 15:56:59 -0400250 name = "tools_util",
251 srcs = glob(["tools/util/*.cpp"]),
252 hdrs = glob(["tools/util/*.h"]),
253 copts = COMMON_COPTS,
254 linkstatic = 1,
255 visibility = ["//visibility:public"],
256 deps = [":spirv_tools"],
257)
258
259# Tools
260
261cc_binary(
262 name = "spirv-as",
263 srcs = [
264 "tools/as/as.cpp",
265 "tools/io.h",
266 ],
267 copts = COMMON_COPTS,
268 visibility = ["//visibility:public"],
269 deps = [
270 ":spirv_tools",
271 ],
272)
273
274cc_binary(
275 name = "spirv-dis",
276 srcs = [
277 "tools/dis/dis.cpp",
278 "tools/io.h",
279 ],
280 copts = COMMON_COPTS,
281 visibility = ["//visibility:public"],
282 deps = [
283 ":spirv_tools",
284 ],
285)
286
287cc_binary(
288 name = "spirv-val",
289 srcs = [
290 "tools/io.h",
291 "tools/val/val.cpp",
292 ],
293 copts = COMMON_COPTS,
294 visibility = ["//visibility:public"],
295 deps = [
296 ":spirv_tools",
297 ":tools_util",
298 ],
299)
300
301cc_binary(
302 name = "spirv-opt",
303 srcs = [
304 "tools/io.h",
305 "tools/opt/opt.cpp",
306 ],
307 copts = COMMON_COPTS,
308 visibility = ["//visibility:public"],
309 deps = [
310 ":spirv_tools",
311 ":spirv_tools_opt",
312 ":tools_util",
313 ],
314)
315
316cc_binary(
317 name = "spirv-reduce",
318 srcs = [
319 "tools/io.h",
320 "tools/reduce/reduce.cpp",
321 ],
322 copts = COMMON_COPTS,
323 visibility = ["//visibility:public"],
324 deps = [
325 ":spirv_tools",
326 ":spirv_tools_opt",
327 ":spirv_tools_reduce",
328 ":tools_util",
329 ],
330)
331
332cc_binary(
333 name = "spirv-link",
334 srcs = [
335 "tools/io.h",
336 "tools/link/linker.cpp",
337 ],
338 copts = COMMON_COPTS,
339 visibility = ["//visibility:public"],
340 deps = [
341 ":spirv_tools",
342 ":spirv_tools_link",
343 ],
344)
345
346cc_binary(
dong-ja706dc272021-08-06 13:03:59 -0500347 name = "spirv-lint",
348 srcs = [
dong-ja1ad8b712021-08-18 15:17:03 -0500349 "tools/io.h",
dong-ja706dc272021-08-06 13:03:59 -0500350 "tools/lint/lint.cpp",
351 ],
352 copts = COMMON_COPTS,
353 visibility = ["//visibility:public"],
354 deps = [
355 ":spirv_tools",
356 ":spirv_tools_lint",
357 ":tools_util",
358 ],
359)
360
361cc_binary(
Ehsana03cd1f2019-09-24 15:56:59 -0400362 name = "spirv-cfg",
363 srcs = [
364 "tools/cfg/bin_to_dot.cpp",
365 "tools/cfg/bin_to_dot.h",
366 "tools/cfg/cfg.cpp",
367 "tools/io.h",
368 ],
369 copts = COMMON_COPTS,
370 visibility = ["//visibility:public"],
371 deps = [":spirv_tools"],
372)
373
374# Unit tests
375
376cc_library(
377 name = "test_common",
378 testonly = 1,
379 srcs = [
380 "test/test_fixture.h",
381 "test/unit_spirv.cpp",
382 "test/unit_spirv.h",
383 ],
384 compatible_with = [],
385 copts = TEST_COPTS,
386 includes = ["test"],
387 linkstatic = 1,
388 deps = [
389 ":spirv_tools",
390 "@com_google_googletest//:gtest",
391 ],
392)
393
394cc_library(
395 name = "link_test_common",
396 testonly = 1,
397 srcs = ["test/link/linker_fixture.h"],
398 compatible_with = [],
399 copts = TEST_COPTS,
400 linkstatic = 1,
401 deps = [
402 ":spirv_tools_link",
403 ":test_common",
404 ],
405)
406
407cc_library(
408 name = "opt_test_common",
409 testonly = 1,
410 srcs = ["test/opt/pass_utils.cpp"],
411 hdrs = [
412 "test/opt/assembly_builder.h",
413 "test/opt/function_utils.h",
414 "test/opt/module_utils.h",
415 "test/opt/pass_fixture.h",
416 "test/opt/pass_utils.h",
417 ],
418 compatible_with = [],
419 copts = TEST_COPTS,
420 linkstatic = 1,
421 deps = [
422 ":spirv_tools_opt",
423 ":test_common",
424 ],
425)
426
427cc_library(
428 name = "reduce_test_common",
429 testonly = 1,
430 srcs = [
431 "test/reduce/reduce_test_util.cpp",
432 "tools/io.h",
433 ],
434 hdrs = ["test/reduce/reduce_test_util.h"],
435 compatible_with = [],
436 copts = TEST_COPTS,
437 linkstatic = 1,
438 deps = [
439 ":spirv_tools_reduce",
440 ":test_common",
441 ],
442)
443
444cc_library(
445 name = "val_test_common",
446 testonly = 1,
447 srcs = [
448 "test/val/val_code_generator.cpp",
449 "test/val/val_fixtures.h",
450 ],
451 hdrs = [
452 "test/val/val_code_generator.h",
453 ],
454 compatible_with = [],
455 copts = TEST_COPTS,
456 linkstatic = 1,
457 deps = [":test_common"],
458)
459
460# PCH (precompiled header) tests only work when using CMake and MSVC on Windows,
461# so they will be skipped in the Bazel builds.
462
463[base_test(
464 name = f[5:-4], # strip test/, .cpp
465 srcs = [f],
466) for f in glob(
467 ["test/*.cpp"],
468 exclude = [
469 "test/cpp_interface_test.cpp", # has its own base_test below.
470 "test/log_test.cpp", # has its own base_test below.
471 "test/pch_test.cpp", # pch tests are skipped.
472 "test/timer_test.cpp", # has its own base_test below.
473 ],
474)]
475
476# This test uses unistd.h and does not run on Windows.
477base_test(
478 name = "timer_test",
479 srcs = select({
480 "@bazel_tools//src/conditions:windows": [],
481 "//conditions:default": ["test/timer_test.cpp"],
482 }),
483)
484
485base_test(
486 name = "cpp_interface_test",
487 srcs = ["test/cpp_interface_test.cpp"],
488 deps = [":spirv_tools_opt"],
489)
490
491base_test(
492 name = "log_test",
493 srcs = ["test/log_test.cpp"],
494 deps = [":spirv_tools_opt"],
495)
496
497[link_test(
498 name = f[10:-4], # strip test/link/, .cpp
499 srcs = [f],
500) for f in glob(
501 ["test/link/*.cpp"],
502)]
503
dong-ja706dc272021-08-06 13:03:59 -0500504[lint_test(
505 name = f[10:-4], # strip test/lint/, .cpp
506 srcs = [f],
507) for f in glob(
508 ["test/lint/*.cpp"],
509)]
510
Ehsana03cd1f2019-09-24 15:56:59 -0400511[opt_test(
512 name = f[9:-4], # strip test/opt/, .cpp
513 srcs = [f],
514) for f in glob(
515 ["test/opt/*.cpp"],
516 # pch tests are skipped.
517 exclude = ["test/opt/pch_test_opt.cpp"],
518)]
519
520[opt_test(
521 name = "dom_tree_" + f[24:-4], # strip test/opt/dominator_tree/, .cpp
522 srcs = [f],
523) for f in glob(
524 ["test/opt/dominator_tree/*.cpp"],
525 # pch tests are skipped.
526 exclude = ["test/opt/dominator_tree/pch_test_opt_dom.cpp"],
527)]
528
529[opt_test(
530 name = "loop_" + f[28:-4], # strip test/opt/loop_optimizations/, .cpp
531 srcs = [f],
532) for f in glob(
533 ["test/opt/loop_optimizations/*.cpp"],
534 # pch tests are skipped.
535 exclude = ["test/opt/loop_optimizations/pch_test_opt_loop.cpp"],
536)]
537
538[reduce_test(
539 name = f[12:-4], # strip test/reduce/, .cpp
540 srcs = [f],
541) for f in glob(["test/reduce/*.cpp"])]
542
543[util_test(
544 name = f[10:-4], # strip test/util/, .cpp
545 srcs = [f],
546) for f in glob(["test/util/*.cpp"])]
547
548[val_test(
549 name = f[9:-4], # strip test/val/, .cpp
550 srcs = [f],
551) for f in glob(
552 ["test/val/*.cpp"],
553 exclude = [
Ehsana03cd1f2019-09-24 15:56:59 -0400554 "test/val/pch_test_val.cpp", # pch tests are skipped.
555 ],
556)]
557