Merge pull request #2098 from jeffbolznv/debugprintf
[platform/upstream/glslang.git] / BUILD.bazel
1 package(
2     default_visibility = ["//visibility:public"],
3 )
4
5 # Description:
6 #
7 # Khronos reference front-end for GLSL and ESSL, and sample SPIR-V generator.
8
9 licenses(["notice"])
10
11 exports_files(["LICENSE"])
12
13 COMMON_COPTS = select({
14     "@bazel_tools//src/conditions:windows": [""],
15     "//conditions:default": [
16         "-Wall",
17         "-Wuninitialized",
18         "-Wunused",
19         "-Wunused-local-typedefs",
20         "-Wunused-parameter",
21         "-Wunused-value",
22         "-Wunused-variable",
23         "-Wno-reorder",
24         "-std=c++11",
25         "-fvisibility=hidden",
26         "-fvisibility-inlines-hidden",
27         "-fno-exceptions",
28         "-fno-rtti",
29     ],
30 })
31
32 cc_library(
33     name = "glslang",
34     srcs = glob(
35         [
36             "glslang/GenericCodeGen/*.cpp",
37             "glslang/MachineIndependent/*.cpp",
38             "glslang/MachineIndependent/preprocessor/*.cpp",
39             "hlsl/*.cpp",
40         ],
41         exclude = [
42             "glslang/MachineIndependent/pch.cpp",
43             "glslang/MachineIndependent/pch.h",
44             "hlsl/pch.cpp",
45             "hlsl/pch.h",
46         ],
47     ) + [
48         "OGLCompilersDLL/InitializeDll.cpp",
49     ] + select({
50         "@bazel_tools//src/conditions:windows":
51             ["glslang/OSDependent/Windows/ossource.cpp"],
52         "//conditions:default":
53             ["glslang/OSDependent/Unix/ossource.cpp"],
54     }),
55     hdrs = glob([
56         "glslang/Include/*.h",
57         "glslang/MachineIndependent/*.h",
58         "glslang/MachineIndependent/preprocessor/*.h",
59         "hlsl/*.h",
60     ]) + [
61         "OGLCompilersDLL/InitializeDll.h",
62         "StandAlone/DirStackFileIncluder.h",
63         "glslang/OSDependent/osinclude.h",
64         "glslang/Public/ShaderLang.h",
65     ],
66     copts = COMMON_COPTS,
67     defines = [
68         "AMD_EXTENSIONS",
69         "ENABLE_HLSL=0",
70         "ENABLE_OPT=0",
71         "NV_EXTENSIONS",
72     ],
73     linkopts = select({
74         "@bazel_tools//src/conditions:windows": [""],
75         "//conditions:default": ["-lm", "-lpthread"],
76     }),
77     linkstatic = 1,
78 )
79
80 genrule(
81     name = "export_spirv_headers",
82     srcs = [
83         "SPIRV/GLSL.ext.AMD.h",
84         "SPIRV/GLSL.ext.EXT.h",
85         "SPIRV/GLSL.ext.KHR.h",
86         "SPIRV/GLSL.ext.NV.h",
87         "SPIRV/GLSL.std.450.h",
88         "SPIRV/NonSemanticDebugPrintf.h",\r
89         "SPIRV/spirv.hpp",
90     ],
91     outs = [
92         "include/SPIRV/GLSL.ext.AMD.h",
93         "include/SPIRV/GLSL.ext.EXT.h",
94         "include/SPIRV/GLSL.ext.KHR.h",
95         "include/SPIRV/GLSL.ext.NV.h",
96         "include/SPIRV/GLSL.std.450.h",
97         "include/SPIRV/NonSemanticDebugPrintf.h",\r
98         "include/SPIRV/spirv.hpp",
99     ],
100     cmd = "mkdir -p $(@D)/include/SPIRV && cp $(SRCS) $(@D)/include/SPIRV/",
101 )
102
103 cc_library(
104     name = "SPIRV_headers",
105     hdrs = [":export_spirv_headers"],
106     copts = COMMON_COPTS,
107     includes = [
108         "include",
109         "include/SPIRV",
110     ],
111     linkstatic = 1,
112 )
113
114 cc_library(
115     name = "SPIRV",
116     srcs = glob(
117         ["SPIRV/*.cpp"],
118         exclude = [
119             "SPIRV/SpvTools.cpp",
120         ],
121     ),
122     hdrs = [
123         "SPIRV/GlslangToSpv.h",
124         "SPIRV/Logger.h",
125         "SPIRV/SPVRemapper.h",
126         "SPIRV/SpvBuilder.h",
127         "SPIRV/SpvTools.h",
128         "SPIRV/bitutils.h",
129         "SPIRV/disassemble.h",
130         "SPIRV/doc.h",
131         "SPIRV/hex_float.h",
132         "SPIRV/spvIR.h",
133     ],
134     copts = COMMON_COPTS,
135     includes = ["SPIRV"],
136     linkopts = select({
137         "@bazel_tools//src/conditions:windows": [""],
138         "//conditions:default": ["-lm"],
139     }),
140     linkstatic = 1,
141     deps = [
142         ":SPIRV_headers",
143         ":glslang",
144     ],
145 )
146
147 cc_library(
148     name = "glslang-default-resource-limits",
149     srcs = ["StandAlone/ResourceLimits.cpp"],
150     hdrs = ["StandAlone/ResourceLimits.h"],
151     copts = COMMON_COPTS,
152     linkstatic = 1,
153     deps = [":glslang"],
154 )
155
156 cc_binary(
157     name = "glslangValidator",
158     srcs = [
159         "StandAlone/StandAlone.cpp",
160         "StandAlone/Worklist.h",
161     ],
162     copts = COMMON_COPTS,
163     deps = [
164         ":SPIRV",
165         ":glslang",
166         ":glslang-default-resource-limits",
167     ],
168 )
169
170 cc_binary(
171     name = "spirv-remap",
172     srcs = ["StandAlone/spirv-remap.cpp"],
173     copts = COMMON_COPTS,
174     deps = [
175         ":SPIRV",
176         ":glslang",
177         ":glslang-default-resource-limits",
178     ],
179 )
180
181 filegroup(
182     name = "test_files",
183     srcs = glob(
184         ["Test/**"],
185         exclude = [
186             "Test/bump",
187             "Test/glslangValidator",
188             "Test/runtests",
189         ],
190     ),
191 )
192
193 cc_library(
194     name = "glslang_test_lib",
195     testonly = 1,
196     srcs = [
197         "gtests/HexFloat.cpp",
198         "gtests/Initializer.h",
199         "gtests/Settings.cpp",
200         "gtests/Settings.h",
201         "gtests/TestFixture.cpp",
202         "gtests/TestFixture.h",
203         "gtests/main.cpp",
204     ],
205     copts = COMMON_COPTS,
206     data = [":test_files"],
207     defines = select({
208         # Unfortunately we can't use $(location) in cc_library at the moment.
209         # See https://github.com/bazelbuild/bazel/issues/1023
210         # So we'll specify the path manually.
211         "@bazel_tools//src/conditions:windows":
212             ["GLSLANG_TEST_DIRECTORY='\"../../../../../Test\"'"],
213         "//conditions:default":
214             ["GLSLANG_TEST_DIRECTORY='\"Test\"'"],
215     }),
216     linkstatic = 1,
217     deps = [
218         ":SPIRV",
219         ":glslang",
220         ":glslang-default-resource-limits",
221         "@com_google_googletest//:gtest",
222     ],
223 )
224
225 GLSLANG_TESTS = glob(
226     ["gtests/*.FromFile.cpp"],
227     # Since we are not building the SPIRV-Tools dependency, the following tests
228     # cannot be performed.
229     exclude = [
230         "gtests/Hlsl.FromFile.cpp",
231         "gtests/Spv.FromFile.cpp",
232     ],
233 )
234
235 [cc_test(
236     name = test_file.replace("gtests/", "").replace(".FromFile.cpp", "") + "_test",
237     srcs = [test_file],
238     copts = COMMON_COPTS,
239     data = [
240         ":test_files",
241     ],
242     deps = [
243         ":SPIRV",
244         ":glslang",
245         ":glslang_test_lib",
246     ],
247 ) for test_file in GLSLANG_TESTS]