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 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", 106 ":gen_core_tables_unified1", 107 ":gen_enum_string_mapping", 108 ":gen_extinst_lang_headers_DebugInfo", 109 ":gen_extinst_lang_headers_OpenCLDebugInfo100", 110 ":gen_extinst_lang_headers_NonSemanticShaderDebugInfo100", 111 ":gen_glsl_tables_unified1", 112 ":gen_opencl_tables_unified1", 113 ":gen_registry_tables", 114 ":gen_vendor_tables_debuginfo", 115 ":gen_vendor_tables_nonsemantic_clspvreflection", 116 ":gen_vendor_tables_opencl_debuginfo_100", 117 ":gen_vendor_tables_nonsemantic_shader_debuginfo_100", 118 ":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( 237 name = "spirv_tools_lint", 238 srcs = glob(["source/lint/*.cpp", "source/lint/*.h"]), 239 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( 250 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( 347 name = "spirv-lint", 348 srcs = [ 349 "tools/io.h", 350 "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( 362 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 504[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 511[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 = [ 554 "test/val/pch_test_val.cpp", # pch tests are skipped. 555 ], 556)] 557 558