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