Ben Clayton | 1d21270 | 2020-07-01 15:43:36 +0100 | [diff] [blame] | 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 | # |
Ben Clayton | cb261e3 | 2020-07-03 12:21:01 +0100 | [diff] [blame] | 17 | # Neither the name of The Khronos Group Inc. nor the names of its |
Ben Clayton | 1d21270 | 2020-07-01 15:43:36 +0100 | [diff] [blame] | 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 | |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 34 | package( |
| 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 Nasiri | 4b9b07a | 2019-10-23 15:03:38 -0400 | [diff] [blame] | 42 | licenses(["notice"]) |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 43 | |
| 44 | exports_files(["LICENSE"]) |
| 45 | |
Ben Clayton | fbe9a23 | 2020-06-17 11:17:19 +0100 | [diff] [blame] | 46 | # Build information generation script |
| 47 | py_binary( |
| 48 | name = "build_info", |
| 49 | srcs = ["build_info.py"], |
| 50 | ) |
| 51 | |
| 52 | genrule( |
| 53 | name = "gen_build_info_h", |
johnkslang | 983698b | 2020-08-23 01:31:49 -0600 | [diff] [blame] | 54 | srcs = ["CHANGES.md", "build_info.h.tmpl"], |
Ben Clayton | fbe9a23 | 2020-06-17 11:17:19 +0100 | [diff] [blame] | 55 | outs = ["glslang/build_info.h"], |
Scott Bennett | 50dce09 | 2021-03-18 16:42:51 -0400 | [diff] [blame] | 56 | 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 Clayton | fbe9a23 | 2020-06-17 11:17:19 +0100 | [diff] [blame] | 58 | tools = [":build_info"], |
| 59 | ) |
| 60 | |
Ehsan Nasiri | dccaa59 | 2019-10-17 15:14:20 -0400 | [diff] [blame] | 61 | COMMON_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 Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 79 | |
| 80 | cc_library( |
| 81 | name = "glslang", |
| 82 | srcs = glob( |
| 83 | [ |
| 84 | "glslang/GenericCodeGen/*.cpp", |
Ben Clayton | f49820d | 2020-06-16 11:54:34 +0100 | [diff] [blame] | 85 | "glslang/HLSL/*.cpp", |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 86 | "glslang/MachineIndependent/*.cpp", |
| 87 | "glslang/MachineIndependent/preprocessor/*.cpp", |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 88 | ], |
| 89 | exclude = [ |
Ben Clayton | f49820d | 2020-06-16 11:54:34 +0100 | [diff] [blame] | 90 | "glslang/HLSL/pch.h", |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 91 | "glslang/MachineIndependent/pch.h", |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 92 | ], |
| 93 | ) + [ |
| 94 | "OGLCompilersDLL/InitializeDll.cpp", |
Ehsan Nasiri | dccaa59 | 2019-10-17 15:14:20 -0400 | [diff] [blame] | 95 | ] + select({ |
johnkslang | 983698b | 2020-08-23 01:31:49 -0600 | [diff] [blame] | 96 | "@bazel_tools//src/conditions:windows": |
| 97 | ["glslang/OSDependent/Windows/ossource.cpp"], |
| 98 | "//conditions:default": |
| 99 | ["glslang/OSDependent/Unix/ossource.cpp"], |
Ehsan Nasiri | dccaa59 | 2019-10-17 15:14:20 -0400 | [diff] [blame] | 100 | }), |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 101 | hdrs = glob([ |
Ben Clayton | f49820d | 2020-06-16 11:54:34 +0100 | [diff] [blame] | 102 | "glslang/HLSL/*.h", |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 103 | "glslang/Include/*.h", |
| 104 | "glslang/MachineIndependent/*.h", |
| 105 | "glslang/MachineIndependent/preprocessor/*.h", |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 106 | ]) + [ |
| 107 | "OGLCompilersDLL/InitializeDll.h", |
| 108 | "StandAlone/DirStackFileIncluder.h", |
| 109 | "glslang/OSDependent/osinclude.h", |
| 110 | "glslang/Public/ShaderLang.h", |
Ben Clayton | fbe9a23 | 2020-06-17 11:17:19 +0100 | [diff] [blame] | 111 | ":gen_build_info_h", |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 112 | ], |
| 113 | copts = COMMON_COPTS, |
| 114 | defines = [ |
| 115 | "AMD_EXTENSIONS", |
| 116 | "ENABLE_HLSL=0", |
| 117 | "ENABLE_OPT=0", |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 118 | "NV_EXTENSIONS", |
| 119 | ], |
Ehsan Nasiri | dccaa59 | 2019-10-17 15:14:20 -0400 | [diff] [blame] | 120 | linkopts = select({ |
| 121 | "@bazel_tools//src/conditions:windows": [""], |
johnkslang | 983698b | 2020-08-23 01:31:49 -0600 | [diff] [blame] | 122 | "//conditions:default": ["-lm", "-lpthread"], |
Ehsan Nasiri | dccaa59 | 2019-10-17 15:14:20 -0400 | [diff] [blame] | 123 | }), |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 124 | linkstatic = 1, |
| 125 | ) |
| 126 | |
| 127 | genrule( |
| 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 Franke | c8274e9 | 2020-03-21 03:20:25 -0400 | [diff] [blame] | 135 | "SPIRV/NonSemanticDebugPrintf.h", |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 136 | "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 Franke | c8274e9 | 2020-03-21 03:20:25 -0400 | [diff] [blame] | 144 | "include/SPIRV/NonSemanticDebugPrintf.h", |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 145 | "include/SPIRV/spirv.hpp", |
| 146 | ], |
Scott Bennett | 50dce09 | 2021-03-18 16:42:51 -0400 | [diff] [blame] | 147 | 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 Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 149 | ) |
| 150 | |
| 151 | cc_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 | |
| 162 | cc_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 Nasiri | dccaa59 | 2019-10-17 15:14:20 -0400 | [diff] [blame] | 184 | linkopts = select({ |
| 185 | "@bazel_tools//src/conditions:windows": [""], |
| 186 | "//conditions:default": ["-lm"], |
| 187 | }), |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 188 | linkstatic = 1, |
| 189 | deps = [ |
| 190 | ":SPIRV_headers", |
| 191 | ":glslang", |
| 192 | ], |
| 193 | ) |
| 194 | |
| 195 | cc_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 | |
| 204 | cc_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 | |
| 218 | cc_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 | |
johnkslang | 983698b | 2020-08-23 01:31:49 -0600 | [diff] [blame] | 229 | filegroup( |
| 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 Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 241 | cc_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, |
johnkslang | 983698b | 2020-08-23 01:31:49 -0600 | [diff] [blame] | 254 | 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 Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 264 | linkstatic = 1, |
| 265 | deps = [ |
| 266 | ":SPIRV", |
| 267 | ":glslang", |
| 268 | ":glslang-default-resource-limits", |
| 269 | "@com_google_googletest//:gtest", |
| 270 | ], |
| 271 | ) |
| 272 | |
| 273 | GLSLANG_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 Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 286 | copts = COMMON_COPTS, |
| 287 | data = [ |
johnkslang | 983698b | 2020-08-23 01:31:49 -0600 | [diff] [blame] | 288 | ":test_files", |
Ehsan Nasiri | 0608b9d | 2019-10-16 16:55:23 -0400 | [diff] [blame] | 289 | ], |
| 290 | deps = [ |
| 291 | ":SPIRV", |
| 292 | ":glslang", |
| 293 | ":glslang_test_lib", |
| 294 | ], |
| 295 | ) for test_file in GLSLANG_TESTS] |