blob: bfb77974a6f912d8a9c54a762b8937487210959f [file] [log] [blame]
Ben Clayton1d212702020-07-01 15:43:36 +01001# 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#
Ben Claytoncb261e32020-07-03 12:21:01 +010017# Neither the name of The Khronos Group Inc. nor the names of its
Ben Clayton1d212702020-07-01 15:43:36 +010018# 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
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -040034package(
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
Ehsan Nasiri4b9b07a2019-10-23 15:03:38 -040042licenses(["notice"])
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -040043
44exports_files(["LICENSE"])
45
Ben Claytonfbe9a232020-06-17 11:17:19 +010046# Build information generation script
47py_binary(
48 name = "build_info",
49 srcs = ["build_info.py"],
50)
51
52genrule(
53 name = "gen_build_info_h",
johnkslang983698b2020-08-23 01:31:49 -060054 srcs = ["CHANGES.md", "build_info.h.tmpl"],
Ben Claytonfbe9a232020-06-17 11:17:19 +010055 outs = ["glslang/build_info.h"],
56 cmd = "$(location build_info) $$(dirname $(location CHANGES.md)) -i $(location build_info.h.tmpl) -o $(location glslang/build_info.h)",
57 tools = [":build_info"],
58)
59
Ehsan Nasiridccaa592019-10-17 15:14:20 -040060COMMON_COPTS = select({
61 "@bazel_tools//src/conditions:windows": [""],
62 "//conditions:default": [
63 "-Wall",
64 "-Wuninitialized",
65 "-Wunused",
66 "-Wunused-local-typedefs",
67 "-Wunused-parameter",
68 "-Wunused-value",
69 "-Wunused-variable",
70 "-Wno-reorder",
71 "-std=c++11",
72 "-fvisibility=hidden",
73 "-fvisibility-inlines-hidden",
74 "-fno-exceptions",
75 "-fno-rtti",
76 ],
77})
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -040078
79cc_library(
80 name = "glslang",
81 srcs = glob(
82 [
83 "glslang/GenericCodeGen/*.cpp",
Ben Claytonf49820d2020-06-16 11:54:34 +010084 "glslang/HLSL/*.cpp",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -040085 "glslang/MachineIndependent/*.cpp",
86 "glslang/MachineIndependent/preprocessor/*.cpp",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -040087 ],
88 exclude = [
Ben Claytonf49820d2020-06-16 11:54:34 +010089 "glslang/HLSL/pch.h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -040090 "glslang/MachineIndependent/pch.h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -040091 ],
92 ) + [
93 "OGLCompilersDLL/InitializeDll.cpp",
Ehsan Nasiridccaa592019-10-17 15:14:20 -040094 ] + select({
johnkslang983698b2020-08-23 01:31:49 -060095 "@bazel_tools//src/conditions:windows":
96 ["glslang/OSDependent/Windows/ossource.cpp"],
97 "//conditions:default":
98 ["glslang/OSDependent/Unix/ossource.cpp"],
Ehsan Nasiridccaa592019-10-17 15:14:20 -040099 }),
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400100 hdrs = glob([
Ben Claytonf49820d2020-06-16 11:54:34 +0100101 "glslang/HLSL/*.h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400102 "glslang/Include/*.h",
103 "glslang/MachineIndependent/*.h",
104 "glslang/MachineIndependent/preprocessor/*.h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400105 ]) + [
106 "OGLCompilersDLL/InitializeDll.h",
107 "StandAlone/DirStackFileIncluder.h",
108 "glslang/OSDependent/osinclude.h",
109 "glslang/Public/ShaderLang.h",
Ben Claytonfbe9a232020-06-17 11:17:19 +0100110 ":gen_build_info_h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400111 ],
112 copts = COMMON_COPTS,
113 defines = [
114 "AMD_EXTENSIONS",
115 "ENABLE_HLSL=0",
116 "ENABLE_OPT=0",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400117 "NV_EXTENSIONS",
118 ],
Ehsan Nasiridccaa592019-10-17 15:14:20 -0400119 linkopts = select({
120 "@bazel_tools//src/conditions:windows": [""],
johnkslang983698b2020-08-23 01:31:49 -0600121 "//conditions:default": ["-lm", "-lpthread"],
Ehsan Nasiridccaa592019-10-17 15:14:20 -0400122 }),
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400123 linkstatic = 1,
124)
125
126genrule(
127 name = "export_spirv_headers",
128 srcs = [
129 "SPIRV/GLSL.ext.AMD.h",
130 "SPIRV/GLSL.ext.EXT.h",
131 "SPIRV/GLSL.ext.KHR.h",
132 "SPIRV/GLSL.ext.NV.h",
133 "SPIRV/GLSL.std.450.h",
Aaron Frankec8274e92020-03-21 03:20:25 -0400134 "SPIRV/NonSemanticDebugPrintf.h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400135 "SPIRV/spirv.hpp",
136 ],
137 outs = [
138 "include/SPIRV/GLSL.ext.AMD.h",
139 "include/SPIRV/GLSL.ext.EXT.h",
140 "include/SPIRV/GLSL.ext.KHR.h",
141 "include/SPIRV/GLSL.ext.NV.h",
142 "include/SPIRV/GLSL.std.450.h",
Aaron Frankec8274e92020-03-21 03:20:25 -0400143 "include/SPIRV/NonSemanticDebugPrintf.h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400144 "include/SPIRV/spirv.hpp",
145 ],
146 cmd = "mkdir -p $(@D)/include/SPIRV && cp $(SRCS) $(@D)/include/SPIRV/",
147)
148
149cc_library(
150 name = "SPIRV_headers",
151 hdrs = [":export_spirv_headers"],
152 copts = COMMON_COPTS,
153 includes = [
154 "include",
155 "include/SPIRV",
156 ],
157 linkstatic = 1,
158)
159
160cc_library(
161 name = "SPIRV",
162 srcs = glob(
163 ["SPIRV/*.cpp"],
164 exclude = [
165 "SPIRV/SpvTools.cpp",
166 ],
167 ),
168 hdrs = [
169 "SPIRV/GlslangToSpv.h",
170 "SPIRV/Logger.h",
171 "SPIRV/SPVRemapper.h",
172 "SPIRV/SpvBuilder.h",
173 "SPIRV/SpvTools.h",
174 "SPIRV/bitutils.h",
175 "SPIRV/disassemble.h",
176 "SPIRV/doc.h",
177 "SPIRV/hex_float.h",
178 "SPIRV/spvIR.h",
179 ],
180 copts = COMMON_COPTS,
181 includes = ["SPIRV"],
Ehsan Nasiridccaa592019-10-17 15:14:20 -0400182 linkopts = select({
183 "@bazel_tools//src/conditions:windows": [""],
184 "//conditions:default": ["-lm"],
185 }),
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400186 linkstatic = 1,
187 deps = [
188 ":SPIRV_headers",
189 ":glslang",
190 ],
191)
192
193cc_library(
194 name = "glslang-default-resource-limits",
195 srcs = ["StandAlone/ResourceLimits.cpp"],
196 hdrs = ["StandAlone/ResourceLimits.h"],
197 copts = COMMON_COPTS,
198 linkstatic = 1,
199 deps = [":glslang"],
200)
201
202cc_binary(
203 name = "glslangValidator",
204 srcs = [
205 "StandAlone/StandAlone.cpp",
206 "StandAlone/Worklist.h",
207 ],
208 copts = COMMON_COPTS,
209 deps = [
210 ":SPIRV",
211 ":glslang",
212 ":glslang-default-resource-limits",
213 ],
214)
215
216cc_binary(
217 name = "spirv-remap",
218 srcs = ["StandAlone/spirv-remap.cpp"],
219 copts = COMMON_COPTS,
220 deps = [
221 ":SPIRV",
222 ":glslang",
223 ":glslang-default-resource-limits",
224 ],
225)
226
johnkslang983698b2020-08-23 01:31:49 -0600227filegroup(
228 name = "test_files",
229 srcs = glob(
230 ["Test/**"],
231 exclude = [
232 "Test/bump",
233 "Test/glslangValidator",
234 "Test/runtests",
235 ],
236 ),
237)
238
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400239cc_library(
240 name = "glslang_test_lib",
241 testonly = 1,
242 srcs = [
243 "gtests/HexFloat.cpp",
244 "gtests/Initializer.h",
245 "gtests/Settings.cpp",
246 "gtests/Settings.h",
247 "gtests/TestFixture.cpp",
248 "gtests/TestFixture.h",
249 "gtests/main.cpp",
250 ],
251 copts = COMMON_COPTS,
johnkslang983698b2020-08-23 01:31:49 -0600252 data = [":test_files"],
253 defines = select({
254 # Unfortunately we can't use $(location) in cc_library at the moment.
255 # See https://github.com/bazelbuild/bazel/issues/1023
256 # So we'll specify the path manually.
257 "@bazel_tools//src/conditions:windows":
258 ["GLSLANG_TEST_DIRECTORY='\"../../../../../Test\"'"],
259 "//conditions:default":
260 ["GLSLANG_TEST_DIRECTORY='\"Test\"'"],
261 }),
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400262 linkstatic = 1,
263 deps = [
264 ":SPIRV",
265 ":glslang",
266 ":glslang-default-resource-limits",
267 "@com_google_googletest//:gtest",
268 ],
269)
270
271GLSLANG_TESTS = glob(
272 ["gtests/*.FromFile.cpp"],
273 # Since we are not building the SPIRV-Tools dependency, the following tests
274 # cannot be performed.
275 exclude = [
276 "gtests/Hlsl.FromFile.cpp",
277 "gtests/Spv.FromFile.cpp",
278 ],
279)
280
281[cc_test(
282 name = test_file.replace("gtests/", "").replace(".FromFile.cpp", "") + "_test",
283 srcs = [test_file],
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400284 copts = COMMON_COPTS,
285 data = [
johnkslang983698b2020-08-23 01:31:49 -0600286 ":test_files",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400287 ],
288 deps = [
289 ":SPIRV",
290 ":glslang",
291 ":glslang_test_lib",
292 ],
293) for test_file in GLSLANG_TESTS]