BUILD.bazel 11 KB

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