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