1# 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# 17# Neither the name of The Khronos Group Inc. nor the names of its 18# 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 34package( 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 42licenses(["notice"]) 43 44exports_files(["LICENSE"]) 45 46# Build information generation script 47py_binary( 48 name = "build_info", 49 srcs = ["build_info.py"], 50) 51 52py_binary( 53 name = "gen_extension_headers", 54 srcs = ["gen_extension_headers.py"], 55) 56 57genrule( 58 name = "gen_build_info_h", 59 srcs = ["CHANGES.md", "build_info.h.tmpl"], 60 outs = ["glslang/build_info.h"], 61 cmd_bash = "$(location build_info) $$(dirname $(location CHANGES.md)) -i $(location build_info.h.tmpl) -o $(location glslang/build_info.h)", 62 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)", 63 tools = [":build_info"], 64) 65 66genrule( 67 name = "gen_extension_headers_h", 68 srcs = ["glslang/ExtensionHeaders", "gen_extension_headers.py"], 69 outs = ["glslang/glsl_intrinsic_header.h"], 70 cmd_bash = "$(location gen_extension_headers) -i $(location glslang/ExtensionHeaders) -o $(location glslang/glsl_intrinsic_header.h)", 71 tools = [":gen_extension_headers"], 72) 73 74COMMON_COPTS = select({ 75 "@bazel_tools//src/conditions:windows": [""], 76 "//conditions:default": [ 77 "-Wall", 78 "-Wuninitialized", 79 "-Wunused", 80 "-Wunused-local-typedefs", 81 "-Wunused-parameter", 82 "-Wunused-value", 83 "-Wunused-variable", 84 "-Wno-reorder", 85 "-std=c++11", 86 "-fvisibility=hidden", 87 "-fvisibility-inlines-hidden", 88 "-fno-exceptions", 89 "-fno-rtti", 90 ], 91}) 92 93cc_library( 94 name = "glslang", 95 srcs = glob( 96 [ 97 "glslang/GenericCodeGen/*.cpp", 98 "glslang/HLSL/*.cpp", 99 "glslang/MachineIndependent/*.cpp", 100 "glslang/MachineIndependent/preprocessor/*.cpp", 101 ], 102 exclude = [ 103 "glslang/HLSL/pch.h", 104 "glslang/MachineIndependent/pch.h", 105 ], 106 ) + [ 107 "OGLCompilersDLL/InitializeDll.cpp", 108 ] + select({ 109 "@bazel_tools//src/conditions:windows": 110 ["glslang/OSDependent/Windows/ossource.cpp"], 111 "//conditions:default": 112 ["glslang/OSDependent/Unix/ossource.cpp"], 113 }), 114 hdrs = glob([ 115 "glslang/HLSL/*.h", 116 "glslang/Include/*.h", 117 "glslang/MachineIndependent/*.h", 118 "glslang/MachineIndependent/preprocessor/*.h", 119 ]) + [ 120 "OGLCompilersDLL/InitializeDll.h", 121 "StandAlone/DirStackFileIncluder.h", 122 "glslang/OSDependent/osinclude.h", 123 "glslang/Public/ShaderLang.h", 124 ":gen_build_info_h", 125 ], 126 copts = COMMON_COPTS, 127 defines = [ 128 "AMD_EXTENSIONS", 129 "ENABLE_HLSL=0", 130 "ENABLE_OPT=0", 131 "NV_EXTENSIONS", 132 ], 133 linkopts = select({ 134 "@bazel_tools//src/conditions:windows": [""], 135 "//conditions:default": ["-lm", "-lpthread"], 136 }), 137 linkstatic = 1, 138) 139 140genrule( 141 name = "export_spirv_headers", 142 srcs = [ 143 "SPIRV/GLSL.ext.AMD.h", 144 "SPIRV/GLSL.ext.EXT.h", 145 "SPIRV/GLSL.ext.KHR.h", 146 "SPIRV/GLSL.ext.NV.h", 147 "SPIRV/GLSL.ext.ARM.h", 148 "SPIRV/GLSL.std.450.h", 149 "SPIRV/NonSemanticDebugPrintf.h", 150 "SPIRV/NonSemanticShaderDebugInfo100.h", 151 "SPIRV/spirv.hpp", 152 ], 153 outs = [ 154 "include/SPIRV/GLSL.ext.AMD.h", 155 "include/SPIRV/GLSL.ext.EXT.h", 156 "include/SPIRV/GLSL.ext.KHR.h", 157 "include/SPIRV/GLSL.ext.NV.h", 158 "include/SPIRV/GLSL.ext.ARM.h", 159 "include/SPIRV/GLSL.std.450.h", 160 "include/SPIRV/NonSemanticDebugPrintf.h", 161 "include/SPIRV/NonSemanticShaderDebugInfo100.h", 162 "include/SPIRV/spirv.hpp", 163 ], 164 cmd_bash = "mkdir -p $(@D)/include/SPIRV && cp $(SRCS) $(@D)/include/SPIRV/", 165 cmd_bat = "(if not exist $(@D)\\include\\SPIRV mkdir $(@D)\\include\\SPIRV) && (for %S in ($(SRCS)) do @xcopy /q %S $(@D)\\include\\SPIRV\\ >NUL)", 166) 167 168cc_library( 169 name = "SPIRV_headers", 170 hdrs = [":export_spirv_headers"], 171 copts = COMMON_COPTS, 172 includes = [ 173 "include", 174 "include/SPIRV", 175 ], 176 linkstatic = 1, 177) 178 179cc_library( 180 name = "SPIRV", 181 srcs = glob( 182 ["SPIRV/*.cpp"], 183 exclude = [ 184 "SPIRV/SpvTools.cpp", 185 ], 186 ), 187 hdrs = [ 188 "SPIRV/GlslangToSpv.h", 189 "SPIRV/Logger.h", 190 "SPIRV/SPVRemapper.h", 191 "SPIRV/SpvBuilder.h", 192 "SPIRV/SpvTools.h", 193 "SPIRV/bitutils.h", 194 "SPIRV/disassemble.h", 195 "SPIRV/doc.h", 196 "SPIRV/hex_float.h", 197 "SPIRV/spvIR.h", 198 ], 199 copts = COMMON_COPTS, 200 includes = ["SPIRV"], 201 linkopts = select({ 202 "@bazel_tools//src/conditions:windows": [""], 203 "//conditions:default": ["-lm"], 204 }), 205 linkstatic = 1, 206 deps = [ 207 ":SPIRV_headers", 208 ":glslang", 209 ], 210) 211 212cc_library( 213 name = "glslang-default-resource-limits", 214 srcs = ["StandAlone/ResourceLimits.cpp"], 215 hdrs = ["glslang/Public/ResourceLimits.h"], 216 copts = COMMON_COPTS, 217 linkstatic = 1, 218 deps = [":glslang"], 219) 220 221cc_binary( 222 name = "glslangValidator", 223 srcs = [ 224 "StandAlone/StandAlone.cpp", 225 "StandAlone/Worklist.h", 226 ":glslang/glsl_intrinsic_header.h" 227 ], 228 copts = COMMON_COPTS, 229 deps = [ 230 ":SPIRV", 231 ":glslang", 232 ":glslang-default-resource-limits", 233 ], 234) 235 236cc_binary( 237 name = "spirv-remap", 238 srcs = ["StandAlone/spirv-remap.cpp"], 239 copts = COMMON_COPTS, 240 deps = [ 241 ":SPIRV", 242 ":glslang", 243 ":glslang-default-resource-limits", 244 ], 245) 246 247filegroup( 248 name = "test_files", 249 srcs = glob( 250 ["Test/**"], 251 exclude = [ 252 "Test/bump", 253 "Test/glslangValidator", 254 "Test/runtests", 255 ], 256 ), 257) 258 259cc_library( 260 name = "glslang_test_lib", 261 testonly = 1, 262 srcs = [ 263 "gtests/HexFloat.cpp", 264 "gtests/Initializer.h", 265 "gtests/Settings.cpp", 266 "gtests/Settings.h", 267 "gtests/TestFixture.cpp", 268 "gtests/TestFixture.h", 269 "gtests/main.cpp", 270 ], 271 copts = COMMON_COPTS, 272 data = [":test_files"], 273 defines = select({ 274 # Unfortunately we can't use $(location) in cc_library at the moment. 275 # See https://github.com/bazelbuild/bazel/issues/1023 276 # So we'll specify the path manually. 277 "@bazel_tools//src/conditions:windows": 278 ["GLSLANG_TEST_DIRECTORY='\"../../../../../Test\"'"], 279 "//conditions:default": 280 ["GLSLANG_TEST_DIRECTORY='\"Test\"'"], 281 }), 282 linkstatic = 1, 283 deps = [ 284 ":SPIRV", 285 ":glslang", 286 ":glslang-default-resource-limits", 287 "@com_google_googletest//:gtest", 288 ], 289) 290 291GLSLANG_TESTS = glob( 292 ["gtests/*.FromFile.cpp"], 293 # Since we are not building the SPIRV-Tools dependency, the following tests 294 # cannot be performed. 295 exclude = [ 296 "gtests/Hlsl.FromFile.cpp", 297 "gtests/Spv.FromFile.cpp", 298 ], 299) 300 301[cc_test( 302 name = test_file.replace("gtests/", "").replace(".FromFile.cpp", "") + "_test", 303 srcs = [test_file], 304 copts = COMMON_COPTS, 305 data = [ 306 ":test_files", 307 ], 308 deps = [ 309 ":SPIRV", 310 ":glslang", 311 ":glslang_test_lib", 312 ], 313) for test_file in GLSLANG_TESTS] 314