BUILD.bazel 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. # Copyright (C) 2020 The Khronos Group Inc.
  2. #
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions
  7. # are met:
  8. #
  9. # Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. #
  12. # Redistributions in binary form must reproduce the above
  13. # copyright notice, this list of conditions and the following
  14. # disclaimer in the documentation and/or other materials provided
  15. # with the distribution.
  16. #
  17. # Neither the name of The Khronos Group Inc. nor the names of its
  18. # contributors may be used to endorse or promote products derived
  19. # from this software without specific prior written permission.
  20. #
  21. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. # COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. # POSSIBILITY OF SUCH DAMAGE.
  33. package(
  34. default_visibility = ["//visibility:public"],
  35. )
  36. # Description:
  37. #
  38. # Khronos reference front-end for GLSL and ESSL, and sample SPIR-V generator.
  39. licenses(["notice"])
  40. exports_files(["LICENSE"])
  41. # Build information generation script
  42. py_binary(
  43. name = "build_info",
  44. srcs = ["build_info.py"],
  45. )
  46. genrule(
  47. name = "gen_build_info_h",
  48. srcs = ["CHANGES.md", "build_info.h.tmpl"],
  49. outs = ["glslang/build_info.h"],
  50. cmd = "$(location build_info) $$(dirname $(location CHANGES.md)) -i $(location build_info.h.tmpl) -o $(location glslang/build_info.h)",
  51. tools = [":build_info"],
  52. )
  53. COMMON_COPTS = select({
  54. "@bazel_tools//src/conditions:windows": [""],
  55. "//conditions:default": [
  56. "-Wall",
  57. "-Wuninitialized",
  58. "-Wunused",
  59. "-Wunused-local-typedefs",
  60. "-Wunused-parameter",
  61. "-Wunused-value",
  62. "-Wunused-variable",
  63. "-Wno-reorder",
  64. "-std=c++11",
  65. "-fvisibility=hidden",
  66. "-fvisibility-inlines-hidden",
  67. "-fno-exceptions",
  68. "-fno-rtti",
  69. ],
  70. })
  71. cc_library(
  72. name = "glslang",
  73. srcs = glob(
  74. [
  75. "glslang/GenericCodeGen/*.cpp",
  76. "glslang/HLSL/*.cpp",
  77. "glslang/MachineIndependent/*.cpp",
  78. "glslang/MachineIndependent/preprocessor/*.cpp",
  79. ],
  80. exclude = [
  81. "glslang/HLSL/pch.h",
  82. "glslang/MachineIndependent/pch.h",
  83. ],
  84. ) + [
  85. "OGLCompilersDLL/InitializeDll.cpp",
  86. ] + select({
  87. "@bazel_tools//src/conditions:windows":
  88. ["glslang/OSDependent/Windows/ossource.cpp"],
  89. "//conditions:default":
  90. ["glslang/OSDependent/Unix/ossource.cpp"],
  91. }),
  92. hdrs = glob([
  93. "glslang/HLSL/*.h",
  94. "glslang/Include/*.h",
  95. "glslang/MachineIndependent/*.h",
  96. "glslang/MachineIndependent/preprocessor/*.h",
  97. ]) + [
  98. "OGLCompilersDLL/InitializeDll.h",
  99. "StandAlone/DirStackFileIncluder.h",
  100. "glslang/OSDependent/osinclude.h",
  101. "glslang/Public/ShaderLang.h",
  102. ":gen_build_info_h",
  103. ],
  104. copts = COMMON_COPTS,
  105. defines = [
  106. "AMD_EXTENSIONS",
  107. "ENABLE_HLSL=0",
  108. "ENABLE_OPT=0",
  109. "NV_EXTENSIONS",
  110. ],
  111. linkopts = select({
  112. "@bazel_tools//src/conditions:windows": [""],
  113. "//conditions:default": ["-lm", "-lpthread"],
  114. }),
  115. linkstatic = 1,
  116. )
  117. genrule(
  118. name = "export_spirv_headers",
  119. srcs = [
  120. "SPIRV/GLSL.ext.AMD.h",
  121. "SPIRV/GLSL.ext.EXT.h",
  122. "SPIRV/GLSL.ext.KHR.h",
  123. "SPIRV/GLSL.ext.NV.h",
  124. "SPIRV/GLSL.std.450.h",
  125. "SPIRV/NonSemanticDebugPrintf.h",
  126. "SPIRV/spirv.hpp",
  127. ],
  128. outs = [
  129. "include/SPIRV/GLSL.ext.AMD.h",
  130. "include/SPIRV/GLSL.ext.EXT.h",
  131. "include/SPIRV/GLSL.ext.KHR.h",
  132. "include/SPIRV/GLSL.ext.NV.h",
  133. "include/SPIRV/GLSL.std.450.h",
  134. "include/SPIRV/NonSemanticDebugPrintf.h",
  135. "include/SPIRV/spirv.hpp",
  136. ],
  137. cmd = "mkdir -p $(@D)/include/SPIRV && cp $(SRCS) $(@D)/include/SPIRV/",
  138. )
  139. cc_library(
  140. name = "SPIRV_headers",
  141. hdrs = [":export_spirv_headers"],
  142. copts = COMMON_COPTS,
  143. includes = [
  144. "include",
  145. "include/SPIRV",
  146. ],
  147. linkstatic = 1,
  148. )
  149. cc_library(
  150. name = "SPIRV",
  151. srcs = glob(
  152. ["SPIRV/*.cpp"],
  153. exclude = [
  154. "SPIRV/SpvTools.cpp",
  155. ],
  156. ),
  157. hdrs = [
  158. "SPIRV/GlslangToSpv.h",
  159. "SPIRV/Logger.h",
  160. "SPIRV/SPVRemapper.h",
  161. "SPIRV/SpvBuilder.h",
  162. "SPIRV/SpvTools.h",
  163. "SPIRV/bitutils.h",
  164. "SPIRV/disassemble.h",
  165. "SPIRV/doc.h",
  166. "SPIRV/hex_float.h",
  167. "SPIRV/spvIR.h",
  168. ],
  169. copts = COMMON_COPTS,
  170. includes = ["SPIRV"],
  171. linkopts = select({
  172. "@bazel_tools//src/conditions:windows": [""],
  173. "//conditions:default": ["-lm"],
  174. }),
  175. linkstatic = 1,
  176. deps = [
  177. ":SPIRV_headers",
  178. ":glslang",
  179. ],
  180. )
  181. cc_library(
  182. name = "glslang-default-resource-limits",
  183. srcs = ["StandAlone/ResourceLimits.cpp"],
  184. hdrs = ["StandAlone/ResourceLimits.h"],
  185. copts = COMMON_COPTS,
  186. linkstatic = 1,
  187. deps = [":glslang"],
  188. )
  189. cc_binary(
  190. name = "glslangValidator",
  191. srcs = [
  192. "StandAlone/StandAlone.cpp",
  193. "StandAlone/Worklist.h",
  194. ],
  195. copts = COMMON_COPTS,
  196. deps = [
  197. ":SPIRV",
  198. ":glslang",
  199. ":glslang-default-resource-limits",
  200. ],
  201. )
  202. cc_binary(
  203. name = "spirv-remap",
  204. srcs = ["StandAlone/spirv-remap.cpp"],
  205. copts = COMMON_COPTS,
  206. deps = [
  207. ":SPIRV",
  208. ":glslang",
  209. ":glslang-default-resource-limits",
  210. ],
  211. )
  212. filegroup(
  213. name = "test_files",
  214. srcs = glob(
  215. ["Test/**"],
  216. exclude = [
  217. "Test/bump",
  218. "Test/glslangValidator",
  219. "Test/runtests",
  220. ],
  221. ),
  222. )
  223. cc_library(
  224. name = "glslang_test_lib",
  225. testonly = 1,
  226. srcs = [
  227. "gtests/HexFloat.cpp",
  228. "gtests/Initializer.h",
  229. "gtests/Settings.cpp",
  230. "gtests/Settings.h",
  231. "gtests/TestFixture.cpp",
  232. "gtests/TestFixture.h",
  233. "gtests/main.cpp",
  234. ],
  235. copts = COMMON_COPTS,
  236. data = [":test_files"],
  237. defines = select({
  238. # Unfortunately we can't use $(location) in cc_library at the moment.
  239. # See https://github.com/bazelbuild/bazel/issues/1023
  240. # So we'll specify the path manually.
  241. "@bazel_tools//src/conditions:windows":
  242. ["GLSLANG_TEST_DIRECTORY='\"../../../../../Test\"'"],
  243. "//conditions:default":
  244. ["GLSLANG_TEST_DIRECTORY='\"Test\"'"],
  245. }),
  246. linkstatic = 1,
  247. deps = [
  248. ":SPIRV",
  249. ":glslang",
  250. ":glslang-default-resource-limits",
  251. "@com_google_googletest//:gtest",
  252. ],
  253. )
  254. GLSLANG_TESTS = glob(
  255. ["gtests/*.FromFile.cpp"],
  256. # Since we are not building the SPIRV-Tools dependency, the following tests
  257. # cannot be performed.
  258. exclude = [
  259. "gtests/Hlsl.FromFile.cpp",
  260. "gtests/Spv.FromFile.cpp",
  261. ],
  262. )
  263. [cc_test(
  264. name = test_file.replace("gtests/", "").replace(".FromFile.cpp", "") + "_test",
  265. srcs = [test_file],
  266. copts = COMMON_COPTS,
  267. data = [
  268. ":test_files",
  269. ],
  270. deps = [
  271. ":SPIRV",
  272. ":glslang",
  273. ":glslang_test_lib",
  274. ],
  275. ) for test_file in GLSLANG_TESTS]