Revert "Update minimum SPIR-V requirement for GL_EXT_buffer_reference"
[platform/upstream/glslang.git] / BUILD.bazel
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
34 package(
35     default_visibility = ["//visibility:public"],
36 )
37
38 # Description:
39 #
40 # Khronos reference front-end for GLSL and ESSL, and sample SPIR-V generator.
41
42 licenses(["notice"])
43
44 exports_files(["LICENSE"])
45
46 # Build information generation script
47 py_binary(
48     name = "build_info",
49     srcs = ["build_info.py"],
50 )
51
52 genrule(
53     name = "gen_build_info_h",
54     srcs = ["CHANGES.md", "build_info.h.tmpl"],
55     outs = ["glslang/build_info.h"],
56     cmd_bash = "$(location build_info) $$(dirname $(location CHANGES.md)) -i $(location build_info.h.tmpl) -o $(location glslang/build_info.h)",
57     cmd_bat = "for %F in ($(location CHANGES.md)) do $(location build_info) %~dpF -i $(location build_info.h.tmpl) -o $(location glslang/build_info.h)",
58     tools = [":build_info"],
59 )
60
61 COMMON_COPTS = select({
62     "@bazel_tools//src/conditions:windows": [""],
63     "//conditions:default": [
64         "-Wall",
65         "-Wuninitialized",
66         "-Wunused",
67         "-Wunused-local-typedefs",
68         "-Wunused-parameter",
69         "-Wunused-value",
70         "-Wunused-variable",
71         "-Wno-reorder",
72         "-std=c++11",
73         "-fvisibility=hidden",
74         "-fvisibility-inlines-hidden",
75         "-fno-exceptions",
76         "-fno-rtti",
77     ],
78 })
79
80 cc_library(
81     name = "glslang",
82     srcs = glob(
83         [
84             "glslang/GenericCodeGen/*.cpp",
85             "glslang/HLSL/*.cpp",
86             "glslang/MachineIndependent/*.cpp",
87             "glslang/MachineIndependent/preprocessor/*.cpp",
88         ],
89         exclude = [
90             "glslang/HLSL/pch.h",
91             "glslang/MachineIndependent/pch.h",
92         ],
93     ) + [
94         "OGLCompilersDLL/InitializeDll.cpp",
95     ] + select({
96         "@bazel_tools//src/conditions:windows":
97             ["glslang/OSDependent/Windows/ossource.cpp"],
98         "//conditions:default":
99             ["glslang/OSDependent/Unix/ossource.cpp"],
100     }),
101     hdrs = glob([
102         "glslang/HLSL/*.h",
103         "glslang/Include/*.h",
104         "glslang/MachineIndependent/*.h",
105         "glslang/MachineIndependent/preprocessor/*.h",
106     ]) + [
107         "OGLCompilersDLL/InitializeDll.h",
108         "StandAlone/DirStackFileIncluder.h",
109         "glslang/OSDependent/osinclude.h",
110         "glslang/Public/ShaderLang.h",
111         ":gen_build_info_h",
112     ],
113     copts = COMMON_COPTS,
114     defines = [
115         "AMD_EXTENSIONS",
116         "ENABLE_HLSL=0",
117         "ENABLE_OPT=0",
118         "NV_EXTENSIONS",
119     ],
120     linkopts = select({
121         "@bazel_tools//src/conditions:windows": [""],
122         "//conditions:default": ["-lm", "-lpthread"],
123     }),
124     linkstatic = 1,
125 )
126
127 genrule(
128     name = "export_spirv_headers",
129     srcs = [
130         "SPIRV/GLSL.ext.AMD.h",
131         "SPIRV/GLSL.ext.EXT.h",
132         "SPIRV/GLSL.ext.KHR.h",
133         "SPIRV/GLSL.ext.NV.h",
134         "SPIRV/GLSL.std.450.h",
135         "SPIRV/NonSemanticDebugPrintf.h",
136         "SPIRV/spirv.hpp",
137     ],
138     outs = [
139         "include/SPIRV/GLSL.ext.AMD.h",
140         "include/SPIRV/GLSL.ext.EXT.h",
141         "include/SPIRV/GLSL.ext.KHR.h",
142         "include/SPIRV/GLSL.ext.NV.h",
143         "include/SPIRV/GLSL.std.450.h",
144         "include/SPIRV/NonSemanticDebugPrintf.h",
145         "include/SPIRV/spirv.hpp",
146     ],
147     cmd_bash = "mkdir -p $(@D)/include/SPIRV && cp $(SRCS) $(@D)/include/SPIRV/",
148     cmd_bat = "(if not exist $(@D)\\include\\SPIRV mkdir $(@D)\\include\\SPIRV) && (for %S in ($(SRCS)) do @xcopy /q %S $(@D)\\include\\SPIRV\\ >NUL)",
149 )
150
151 cc_library(
152     name = "SPIRV_headers",
153     hdrs = [":export_spirv_headers"],
154     copts = COMMON_COPTS,
155     includes = [
156         "include",
157         "include/SPIRV",
158     ],
159     linkstatic = 1,
160 )
161
162 cc_library(
163     name = "SPIRV",
164     srcs = glob(
165         ["SPIRV/*.cpp"],
166         exclude = [
167             "SPIRV/SpvTools.cpp",
168         ],
169     ),
170     hdrs = [
171         "SPIRV/GlslangToSpv.h",
172         "SPIRV/Logger.h",
173         "SPIRV/SPVRemapper.h",
174         "SPIRV/SpvBuilder.h",
175         "SPIRV/SpvTools.h",
176         "SPIRV/bitutils.h",
177         "SPIRV/disassemble.h",
178         "SPIRV/doc.h",
179         "SPIRV/hex_float.h",
180         "SPIRV/spvIR.h",
181     ],
182     copts = COMMON_COPTS,
183     includes = ["SPIRV"],
184     linkopts = select({
185         "@bazel_tools//src/conditions:windows": [""],
186         "//conditions:default": ["-lm"],
187     }),
188     linkstatic = 1,
189     deps = [
190         ":SPIRV_headers",
191         ":glslang",
192     ],
193 )
194
195 cc_library(
196     name = "glslang-default-resource-limits",
197     srcs = ["StandAlone/ResourceLimits.cpp"],
198     hdrs = ["StandAlone/ResourceLimits.h"],
199     copts = COMMON_COPTS,
200     linkstatic = 1,
201     deps = [":glslang"],
202 )
203
204 cc_binary(
205     name = "glslangValidator",
206     srcs = [
207         "StandAlone/StandAlone.cpp",
208         "StandAlone/Worklist.h",
209     ],
210     copts = COMMON_COPTS,
211     deps = [
212         ":SPIRV",
213         ":glslang",
214         ":glslang-default-resource-limits",
215     ],
216 )
217
218 cc_binary(
219     name = "spirv-remap",
220     srcs = ["StandAlone/spirv-remap.cpp"],
221     copts = COMMON_COPTS,
222     deps = [
223         ":SPIRV",
224         ":glslang",
225         ":glslang-default-resource-limits",
226     ],
227 )
228
229 filegroup(
230     name = "test_files",
231     srcs = glob(
232         ["Test/**"],
233         exclude = [
234             "Test/bump",
235             "Test/glslangValidator",
236             "Test/runtests",
237         ],
238     ),
239 )
240
241 cc_library(
242     name = "glslang_test_lib",
243     testonly = 1,
244     srcs = [
245         "gtests/HexFloat.cpp",
246         "gtests/Initializer.h",
247         "gtests/Settings.cpp",
248         "gtests/Settings.h",
249         "gtests/TestFixture.cpp",
250         "gtests/TestFixture.h",
251         "gtests/main.cpp",
252     ],
253     copts = COMMON_COPTS,
254     data = [":test_files"],
255     defines = select({
256         # Unfortunately we can't use $(location) in cc_library at the moment.
257         # See https://github.com/bazelbuild/bazel/issues/1023
258         # So we'll specify the path manually.
259         "@bazel_tools//src/conditions:windows":
260             ["GLSLANG_TEST_DIRECTORY='\"../../../../../Test\"'"],
261         "//conditions:default":
262             ["GLSLANG_TEST_DIRECTORY='\"Test\"'"],
263     }),
264     linkstatic = 1,
265     deps = [
266         ":SPIRV",
267         ":glslang",
268         ":glslang-default-resource-limits",
269         "@com_google_googletest//:gtest",
270     ],
271 )
272
273 GLSLANG_TESTS = glob(
274     ["gtests/*.FromFile.cpp"],
275     # Since we are not building the SPIRV-Tools dependency, the following tests
276     # cannot be performed.
277     exclude = [
278         "gtests/Hlsl.FromFile.cpp",
279         "gtests/Spv.FromFile.cpp",
280     ],
281 )
282
283 [cc_test(
284     name = test_file.replace("gtests/", "").replace(".FromFile.cpp", "") + "_test",
285     srcs = [test_file],
286     copts = COMMON_COPTS,
287     data = [
288         ":test_files",
289     ],
290     deps = [
291         ":SPIRV",
292         ":glslang",
293         ":glslang_test_lib",
294     ],
295 ) for test_file in GLSLANG_TESTS]