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