BUILD.bazel 11 KB

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