1COMMON_COPTS = [ 2 "-DSPIRV_CHECK_CONTEXT", 3 "-DSPIRV_COLOR_TERMINAL", 4 ] + select({ 5 "@bazel_tools//src/conditions:windows": [""], 6 "//conditions:default": [ 7 "-DSPIRV_LINUX", 8 "-DSPIRV_TIMER_ENABLED", 9 "-Wall", 10 "-Wextra", 11 "-Wnon-virtual-dtor", 12 "-Wno-missing-field-initializers", 13 "-Werror", 14 "-std=c++11", 15 "-fvisibility=hidden", 16 "-fno-exceptions", 17 "-fno-rtti", 18 "-Wno-long-long", 19 "-Wshadow", 20 "-Wundef", 21 "-Wconversion", 22 "-Wno-sign-conversion", 23 ], 24}) 25 26TEST_COPTS = COMMON_COPTS + select({ 27 "@bazel_tools//src/conditions:windows": [ 28 # Disable C4503 "decorated name length exceeded" warning, 29 # triggered by some heavily templated types. 30 # We don't care much about that in test code. 31 # Important to do since we have warnings-as-errors. 32 "/wd4503" 33 ], 34 "//conditions:default": [ 35 "-Wno-undef", 36 "-Wno-self-assign", 37 "-Wno-shadow", 38 "-Wno-unused-parameter" 39 ], 40}) 41 42DEBUGINFO_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_ext_inst_debuginfo_grammar_unified1" 43CLDEBUGINFO100_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_ext_inst_opencl_debuginfo_100_grammar_unified1" 44 45def generate_core_tables(version = None): 46 if not version: 47 fail("Must specify version", "version") 48 grammars = [ 49 "@spirv_headers//:spirv_core_grammar_" + version, 50 DEBUGINFO_GRAMMAR_JSON_FILE, 51 CLDEBUGINFO100_GRAMMAR_JSON_FILE, 52 ] 53 outs = [ 54 "core.insts-{}.inc".format(version), 55 "operand.kinds-{}.inc".format(version), 56 ] 57 fmtargs = grammars + outs 58 native.genrule( 59 name = "gen_core_tables_" + version, 60 srcs = grammars, 61 outs = outs, 62 cmd = ( 63 "$(location :generate_grammar_tables) " + 64 "--spirv-core-grammar=$(location {0}) " + 65 "--extinst-debuginfo-grammar=$(location {1}) " + 66 "--extinst-cldebuginfo100-grammar=$(location {2}) " + 67 "--core-insts-output=$(location {3}) " + 68 "--operand-kinds-output=$(location {4})" 69 ).format(*fmtargs), 70 tools = [":generate_grammar_tables"], 71 visibility = ["//visibility:private"], 72 ) 73 74def generate_enum_string_mapping(version = None): 75 if not version: 76 fail("Must specify version", "version") 77 grammars = [ 78 "@spirv_headers//:spirv_core_grammar_" + version, 79 DEBUGINFO_GRAMMAR_JSON_FILE, 80 CLDEBUGINFO100_GRAMMAR_JSON_FILE, 81 ] 82 outs = [ 83 "extension_enum.inc", 84 "enum_string_mapping.inc", 85 ] 86 fmtargs = grammars + outs 87 native.genrule( 88 name = "gen_enum_string_mapping", 89 srcs = grammars, 90 outs = outs, 91 cmd = ( 92 "$(location :generate_grammar_tables) " + 93 "--spirv-core-grammar=$(location {0}) " + 94 "--extinst-debuginfo-grammar=$(location {1}) " + 95 "--extinst-cldebuginfo100-grammar=$(location {2}) " + 96 "--extension-enum-output=$(location {3}) " + 97 "--enum-string-mapping-output=$(location {4})" 98 ).format(*fmtargs), 99 tools = [":generate_grammar_tables"], 100 visibility = ["//visibility:private"], 101 ) 102 103def generate_opencl_tables(version = None): 104 if not version: 105 fail("Must specify version", "version") 106 grammars = [ 107 "@spirv_headers//:spirv_opencl_grammar_" + version, 108 ] 109 outs = ["opencl.std.insts.inc"] 110 fmtargs = grammars + outs 111 native.genrule( 112 name = "gen_opencl_tables_" + version, 113 srcs = grammars, 114 outs = outs, 115 cmd = ( 116 "$(location :generate_grammar_tables) " + 117 "--extinst-opencl-grammar=$(location {0}) " + 118 "--opencl-insts-output=$(location {1})" 119 ).format(*fmtargs), 120 tools = [":generate_grammar_tables"], 121 visibility = ["//visibility:private"], 122 ) 123 124def generate_glsl_tables(version = None): 125 if not version: 126 fail("Must specify version", "version") 127 grammars = [ 128 "@spirv_headers//:spirv_glsl_grammar_" + version, 129 ] 130 outs = ["glsl.std.450.insts.inc"] 131 fmtargs = grammars + outs 132 native.genrule( 133 name = "gen_glsl_tables_" + version, 134 srcs = grammars, 135 outs = outs, 136 cmd = ( 137 "$(location :generate_grammar_tables) " + 138 "--extinst-glsl-grammar=$(location {0}) " + 139 "--glsl-insts-output=$(location {1})" 140 ).format(*fmtargs), 141 tools = [":generate_grammar_tables"], 142 visibility = ["//visibility:private"], 143 ) 144 145def generate_vendor_tables(extension, operand_kind_prefix = ""): 146 if not extension: 147 fail("Must specify extension", "extension") 148 extension_rule = extension.replace("-", "_").replace(".", "_") 149 grammars = ["@spirv_headers//:spirv_ext_inst_{}_grammar_unified1".format(extension_rule)] 150 outs = ["{}.insts.inc".format(extension)] 151 prefices = [operand_kind_prefix] 152 fmtargs = grammars + outs + prefices 153 native.genrule( 154 name = "gen_vendor_tables_" + extension_rule, 155 srcs = grammars, 156 outs = outs, 157 cmd = ( 158 "$(location :generate_grammar_tables) " + 159 "--extinst-vendor-grammar=$(location {0}) " + 160 "--vendor-insts-output=$(location {1}) " + 161 "--vendor-operand-kind-prefix={2}" 162 ).format(*fmtargs), 163 tools = [":generate_grammar_tables"], 164 visibility = ["//visibility:private"], 165 ) 166 167def generate_extinst_lang_headers(name, grammar = None): 168 if not grammar: 169 fail("Must specify grammar", "grammar") 170 outs = [name + ".h"] 171 fmtargs = outs 172 native.genrule( 173 name = "gen_extinst_lang_headers_" + name, 174 srcs = [grammar], 175 outs = outs, 176 cmd = ( 177 "$(location :generate_language_headers) " + 178 "--extinst-grammar=$< " + 179 "--extinst-output-path=$(location {0})" 180 ).format(*fmtargs), 181 tools = [":generate_language_headers"], 182 visibility = ["//visibility:private"], 183 ) 184 185def base_test(name, srcs, deps = []): 186 if srcs == []: 187 return 188 if name[-5:] != "_test": 189 name = name + "_test" 190 native.cc_test( 191 name = "base_" + name, 192 srcs = srcs, 193 compatible_with = [], 194 copts = TEST_COPTS, 195 size = "large", 196 deps = [ 197 ":test_common", 198 "@com_google_googletest//:gtest_main", 199 "@com_google_googletest//:gtest", 200 "@com_google_effcee//:effcee", 201 ] + deps, 202 ) 203 204def link_test(name, srcs, deps = []): 205 if name[-5:] != "_test": 206 name = name + "_test" 207 native.cc_test( 208 name = "link_" + name, 209 srcs = srcs, 210 compatible_with = [], 211 copts = TEST_COPTS, 212 size = "large", 213 deps = [ 214 ":link_test_common", 215 "@com_google_googletest//:gtest_main", 216 "@com_google_googletest//:gtest", 217 "@com_google_effcee//:effcee", 218 ] + deps, 219 ) 220 221def opt_test(name, srcs, deps = []): 222 if name[-5:] != "_test": 223 name = name + "_test" 224 native.cc_test( 225 name = "opt_" + name, 226 srcs = srcs, 227 compatible_with = [], 228 copts = TEST_COPTS, 229 size = "large", 230 deps = [ 231 ":opt_test_common", 232 "@com_google_googletest//:gtest_main", 233 "@com_google_googletest//:gtest", 234 "@com_google_effcee//:effcee", 235 ] + deps, 236 ) 237 238def reduce_test(name, srcs, deps = []): 239 if name[-5:] != "_test": 240 name = name + "_test" 241 native.cc_test( 242 name = "reduce_" + name, 243 srcs = srcs, 244 compatible_with = [], 245 copts = TEST_COPTS, 246 size = "large", 247 deps = [ 248 ":reduce_test_common", 249 ":spirv_tools_reduce", 250 "@com_google_googletest//:gtest_main", 251 "@com_google_googletest//:gtest", 252 "@com_google_effcee//:effcee", 253 ] + deps, 254 ) 255 256def util_test(name, srcs, deps = []): 257 if name[-5:] != "_test": 258 name = name + "_test" 259 native.cc_test( 260 name = "util_" + name, 261 srcs = srcs, 262 compatible_with = [], 263 copts = TEST_COPTS, 264 size = "large", 265 deps = [ 266 ":opt_test_common", 267 "@com_google_googletest//:gtest_main", 268 "@com_google_googletest//:gtest", 269 "@com_google_effcee//:effcee", 270 ] + deps, 271 ) 272 273def val_test(name, srcs = [], copts = [], deps = [], **kwargs): 274 if name[-5:] != "_test": 275 name = name + "_test" 276 if name[:4] != "val_": 277 name = "val_" + name 278 native.cc_test( 279 name = name, 280 srcs = srcs, 281 compatible_with = [], 282 copts = TEST_COPTS + copts, 283 size = "large", 284 deps = [ 285 ":val_test_common", 286 "@com_google_googletest//:gtest_main", 287 "@com_google_googletest//:gtest", 288 "@com_google_effcee//:effcee", 289 ] + deps, 290 **kwargs 291 ) 292