Disable layout error check for RT ops in presence of EXT_spirv_intrinsics
[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/spirv.hpp",
150     ],
151     outs = [
152         "include/SPIRV/GLSL.ext.AMD.h",
153         "include/SPIRV/GLSL.ext.EXT.h",
154         "include/SPIRV/GLSL.ext.KHR.h",
155         "include/SPIRV/GLSL.ext.NV.h",
156         "include/SPIRV/GLSL.std.450.h",
157         "include/SPIRV/NonSemanticDebugPrintf.h",
158         "include/SPIRV/spirv.hpp",
159     ],
160     cmd_bash = "mkdir -p $(@D)/include/SPIRV && cp $(SRCS) $(@D)/include/SPIRV/",
161     cmd_bat = "(if not exist $(@D)\\include\\SPIRV mkdir $(@D)\\include\\SPIRV) && (for %S in ($(SRCS)) do @xcopy /q %S $(@D)\\include\\SPIRV\\ >NUL)",
162 )
163
164 cc_library(
165     name = "SPIRV_headers",
166     hdrs = [":export_spirv_headers"],
167     copts = COMMON_COPTS,
168     includes = [
169         "include",
170         "include/SPIRV",
171     ],
172     linkstatic = 1,
173 )
174
175 cc_library(
176     name = "SPIRV",
177     srcs = glob(
178         ["SPIRV/*.cpp"],
179         exclude = [
180             "SPIRV/SpvTools.cpp",
181         ],
182     ),
183     hdrs = [
184         "SPIRV/GlslangToSpv.h",
185         "SPIRV/Logger.h",
186         "SPIRV/SPVRemapper.h",
187         "SPIRV/SpvBuilder.h",
188         "SPIRV/SpvTools.h",
189         "SPIRV/bitutils.h",
190         "SPIRV/disassemble.h",
191         "SPIRV/doc.h",
192         "SPIRV/hex_float.h",
193         "SPIRV/spvIR.h",
194     ],
195     copts = COMMON_COPTS,
196     includes = ["SPIRV"],
197     linkopts = select({
198         "@bazel_tools//src/conditions:windows": [""],
199         "//conditions:default": ["-lm"],
200     }),
201     linkstatic = 1,
202     deps = [
203         ":SPIRV_headers",
204         ":glslang",
205     ],
206 )
207
208 cc_library(
209     name = "glslang-default-resource-limits",
210     srcs = ["StandAlone/ResourceLimits.cpp"],
211     hdrs = ["StandAlone/ResourceLimits.h"],
212     copts = COMMON_COPTS,
213     linkstatic = 1,
214     deps = [":glslang"],
215 )
216
217 cc_binary(
218     name = "glslangValidator",
219     srcs = [
220         "StandAlone/StandAlone.cpp",
221         "StandAlone/Worklist.h",
222         ":glslang/glsl_intrinsic_header.h"
223     ],
224     copts = COMMON_COPTS,
225     deps = [
226         ":SPIRV",
227         ":glslang",
228         ":glslang-default-resource-limits",
229     ],
230 )
231
232 cc_binary(
233     name = "spirv-remap",
234     srcs = ["StandAlone/spirv-remap.cpp"],
235     copts = COMMON_COPTS,
236     deps = [
237         ":SPIRV",
238         ":glslang",
239         ":glslang-default-resource-limits",
240     ],
241 )
242
243 filegroup(
244     name = "test_files",
245     srcs = glob(
246         ["Test/**"],
247         exclude = [
248             "Test/bump",
249             "Test/glslangValidator",
250             "Test/runtests",
251         ],
252     ),
253 )
254
255 cc_library(
256     name = "glslang_test_lib",
257     testonly = 1,
258     srcs = [
259         "gtests/HexFloat.cpp",
260         "gtests/Initializer.h",
261         "gtests/Settings.cpp",
262         "gtests/Settings.h",
263         "gtests/TestFixture.cpp",
264         "gtests/TestFixture.h",
265         "gtests/main.cpp",
266     ],
267     copts = COMMON_COPTS,
268     data = [":test_files"],
269     defines = select({
270         # Unfortunately we can't use $(location) in cc_library at the moment.
271         # See https://github.com/bazelbuild/bazel/issues/1023
272         # So we'll specify the path manually.
273         "@bazel_tools//src/conditions:windows":
274             ["GLSLANG_TEST_DIRECTORY='\"../../../../../Test\"'"],
275         "//conditions:default":
276             ["GLSLANG_TEST_DIRECTORY='\"Test\"'"],
277     }),
278     linkstatic = 1,
279     deps = [
280         ":SPIRV",
281         ":glslang",
282         ":glslang-default-resource-limits",
283         "@com_google_googletest//:gtest",
284     ],
285 )
286
287 GLSLANG_TESTS = glob(
288     ["gtests/*.FromFile.cpp"],
289     # Since we are not building the SPIRV-Tools dependency, the following tests
290     # cannot be performed.
291     exclude = [
292         "gtests/Hlsl.FromFile.cpp",
293         "gtests/Spv.FromFile.cpp",
294     ],
295 )
296
297 [cc_test(
298     name = test_file.replace("gtests/", "").replace(".FromFile.cpp", "") + "_test",
299     srcs = [test_file],
300     copts = COMMON_COPTS,
301     data = [
302         ":test_files",
303     ],
304     deps = [
305         ":SPIRV",
306         ":glslang",
307         ":glslang_test_lib",
308     ],
309 ) for test_file in GLSLANG_TESTS]