BUILD.bazel 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. package(
  2. default_visibility = ["//visibility:public"],
  3. )
  4. # Description:
  5. #
  6. # Khronos reference front-end for GLSL and ESSL, and sample SPIR-V generator.
  7. licenses(["notice"])
  8. exports_files(["LICENSE"])
  9. COMMON_COPTS = select({
  10. "@bazel_tools//src/conditions:windows": [""],
  11. "//conditions:default": [
  12. "-Wall",
  13. "-Wuninitialized",
  14. "-Wunused",
  15. "-Wunused-local-typedefs",
  16. "-Wunused-parameter",
  17. "-Wunused-value",
  18. "-Wunused-variable",
  19. "-Wno-reorder",
  20. "-std=c++11",
  21. "-fvisibility=hidden",
  22. "-fvisibility-inlines-hidden",
  23. "-fno-exceptions",
  24. "-fno-rtti",
  25. ],
  26. })
  27. cc_library(
  28. name = "glslang",
  29. srcs = glob(
  30. [
  31. "glslang/GenericCodeGen/*.cpp",
  32. "glslang/MachineIndependent/*.cpp",
  33. "glslang/MachineIndependent/preprocessor/*.cpp",
  34. "hlsl/*.cpp",
  35. ],
  36. exclude = [
  37. "glslang/MachineIndependent/pch.cpp",
  38. "glslang/MachineIndependent/pch.h",
  39. "hlsl/pch.cpp",
  40. "hlsl/pch.h",
  41. ],
  42. ) + [
  43. "OGLCompilersDLL/InitializeDll.cpp",
  44. ] + select({
  45. "@bazel_tools//src/conditions:windows":
  46. ["glslang/OSDependent/Windows/ossource.cpp"],
  47. "//conditions:default":
  48. ["glslang/OSDependent/Unix/ossource.cpp"],
  49. }),
  50. hdrs = glob([
  51. "glslang/Include/*.h",
  52. "glslang/MachineIndependent/*.h",
  53. "glslang/MachineIndependent/preprocessor/*.h",
  54. "hlsl/*.h",
  55. ]) + [
  56. "OGLCompilersDLL/InitializeDll.h",
  57. "StandAlone/DirStackFileIncluder.h",
  58. "glslang/OSDependent/osinclude.h",
  59. "glslang/Public/ShaderLang.h",
  60. ],
  61. copts = COMMON_COPTS,
  62. defines = [
  63. "AMD_EXTENSIONS",
  64. "ENABLE_HLSL=0",
  65. "ENABLE_OPT=0",
  66. "NV_EXTENSIONS",
  67. ],
  68. linkopts = select({
  69. "@bazel_tools//src/conditions:windows": [""],
  70. "//conditions:default": ["-lm", "-lpthread"],
  71. }),
  72. linkstatic = 1,
  73. )
  74. genrule(
  75. name = "export_spirv_headers",
  76. srcs = [
  77. "SPIRV/GLSL.ext.AMD.h",
  78. "SPIRV/GLSL.ext.EXT.h",
  79. "SPIRV/GLSL.ext.KHR.h",
  80. "SPIRV/GLSL.ext.NV.h",
  81. "SPIRV/GLSL.std.450.h",
  82. "SPIRV/spirv.hpp",
  83. ],
  84. outs = [
  85. "include/SPIRV/GLSL.ext.AMD.h",
  86. "include/SPIRV/GLSL.ext.EXT.h",
  87. "include/SPIRV/GLSL.ext.KHR.h",
  88. "include/SPIRV/GLSL.ext.NV.h",
  89. "include/SPIRV/GLSL.std.450.h",
  90. "include/SPIRV/spirv.hpp",
  91. ],
  92. cmd = "mkdir -p $(@D)/include/SPIRV && cp $(SRCS) $(@D)/include/SPIRV/",
  93. )
  94. cc_library(
  95. name = "SPIRV_headers",
  96. hdrs = [":export_spirv_headers"],
  97. copts = COMMON_COPTS,
  98. includes = [
  99. "include",
  100. "include/SPIRV",
  101. ],
  102. linkstatic = 1,
  103. )
  104. cc_library(
  105. name = "SPIRV",
  106. srcs = glob(
  107. ["SPIRV/*.cpp"],
  108. exclude = [
  109. "SPIRV/SpvTools.cpp",
  110. ],
  111. ),
  112. hdrs = [
  113. "SPIRV/GlslangToSpv.h",
  114. "SPIRV/Logger.h",
  115. "SPIRV/SPVRemapper.h",
  116. "SPIRV/SpvBuilder.h",
  117. "SPIRV/SpvTools.h",
  118. "SPIRV/bitutils.h",
  119. "SPIRV/disassemble.h",
  120. "SPIRV/doc.h",
  121. "SPIRV/hex_float.h",
  122. "SPIRV/spvIR.h",
  123. ],
  124. copts = COMMON_COPTS,
  125. includes = ["SPIRV"],
  126. linkopts = select({
  127. "@bazel_tools//src/conditions:windows": [""],
  128. "//conditions:default": ["-lm"],
  129. }),
  130. linkstatic = 1,
  131. deps = [
  132. ":SPIRV_headers",
  133. ":glslang",
  134. ],
  135. )
  136. cc_library(
  137. name = "glslang-default-resource-limits",
  138. srcs = ["StandAlone/ResourceLimits.cpp"],
  139. hdrs = ["StandAlone/ResourceLimits.h"],
  140. copts = COMMON_COPTS,
  141. linkstatic = 1,
  142. deps = [":glslang"],
  143. )
  144. cc_binary(
  145. name = "glslangValidator",
  146. srcs = [
  147. "StandAlone/StandAlone.cpp",
  148. "StandAlone/Worklist.h",
  149. ],
  150. copts = COMMON_COPTS,
  151. deps = [
  152. ":SPIRV",
  153. ":glslang",
  154. ":glslang-default-resource-limits",
  155. ],
  156. )
  157. cc_binary(
  158. name = "spirv-remap",
  159. srcs = ["StandAlone/spirv-remap.cpp"],
  160. copts = COMMON_COPTS,
  161. deps = [
  162. ":SPIRV",
  163. ":glslang",
  164. ":glslang-default-resource-limits",
  165. ],
  166. )
  167. filegroup(
  168. name = "test_files",
  169. srcs = glob(
  170. ["Test/**"],
  171. exclude = [
  172. "Test/bump",
  173. "Test/glslangValidator",
  174. "Test/runtests",
  175. ],
  176. ),
  177. )
  178. cc_library(
  179. name = "glslang_test_lib",
  180. testonly = 1,
  181. srcs = [
  182. "gtests/HexFloat.cpp",
  183. "gtests/Initializer.h",
  184. "gtests/Settings.cpp",
  185. "gtests/Settings.h",
  186. "gtests/TestFixture.cpp",
  187. "gtests/TestFixture.h",
  188. "gtests/main.cpp",
  189. ],
  190. copts = COMMON_COPTS,
  191. data = [":test_files"],
  192. defines = select({
  193. # Unfortunately we can't use $(location) in cc_library at the moment.
  194. # See https://github.com/bazelbuild/bazel/issues/1023
  195. # So we'll specify the path manually.
  196. "@bazel_tools//src/conditions:windows":
  197. ["GLSLANG_TEST_DIRECTORY='\"../../../../../Test\"'"],
  198. "//conditions:default":
  199. ["GLSLANG_TEST_DIRECTORY='\"Test\"'"],
  200. }),
  201. linkstatic = 1,
  202. deps = [
  203. ":SPIRV",
  204. ":glslang",
  205. ":glslang-default-resource-limits",
  206. "@com_google_googletest//:gtest",
  207. ],
  208. )
  209. GLSLANG_TESTS = glob(
  210. ["gtests/*.FromFile.cpp"],
  211. # Since we are not building the SPIRV-Tools dependency, the following tests
  212. # cannot be performed.
  213. exclude = [
  214. "gtests/Hlsl.FromFile.cpp",
  215. "gtests/Spv.FromFile.cpp",
  216. ],
  217. )
  218. [cc_test(
  219. name = test_file.replace("gtests/", "").replace(".FromFile.cpp", "") + "_test",
  220. srcs = [test_file],
  221. copts = COMMON_COPTS,
  222. data = [
  223. ":test_files",
  224. ],
  225. deps = [
  226. ":SPIRV",
  227. ":glslang",
  228. ":glslang_test_lib",
  229. ],
  230. ) for test_file in GLSLANG_TESTS]