• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1load(
2    ":build_defs.bzl",
3    "COMMON_COPTS",
4    "DEBUGINFO_GRAMMAR_JSON_FILE",
5    "CLDEBUGINFO100_GRAMMAR_JSON_FILE",
6    "SHDEBUGINFO100_GRAMMAR_JSON_FILE",
7    "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",
16    "lint_test",
17    "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
44generate_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
62generate_vendor_tables("opencl.debuginfo.100", "CLDEBUG100_")
63
64generate_vendor_tables("nonsemantic.shader.debuginfo.100", "SHDEBUG100_")
65
66generate_vendor_tables("nonsemantic.clspvreflection")
67
68generate_extinst_lang_headers("DebugInfo", DEBUGINFO_GRAMMAR_JSON_FILE)
69
70generate_extinst_lang_headers("OpenCLDebugInfo100", CLDEBUGINFO100_GRAMMAR_JSON_FILE)
71
72generate_extinst_lang_headers("NonSemanticShaderDebugInfo100", SHDEBUGINFO100_GRAMMAR_JSON_FILE)
73
74py_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    cmd_bat = "$(location //:generate_registry_tables) --xml=$(location @spirv_headers//:spirv_xml_registry) --generator-output=$(location generators.inc)",
85    exec_tools = [":generate_registry_tables"],
86)
87
88py_binary(
89    name = "update_build_version",
90    srcs = ["utils/update_build_version.py"],
91)
92
93genrule(
94    name = "gen_build_version",
95    srcs = ["CHANGES"],
96    outs = ["build-version.inc"],
97    cmd = "SOURCE_DATE_EPOCH=0 $(location update_build_version) $(location CHANGES) $(location build-version.inc)",
98    cmd_bat = "set SOURCE_DATE_EPOCH=0  && $(location //:update_build_version) $(location CHANGES) $(location build-version.inc)",
99    exec_tools = [":update_build_version"],
100)
101
102# Libraries
103
104cc_library(
105    name = "generated_headers",
106    hdrs = [
107        ":gen_build_version",
108        ":gen_core_tables_unified1",
109        ":gen_enum_string_mapping",
110        ":gen_extinst_lang_headers_DebugInfo",
111        ":gen_extinst_lang_headers_OpenCLDebugInfo100",
112        ":gen_extinst_lang_headers_NonSemanticShaderDebugInfo100",
113        ":gen_glsl_tables_unified1",
114        ":gen_opencl_tables_unified1",
115        ":gen_registry_tables",
116        ":gen_vendor_tables_debuginfo",
117        ":gen_vendor_tables_nonsemantic_clspvreflection",
118        ":gen_vendor_tables_opencl_debuginfo_100",
119        ":gen_vendor_tables_nonsemantic_shader_debuginfo_100",
120        ":gen_vendor_tables_spv_amd_gcn_shader",
121        ":gen_vendor_tables_spv_amd_shader_ballot",
122        ":gen_vendor_tables_spv_amd_shader_explicit_vertex_parameter",
123        ":gen_vendor_tables_spv_amd_shader_trinary_minmax",
124    ],
125    copts = COMMON_COPTS,
126)
127
128cc_library(
129    name = "spirv_tools_headers",
130    hdrs = glob([
131        "include/spirv-tools/libspirv.h",
132        "include/spirv-tools/libspirv.hpp",
133        "source/*.h",
134        "source/util/*.h",
135        "source/val/*.h",
136    ]),
137    copts = COMMON_COPTS,
138    includes = ["source"],
139    deps = [
140        "@spirv_headers//:spirv_c_headers",
141    ],
142)
143
144cc_library(
145    name = "spirv_tools",
146    srcs = glob([
147        "source/*.cpp",
148        "source/util/*.cpp",
149        "source/val/*.cpp",
150    ]),
151    hdrs = [
152        "include/spirv-tools/libspirv.h",
153        "include/spirv-tools/libspirv.hpp",
154    ],
155    copts = COMMON_COPTS + select({
156        "@bazel_tools//src/conditions:windows": [""],
157        "//conditions:default": ["-Wno-implicit-fallthrough"],
158    }),
159    includes = ["include"],
160    linkstatic = 1,
161    visibility = ["//visibility:public"],
162    deps = [
163        ":generated_headers",
164        ":spirv_tools_headers",
165        "@spirv_headers//:spirv_c_headers",
166        "@spirv_headers//:spirv_common_headers",
167    ],
168)
169
170cc_library(
171    name = "spirv_tools_comp",
172    srcs = glob([
173        "source/comp/*.cpp",
174        "source/comp/*.h",
175    ]),
176    copts = COMMON_COPTS,
177    linkstatic = 1,
178    visibility = ["//visibility:public"],
179    deps = [
180        ":generated_headers",
181        ":spirv_tools",
182        ":spirv_tools_headers",
183        "@spirv_headers//:spirv_common_headers",
184    ],
185)
186
187cc_library(
188    name = "spirv_tools_opt_headers",
189    hdrs = glob(["source/opt/*.h"]),
190    copts = COMMON_COPTS,
191)
192
193cc_library(
194    name = "spirv_tools_opt",
195    srcs = glob(["source/opt/*.cpp"]),
196    hdrs = [
197        "include/spirv-tools/instrument.hpp",
198        "include/spirv-tools/optimizer.hpp",
199    ],
200    copts = COMMON_COPTS,
201    includes = ["include"],
202    linkstatic = 1,
203    visibility = ["//visibility:public"],
204    deps = [
205        ":spirv_tools",
206        ":spirv_tools_headers",
207        ":spirv_tools_opt_headers",
208        "@spirv_headers//:spirv_common_headers",
209    ],
210)
211
212cc_library(
213    name = "spirv_tools_reduce",
214    srcs = glob(["source/reduce/*.cpp"]),
215    hdrs = glob(["source/reduce/*.h"]),
216    copts = COMMON_COPTS,
217    linkstatic = 1,
218    visibility = ["//visibility:public"],
219    deps = [
220        ":spirv_tools",
221        ":spirv_tools_opt",
222    ],
223)
224
225cc_library(
226    name = "spirv_tools_link",
227    srcs = glob(["source/link/*.cpp"]),
228    hdrs = ["include/spirv-tools/linker.hpp"],
229    copts = COMMON_COPTS,
230    linkstatic = 1,
231    visibility = ["//visibility:public"],
232    deps = [
233        ":spirv_tools",
234        ":spirv_tools_opt",
235    ],
236)
237
238cc_library(
239    name = "spirv_tools_lint",
240    srcs = glob(["source/lint/*.cpp", "source/lint/*.h"]),
241    hdrs = ["include/spirv-tools/linter.hpp"],
242    copts = COMMON_COPTS,
243    linkstatic = 1,
244    visibility = ["//visibility:public"],
245    deps = [
246        ":spirv_tools",
247        ":spirv_tools_opt",
248    ],
249)
250
251cc_library(
252    name = "tools_util",
253    srcs = glob(["tools/util/*.cpp"]),
254    hdrs = glob(["tools/util/*.h"]),
255    copts = COMMON_COPTS,
256    linkstatic = 1,
257    visibility = ["//visibility:public"],
258    deps = [":spirv_tools"],
259)
260
261# Tools
262
263cc_binary(
264    name = "spirv-as",
265    srcs = [
266        "tools/as/as.cpp",
267        "tools/io.h",
268    ],
269    copts = COMMON_COPTS,
270    visibility = ["//visibility:public"],
271    deps = [
272        ":spirv_tools",
273    ],
274)
275
276cc_binary(
277    name = "spirv-dis",
278    srcs = [
279        "tools/dis/dis.cpp",
280        "tools/io.h",
281    ],
282    copts = COMMON_COPTS,
283    visibility = ["//visibility:public"],
284    deps = [
285        ":spirv_tools",
286    ],
287)
288
289cc_binary(
290    name = "spirv-val",
291    srcs = [
292        "tools/io.h",
293        "tools/val/val.cpp",
294    ],
295    copts = COMMON_COPTS,
296    visibility = ["//visibility:public"],
297    deps = [
298        ":spirv_tools",
299        ":tools_util",
300    ],
301)
302
303cc_binary(
304    name = "spirv-opt",
305    srcs = [
306        "tools/io.h",
307        "tools/opt/opt.cpp",
308    ],
309    copts = COMMON_COPTS,
310    visibility = ["//visibility:public"],
311    deps = [
312        ":spirv_tools",
313        ":spirv_tools_opt",
314        ":tools_util",
315    ],
316)
317
318cc_binary(
319    name = "spirv-reduce",
320    srcs = [
321        "tools/io.h",
322        "tools/reduce/reduce.cpp",
323    ],
324    copts = COMMON_COPTS,
325    visibility = ["//visibility:public"],
326    deps = [
327        ":spirv_tools",
328        ":spirv_tools_opt",
329        ":spirv_tools_reduce",
330        ":tools_util",
331    ],
332)
333
334cc_binary(
335    name = "spirv-link",
336    srcs = [
337        "tools/io.h",
338        "tools/link/linker.cpp",
339    ],
340    copts = COMMON_COPTS,
341    visibility = ["//visibility:public"],
342    deps = [
343        ":spirv_tools",
344        ":spirv_tools_link",
345    ],
346)
347
348cc_binary(
349    name = "spirv-lint",
350    srcs = [
351        "tools/io.h",
352        "tools/lint/lint.cpp",
353    ],
354    copts = COMMON_COPTS,
355    visibility = ["//visibility:public"],
356    deps = [
357        ":spirv_tools",
358        ":spirv_tools_lint",
359        ":tools_util",
360    ],
361)
362
363cc_binary(
364    name = "spirv-cfg",
365    srcs = [
366        "tools/cfg/bin_to_dot.cpp",
367        "tools/cfg/bin_to_dot.h",
368        "tools/cfg/cfg.cpp",
369        "tools/io.h",
370    ],
371    copts = COMMON_COPTS,
372    visibility = ["//visibility:public"],
373    deps = [":spirv_tools"],
374)
375
376# Unit tests
377
378cc_library(
379    name = "test_common",
380    testonly = 1,
381    srcs = [
382        "test/test_fixture.h",
383        "test/unit_spirv.cpp",
384        "test/unit_spirv.h",
385    ],
386    compatible_with = [],
387    copts = TEST_COPTS,
388    includes = ["test"],
389    linkstatic = 1,
390    deps = [
391        ":spirv_tools",
392        "@com_google_googletest//:gtest",
393    ],
394)
395
396cc_library(
397    name = "link_test_common",
398    testonly = 1,
399    srcs = ["test/link/linker_fixture.h"],
400    compatible_with = [],
401    copts = TEST_COPTS,
402    linkstatic = 1,
403    deps = [
404        ":spirv_tools_link",
405        ":test_common",
406    ],
407)
408
409cc_library(
410    name = "opt_test_common",
411    testonly = 1,
412    srcs = ["test/opt/pass_utils.cpp"],
413    hdrs = [
414        "test/opt/assembly_builder.h",
415        "test/opt/function_utils.h",
416        "test/opt/module_utils.h",
417        "test/opt/pass_fixture.h",
418        "test/opt/pass_utils.h",
419    ],
420    compatible_with = [],
421    copts = TEST_COPTS,
422    linkstatic = 1,
423    deps = [
424        ":spirv_tools_opt",
425        ":test_common",
426    ],
427)
428
429cc_library(
430    name = "reduce_test_common",
431    testonly = 1,
432    srcs = [
433        "test/reduce/reduce_test_util.cpp",
434        "tools/io.h",
435    ],
436    hdrs = ["test/reduce/reduce_test_util.h"],
437    compatible_with = [],
438    copts = TEST_COPTS,
439    linkstatic = 1,
440    deps = [
441        ":spirv_tools_reduce",
442        ":test_common",
443    ],
444)
445
446cc_library(
447    name = "val_test_common",
448    testonly = 1,
449    srcs = [
450        "test/val/val_code_generator.cpp",
451        "test/val/val_fixtures.h",
452    ],
453    hdrs = [
454        "test/val/val_code_generator.h",
455    ],
456    compatible_with = [],
457    copts = TEST_COPTS,
458    linkstatic = 1,
459    deps = [":test_common"],
460)
461
462# PCH (precompiled header) tests only work when using CMake and MSVC on Windows,
463# so they will be skipped in the Bazel builds.
464
465[base_test(
466    name = f[5:-4],  # strip test/, .cpp
467    srcs = [f],
468) for f in glob(
469    ["test/*.cpp"],
470    exclude = [
471        "test/cpp_interface_test.cpp", # has its own base_test below.
472        "test/log_test.cpp", # has its own base_test below.
473        "test/pch_test.cpp", # pch tests are skipped.
474        "test/timer_test.cpp", # has its own base_test below.
475    ],
476)]
477
478# This test uses unistd.h and does not run on Windows.
479base_test(
480    name = "timer_test",
481    srcs = select({
482        "@bazel_tools//src/conditions:windows": [],
483        "//conditions:default": ["test/timer_test.cpp"],
484    }),
485)
486
487base_test(
488    name = "cpp_interface_test",
489    srcs = ["test/cpp_interface_test.cpp"],
490    deps = [":spirv_tools_opt"],
491)
492
493base_test(
494    name = "log_test",
495    srcs = ["test/log_test.cpp"],
496    deps = [":spirv_tools_opt"],
497)
498
499[link_test(
500    name = f[10:-4],  # strip test/link/, .cpp
501    srcs = [f],
502) for f in glob(
503    ["test/link/*.cpp"],
504)]
505
506[lint_test(
507    name = f[10:-4],  # strip test/lint/, .cpp
508    srcs = [f],
509) for f in glob(
510    ["test/lint/*.cpp"],
511)]
512
513[opt_test(
514    name = f[9:-4],  # strip test/opt/, .cpp
515    srcs = [f],
516) for f in glob(
517    ["test/opt/*.cpp"],
518    # pch tests are skipped.
519    exclude = ["test/opt/pch_test_opt.cpp"],
520)]
521
522[opt_test(
523    name = "dom_tree_" + f[24:-4],  # strip test/opt/dominator_tree/, .cpp
524    srcs = [f],
525) for f in glob(
526    ["test/opt/dominator_tree/*.cpp"],
527    # pch tests are skipped.
528    exclude = ["test/opt/dominator_tree/pch_test_opt_dom.cpp"],
529)]
530
531[opt_test(
532    name = "loop_" + f[28:-4],  # strip test/opt/loop_optimizations/, .cpp
533    srcs = [f],
534) for f in glob(
535    ["test/opt/loop_optimizations/*.cpp"],
536    # pch tests are skipped.
537    exclude = ["test/opt/loop_optimizations/pch_test_opt_loop.cpp"],
538)]
539
540[reduce_test(
541    name = f[12:-4],  # strip test/reduce/, .cpp
542    srcs = [f],
543) for f in glob(["test/reduce/*.cpp"])]
544
545[util_test(
546    name = f[10:-4],  # strip test/util/, .cpp
547    srcs = [f],
548) for f in glob(["test/util/*.cpp"])]
549
550[val_test(
551    name = f[9:-4],  # strip test/val/, .cpp
552    srcs = [f],
553) for f in glob(
554    ["test/val/*.cpp"],
555    exclude = [
556        "test/val/pch_test_val.cpp", # pch tests are skipped.
557    ],
558)]
559
560