blob: e8cf6a864bb15b0dd452c18ca9e92a5dc3ed0047 [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"],
Scott Bennett50dce092021-03-18 16:42:51 -040056 cmd_bash = "$(location build_info) $$(dirname $(location CHANGES.md)) -i $(location build_info.h.tmpl) -o $(location glslang/build_info.h)",
57 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)",
Ben Claytonfbe9a232020-06-17 11:17:19 +010058 tools = [":build_info"],
59)
60
Ehsan Nasiridccaa592019-10-17 15:14:20 -040061COMMON_COPTS = select({
62 "@bazel_tools//src/conditions:windows": [""],
63 "//conditions:default": [
64 "-Wall",
65 "-Wuninitialized",
66 "-Wunused",
67 "-Wunused-local-typedefs",
68 "-Wunused-parameter",
69 "-Wunused-value",
70 "-Wunused-variable",
71 "-Wno-reorder",
72 "-std=c++11",
73 "-fvisibility=hidden",
74 "-fvisibility-inlines-hidden",
75 "-fno-exceptions",
76 "-fno-rtti",
77 ],
78})
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -040079
80cc_library(
81 name = "glslang",
82 srcs = glob(
83 [
84 "glslang/GenericCodeGen/*.cpp",
Ben Claytonf49820d2020-06-16 11:54:34 +010085 "glslang/HLSL/*.cpp",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -040086 "glslang/MachineIndependent/*.cpp",
87 "glslang/MachineIndependent/preprocessor/*.cpp",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -040088 ],
89 exclude = [
Ben Claytonf49820d2020-06-16 11:54:34 +010090 "glslang/HLSL/pch.h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -040091 "glslang/MachineIndependent/pch.h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -040092 ],
93 ) + [
94 "OGLCompilersDLL/InitializeDll.cpp",
Ehsan Nasiridccaa592019-10-17 15:14:20 -040095 ] + select({
johnkslang983698b2020-08-23 01:31:49 -060096 "@bazel_tools//src/conditions:windows":
97 ["glslang/OSDependent/Windows/ossource.cpp"],
98 "//conditions:default":
99 ["glslang/OSDependent/Unix/ossource.cpp"],
Ehsan Nasiridccaa592019-10-17 15:14:20 -0400100 }),
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400101 hdrs = glob([
Ben Claytonf49820d2020-06-16 11:54:34 +0100102 "glslang/HLSL/*.h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400103 "glslang/Include/*.h",
104 "glslang/MachineIndependent/*.h",
105 "glslang/MachineIndependent/preprocessor/*.h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400106 ]) + [
107 "OGLCompilersDLL/InitializeDll.h",
108 "StandAlone/DirStackFileIncluder.h",
109 "glslang/OSDependent/osinclude.h",
110 "glslang/Public/ShaderLang.h",
Ben Claytonfbe9a232020-06-17 11:17:19 +0100111 ":gen_build_info_h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400112 ],
113 copts = COMMON_COPTS,
114 defines = [
115 "AMD_EXTENSIONS",
116 "ENABLE_HLSL=0",
117 "ENABLE_OPT=0",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400118 "NV_EXTENSIONS",
119 ],
Ehsan Nasiridccaa592019-10-17 15:14:20 -0400120 linkopts = select({
121 "@bazel_tools//src/conditions:windows": [""],
johnkslang983698b2020-08-23 01:31:49 -0600122 "//conditions:default": ["-lm", "-lpthread"],
Ehsan Nasiridccaa592019-10-17 15:14:20 -0400123 }),
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400124 linkstatic = 1,
125)
126
127genrule(
128 name = "export_spirv_headers",
129 srcs = [
130 "SPIRV/GLSL.ext.AMD.h",
131 "SPIRV/GLSL.ext.EXT.h",
132 "SPIRV/GLSL.ext.KHR.h",
133 "SPIRV/GLSL.ext.NV.h",
134 "SPIRV/GLSL.std.450.h",
Aaron Frankec8274e92020-03-21 03:20:25 -0400135 "SPIRV/NonSemanticDebugPrintf.h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400136 "SPIRV/spirv.hpp",
137 ],
138 outs = [
139 "include/SPIRV/GLSL.ext.AMD.h",
140 "include/SPIRV/GLSL.ext.EXT.h",
141 "include/SPIRV/GLSL.ext.KHR.h",
142 "include/SPIRV/GLSL.ext.NV.h",
143 "include/SPIRV/GLSL.std.450.h",
Aaron Frankec8274e92020-03-21 03:20:25 -0400144 "include/SPIRV/NonSemanticDebugPrintf.h",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400145 "include/SPIRV/spirv.hpp",
146 ],
Scott Bennett50dce092021-03-18 16:42:51 -0400147 cmd_bash = "mkdir -p $(@D)/include/SPIRV && cp $(SRCS) $(@D)/include/SPIRV/",
148 cmd_bat = "(if not exist $(@D)\\include\\SPIRV mkdir $(@D)\\include\\SPIRV) && (for %S in ($(SRCS)) do @xcopy /q %S $(@D)\\include\\SPIRV\\ >NUL)",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400149)
150
151cc_library(
152 name = "SPIRV_headers",
153 hdrs = [":export_spirv_headers"],
154 copts = COMMON_COPTS,
155 includes = [
156 "include",
157 "include/SPIRV",
158 ],
159 linkstatic = 1,
160)
161
162cc_library(
163 name = "SPIRV",
164 srcs = glob(
165 ["SPIRV/*.cpp"],
166 exclude = [
167 "SPIRV/SpvTools.cpp",
168 ],
169 ),
170 hdrs = [
171 "SPIRV/GlslangToSpv.h",
172 "SPIRV/Logger.h",
173 "SPIRV/SPVRemapper.h",
174 "SPIRV/SpvBuilder.h",
175 "SPIRV/SpvTools.h",
176 "SPIRV/bitutils.h",
177 "SPIRV/disassemble.h",
178 "SPIRV/doc.h",
179 "SPIRV/hex_float.h",
180 "SPIRV/spvIR.h",
181 ],
182 copts = COMMON_COPTS,
183 includes = ["SPIRV"],
Ehsan Nasiridccaa592019-10-17 15:14:20 -0400184 linkopts = select({
185 "@bazel_tools//src/conditions:windows": [""],
186 "//conditions:default": ["-lm"],
187 }),
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400188 linkstatic = 1,
189 deps = [
190 ":SPIRV_headers",
191 ":glslang",
192 ],
193)
194
195cc_library(
196 name = "glslang-default-resource-limits",
197 srcs = ["StandAlone/ResourceLimits.cpp"],
198 hdrs = ["StandAlone/ResourceLimits.h"],
199 copts = COMMON_COPTS,
200 linkstatic = 1,
201 deps = [":glslang"],
202)
203
204cc_binary(
205 name = "glslangValidator",
206 srcs = [
207 "StandAlone/StandAlone.cpp",
208 "StandAlone/Worklist.h",
209 ],
210 copts = COMMON_COPTS,
211 deps = [
212 ":SPIRV",
213 ":glslang",
214 ":glslang-default-resource-limits",
215 ],
216)
217
218cc_binary(
219 name = "spirv-remap",
220 srcs = ["StandAlone/spirv-remap.cpp"],
221 copts = COMMON_COPTS,
222 deps = [
223 ":SPIRV",
224 ":glslang",
225 ":glslang-default-resource-limits",
226 ],
227)
228
johnkslang983698b2020-08-23 01:31:49 -0600229filegroup(
230 name = "test_files",
231 srcs = glob(
232 ["Test/**"],
233 exclude = [
234 "Test/bump",
235 "Test/glslangValidator",
236 "Test/runtests",
237 ],
238 ),
239)
240
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400241cc_library(
242 name = "glslang_test_lib",
243 testonly = 1,
244 srcs = [
245 "gtests/HexFloat.cpp",
246 "gtests/Initializer.h",
247 "gtests/Settings.cpp",
248 "gtests/Settings.h",
249 "gtests/TestFixture.cpp",
250 "gtests/TestFixture.h",
251 "gtests/main.cpp",
252 ],
253 copts = COMMON_COPTS,
johnkslang983698b2020-08-23 01:31:49 -0600254 data = [":test_files"],
255 defines = select({
256 # Unfortunately we can't use $(location) in cc_library at the moment.
257 # See https://github.com/bazelbuild/bazel/issues/1023
258 # So we'll specify the path manually.
259 "@bazel_tools//src/conditions:windows":
260 ["GLSLANG_TEST_DIRECTORY='\"../../../../../Test\"'"],
261 "//conditions:default":
262 ["GLSLANG_TEST_DIRECTORY='\"Test\"'"],
263 }),
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400264 linkstatic = 1,
265 deps = [
266 ":SPIRV",
267 ":glslang",
268 ":glslang-default-resource-limits",
269 "@com_google_googletest//:gtest",
270 ],
271)
272
273GLSLANG_TESTS = glob(
274 ["gtests/*.FromFile.cpp"],
275 # Since we are not building the SPIRV-Tools dependency, the following tests
276 # cannot be performed.
277 exclude = [
278 "gtests/Hlsl.FromFile.cpp",
279 "gtests/Spv.FromFile.cpp",
280 ],
281)
282
283[cc_test(
284 name = test_file.replace("gtests/", "").replace(".FromFile.cpp", "") + "_test",
285 srcs = [test_file],
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400286 copts = COMMON_COPTS,
287 data = [
johnkslang983698b2020-08-23 01:31:49 -0600288 ":test_files",
Ehsan Nasiri0608b9d2019-10-16 16:55:23 -0400289 ],
290 deps = [
291 ":SPIRV",
292 ":glslang",
293 ":glslang_test_lib",
294 ],
295) for test_file in GLSLANG_TESTS]