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