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