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