Use CMake's builtin functionality for PCHs
[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.h",
76             "glslang/MachineIndependent/pch.h",
77         ],
78     ) + [
79         "OGLCompilersDLL/InitializeDll.cpp",
80     ] + select({
81         "@bazel_tools//src/conditions:windows":
82             ["glslang/OSDependent/Windows/ossource.cpp"],
83         "//conditions:default":
84             ["glslang/OSDependent/Unix/ossource.cpp"],
85     }),
86     hdrs = glob([
87         "glslang/HLSL/*.h",
88         "glslang/Include/*.h",
89         "glslang/MachineIndependent/*.h",
90         "glslang/MachineIndependent/preprocessor/*.h",
91     ]) + [
92         "OGLCompilersDLL/InitializeDll.h",
93         "StandAlone/DirStackFileIncluder.h",
94         "glslang/OSDependent/osinclude.h",
95         "glslang/Public/ShaderLang.h",
96     ],
97     copts = COMMON_COPTS,
98     defines = [
99         "AMD_EXTENSIONS",
100         "ENABLE_HLSL=0",
101         "ENABLE_OPT=0",
102         "NV_EXTENSIONS",
103     ],
104     linkopts = select({
105         "@bazel_tools//src/conditions:windows": [""],
106         "//conditions:default": ["-lm", "-lpthread"],
107     }),
108     linkstatic = 1,
109 )
110
111 genrule(
112     name = "export_spirv_headers",
113     srcs = [
114         "SPIRV/GLSL.ext.AMD.h",
115         "SPIRV/GLSL.ext.EXT.h",
116         "SPIRV/GLSL.ext.KHR.h",
117         "SPIRV/GLSL.ext.NV.h",
118         "SPIRV/GLSL.std.450.h",
119         "SPIRV/NonSemanticDebugPrintf.h",
120         "SPIRV/spirv.hpp",
121     ],
122     outs = [
123         "include/SPIRV/GLSL.ext.AMD.h",
124         "include/SPIRV/GLSL.ext.EXT.h",
125         "include/SPIRV/GLSL.ext.KHR.h",
126         "include/SPIRV/GLSL.ext.NV.h",
127         "include/SPIRV/GLSL.std.450.h",
128         "include/SPIRV/NonSemanticDebugPrintf.h",
129         "include/SPIRV/spirv.hpp",
130     ],
131     cmd = "mkdir -p $(@D)/include/SPIRV && cp $(SRCS) $(@D)/include/SPIRV/",
132 )
133
134 cc_library(
135     name = "SPIRV_headers",
136     hdrs = [":export_spirv_headers"],
137     copts = COMMON_COPTS,
138     includes = [
139         "include",
140         "include/SPIRV",
141     ],
142     linkstatic = 1,
143 )
144
145 cc_library(
146     name = "SPIRV",
147     srcs = glob(
148         ["SPIRV/*.cpp"],
149         exclude = [
150             "SPIRV/SpvTools.cpp",
151         ],
152     ),
153     hdrs = [
154         "SPIRV/GlslangToSpv.h",
155         "SPIRV/Logger.h",
156         "SPIRV/SPVRemapper.h",
157         "SPIRV/SpvBuilder.h",
158         "SPIRV/SpvTools.h",
159         "SPIRV/bitutils.h",
160         "SPIRV/disassemble.h",
161         "SPIRV/doc.h",
162         "SPIRV/hex_float.h",
163         "SPIRV/spvIR.h",
164     ],
165     copts = COMMON_COPTS,
166     includes = ["SPIRV"],
167     linkopts = select({
168         "@bazel_tools//src/conditions:windows": [""],
169         "//conditions:default": ["-lm"],
170     }),
171     linkstatic = 1,
172     deps = [
173         ":SPIRV_headers",
174         ":glslang",
175     ],
176 )
177
178 cc_library(
179     name = "glslang-default-resource-limits",
180     srcs = ["StandAlone/ResourceLimits.cpp"],
181     hdrs = ["StandAlone/ResourceLimits.h"],
182     copts = COMMON_COPTS,
183     linkstatic = 1,
184     deps = [":glslang"],
185 )
186
187 cc_binary(
188     name = "glslangValidator",
189     srcs = [
190         "StandAlone/StandAlone.cpp",
191         "StandAlone/Worklist.h",
192     ],
193     copts = COMMON_COPTS,
194     deps = [
195         ":SPIRV",
196         ":glslang",
197         ":glslang-default-resource-limits",
198     ],
199 )
200
201 cc_binary(
202     name = "spirv-remap",
203     srcs = ["StandAlone/spirv-remap.cpp"],
204     copts = COMMON_COPTS,
205     deps = [
206         ":SPIRV",
207         ":glslang",
208         ":glslang-default-resource-limits",
209     ],
210 )
211
212 filegroup(
213     name = "test_files",
214     srcs = glob(
215         ["Test/**"],
216         exclude = [
217             "Test/bump",
218             "Test/glslangValidator",
219             "Test/runtests",
220         ],
221     ),
222 )
223
224 cc_library(
225     name = "glslang_test_lib",
226     testonly = 1,
227     srcs = [
228         "gtests/HexFloat.cpp",
229         "gtests/Initializer.h",
230         "gtests/Settings.cpp",
231         "gtests/Settings.h",
232         "gtests/TestFixture.cpp",
233         "gtests/TestFixture.h",
234         "gtests/main.cpp",
235     ],
236     copts = COMMON_COPTS,
237     data = [":test_files"],
238     defines = select({
239         # Unfortunately we can't use $(location) in cc_library at the moment.
240         # See https://github.com/bazelbuild/bazel/issues/1023
241         # So we'll specify the path manually.
242         "@bazel_tools//src/conditions:windows":
243             ["GLSLANG_TEST_DIRECTORY='\"../../../../../Test\"'"],
244         "//conditions:default":
245             ["GLSLANG_TEST_DIRECTORY='\"Test\"'"],
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     copts = COMMON_COPTS,
270     data = [
271         ":test_files",
272     ],
273     deps = [
274         ":SPIRV",
275         ":glslang",
276         ":glslang_test_lib",
277     ],
278 ) for test_file in GLSLANG_TESTS]