Merge pull request #1947 from ehsannas/fix_licenses
[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/spirv.hpp",
89     ],
90     outs = [
91         "include/SPIRV/GLSL.ext.AMD.h",
92         "include/SPIRV/GLSL.ext.EXT.h",
93         "include/SPIRV/GLSL.ext.KHR.h",
94         "include/SPIRV/GLSL.ext.NV.h",
95         "include/SPIRV/GLSL.std.450.h",
96         "include/SPIRV/spirv.hpp",
97     ],
98     cmd = "mkdir -p $(@D)/include/SPIRV && cp $(SRCS) $(@D)/include/SPIRV/",
99 )
100
101 cc_library(
102     name = "SPIRV_headers",
103     hdrs = [":export_spirv_headers"],
104     copts = COMMON_COPTS,
105     includes = [
106         "include",
107         "include/SPIRV",
108     ],
109     linkstatic = 1,
110 )
111
112 cc_library(
113     name = "SPIRV",
114     srcs = glob(
115         ["SPIRV/*.cpp"],
116         exclude = [
117             "SPIRV/SpvTools.cpp",
118         ],
119     ),
120     hdrs = [
121         "SPIRV/GlslangToSpv.h",
122         "SPIRV/Logger.h",
123         "SPIRV/SPVRemapper.h",
124         "SPIRV/SpvBuilder.h",
125         "SPIRV/SpvTools.h",
126         "SPIRV/bitutils.h",
127         "SPIRV/disassemble.h",
128         "SPIRV/doc.h",
129         "SPIRV/hex_float.h",
130         "SPIRV/spvIR.h",
131     ],
132     copts = COMMON_COPTS,
133     includes = ["SPIRV"],
134     linkopts = select({
135         "@bazel_tools//src/conditions:windows": [""],
136         "//conditions:default": ["-lm"],
137     }),
138     linkstatic = 1,
139     deps = [
140         ":SPIRV_headers",
141         ":glslang",
142     ],
143 )
144
145 cc_library(
146     name = "glslang-default-resource-limits",
147     srcs = ["StandAlone/ResourceLimits.cpp"],
148     hdrs = ["StandAlone/ResourceLimits.h"],
149     copts = COMMON_COPTS,
150     linkstatic = 1,
151     deps = [":glslang"],
152 )
153
154 cc_binary(
155     name = "glslangValidator",
156     srcs = [
157         "StandAlone/StandAlone.cpp",
158         "StandAlone/Worklist.h",
159     ],
160     copts = COMMON_COPTS,
161     deps = [
162         ":SPIRV",
163         ":glslang",
164         ":glslang-default-resource-limits",
165     ],
166 )
167
168 cc_binary(
169     name = "spirv-remap",
170     srcs = ["StandAlone/spirv-remap.cpp"],
171     copts = COMMON_COPTS,
172     deps = [
173         ":SPIRV",
174         ":glslang",
175         ":glslang-default-resource-limits",
176     ],
177 )
178
179 filegroup(
180     name = "test_files",
181     srcs = glob(
182         ["Test/**"],
183         exclude = [
184             "Test/bump",
185             "Test/glslangValidator",
186             "Test/runtests",
187         ],
188     ),
189 )
190
191 cc_library(
192     name = "glslang_test_lib",
193     testonly = 1,
194     srcs = [
195         "gtests/HexFloat.cpp",
196         "gtests/Initializer.h",
197         "gtests/Settings.cpp",
198         "gtests/Settings.h",
199         "gtests/TestFixture.cpp",
200         "gtests/TestFixture.h",
201         "gtests/main.cpp",
202     ],
203     copts = COMMON_COPTS,
204     data = [":test_files"],
205     defines = select({
206         # Unfortunately we can't use $(location) in cc_library at the moment.
207         # See https://github.com/bazelbuild/bazel/issues/1023
208         # So we'll specify the path manually.
209         "@bazel_tools//src/conditions:windows":
210             ["GLSLANG_TEST_DIRECTORY='\"../../../../../Test\"'"],
211         "//conditions:default":
212             ["GLSLANG_TEST_DIRECTORY='\"Test\"'"],
213     }),
214     linkstatic = 1,
215     deps = [
216         ":SPIRV",
217         ":glslang",
218         ":glslang-default-resource-limits",
219         "@com_google_googletest//:gtest",
220     ],
221 )
222
223 GLSLANG_TESTS = glob(
224     ["gtests/*.FromFile.cpp"],
225     # Since we are not building the SPIRV-Tools dependency, the following tests
226     # cannot be performed.
227     exclude = [
228         "gtests/Hlsl.FromFile.cpp",
229         "gtests/Spv.FromFile.cpp",
230     ],
231 )
232
233 [cc_test(
234     name = test_file.replace("gtests/", "").replace(".FromFile.cpp", "") + "_test",
235     srcs = [test_file],
236     copts = COMMON_COPTS,
237     data = [
238         ":test_files",
239     ],
240     deps = [
241         ":SPIRV",
242         ":glslang",
243         ":glslang_test_lib",
244     ],
245 ) for test_file in GLSLANG_TESTS]