BUILD.bazel 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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/NonSemanticDebugPrintf.h",
  83. "SPIRV/spirv.hpp",
  84. ],
  85. outs = [
  86. "include/SPIRV/GLSL.ext.AMD.h",
  87. "include/SPIRV/GLSL.ext.EXT.h",
  88. "include/SPIRV/GLSL.ext.KHR.h",
  89. "include/SPIRV/GLSL.ext.NV.h",
  90. "include/SPIRV/GLSL.std.450.h",
  91. "include/SPIRV/NonSemanticDebugPrintf.h",
  92. "include/SPIRV/spirv.hpp",
  93. ],
  94. cmd = "mkdir -p $(@D)/include/SPIRV && cp $(SRCS) $(@D)/include/SPIRV/",
  95. )
  96. cc_library(
  97. name = "SPIRV_headers",
  98. hdrs = [":export_spirv_headers"],
  99. copts = COMMON_COPTS,
  100. includes = [
  101. "include",
  102. "include/SPIRV",
  103. ],
  104. linkstatic = 1,
  105. )
  106. cc_library(
  107. name = "SPIRV",
  108. srcs = glob(
  109. ["SPIRV/*.cpp"],
  110. exclude = [
  111. "SPIRV/SpvTools.cpp",
  112. ],
  113. ),
  114. hdrs = [
  115. "SPIRV/GlslangToSpv.h",
  116. "SPIRV/Logger.h",
  117. "SPIRV/SPVRemapper.h",
  118. "SPIRV/SpvBuilder.h",
  119. "SPIRV/SpvTools.h",
  120. "SPIRV/bitutils.h",
  121. "SPIRV/disassemble.h",
  122. "SPIRV/doc.h",
  123. "SPIRV/hex_float.h",
  124. "SPIRV/spvIR.h",
  125. ],
  126. copts = COMMON_COPTS,
  127. includes = ["SPIRV"],
  128. linkopts = select({
  129. "@bazel_tools//src/conditions:windows": [""],
  130. "//conditions:default": ["-lm"],
  131. }),
  132. linkstatic = 1,
  133. deps = [
  134. ":SPIRV_headers",
  135. ":glslang",
  136. ],
  137. )
  138. cc_library(
  139. name = "glslang-default-resource-limits",
  140. srcs = ["StandAlone/ResourceLimits.cpp"],
  141. hdrs = ["StandAlone/ResourceLimits.h"],
  142. copts = COMMON_COPTS,
  143. linkstatic = 1,
  144. deps = [":glslang"],
  145. )
  146. cc_binary(
  147. name = "glslangValidator",
  148. srcs = [
  149. "StandAlone/StandAlone.cpp",
  150. "StandAlone/Worklist.h",
  151. ],
  152. copts = COMMON_COPTS,
  153. deps = [
  154. ":SPIRV",
  155. ":glslang",
  156. ":glslang-default-resource-limits",
  157. ],
  158. )
  159. cc_binary(
  160. name = "spirv-remap",
  161. srcs = ["StandAlone/spirv-remap.cpp"],
  162. copts = COMMON_COPTS,
  163. deps = [
  164. ":SPIRV",
  165. ":glslang",
  166. ":glslang-default-resource-limits",
  167. ],
  168. )
  169. filegroup(
  170. name = "test_files",
  171. srcs = glob(
  172. ["Test/**"],
  173. exclude = [
  174. "Test/bump",
  175. "Test/glslangValidator",
  176. "Test/runtests",
  177. ],
  178. ),
  179. )
  180. cc_library(
  181. name = "glslang_test_lib",
  182. testonly = 1,
  183. srcs = [
  184. "gtests/HexFloat.cpp",
  185. "gtests/Initializer.h",
  186. "gtests/Settings.cpp",
  187. "gtests/Settings.h",
  188. "gtests/TestFixture.cpp",
  189. "gtests/TestFixture.h",
  190. "gtests/main.cpp",
  191. ],
  192. copts = COMMON_COPTS,
  193. data = [":test_files"],
  194. defines = select({
  195. # Unfortunately we can't use $(location) in cc_library at the moment.
  196. # See https://github.com/bazelbuild/bazel/issues/1023
  197. # So we'll specify the path manually.
  198. "@bazel_tools//src/conditions:windows":
  199. ["GLSLANG_TEST_DIRECTORY='\"../../../../../Test\"'"],
  200. "//conditions:default":
  201. ["GLSLANG_TEST_DIRECTORY='\"Test\"'"],
  202. }),
  203. linkstatic = 1,
  204. deps = [
  205. ":SPIRV",
  206. ":glslang",
  207. ":glslang-default-resource-limits",
  208. "@com_google_googletest//:gtest",
  209. ],
  210. )
  211. GLSLANG_TESTS = glob(
  212. ["gtests/*.FromFile.cpp"],
  213. # Since we are not building the SPIRV-Tools dependency, the following tests
  214. # cannot be performed.
  215. exclude = [
  216. "gtests/Hlsl.FromFile.cpp",
  217. "gtests/Spv.FromFile.cpp",
  218. ],
  219. )
  220. [cc_test(
  221. name = test_file.replace("gtests/", "").replace(".FromFile.cpp", "") + "_test",
  222. srcs = [test_file],
  223. copts = COMMON_COPTS,
  224. data = [
  225. ":test_files",
  226. ],
  227. deps = [
  228. ":SPIRV",
  229. ":glslang",
  230. ":glslang_test_lib",
  231. ],
  232. ) for test_file in GLSLANG_TESTS]