Validate SPV_NV_cooperative_vector (#5972)
[KhronosGroup/SPIRV-Tools.git] / build_defs.bzl
blob76bf3e7923dff72ba1812a532f491b235b2351f7
1 """Constants and macros for spirv-tools BUILD."""
3 COMMON_COPTS = [
4     "-DSPIRV_CHECK_CONTEXT",
5     "-DSPIRV_COLOR_TERMINAL",
6 ] + select({
7     "@platforms//os:windows": [],
8     "//conditions:default": [
9         "-DSPIRV_LINUX",
10         "-DSPIRV_TIMER_ENABLED",
11         "-fvisibility=hidden",
12         "-fno-exceptions",
13         "-fno-rtti",
14         "-Wall",
15         "-Wextra",
16         "-Wnon-virtual-dtor",
17         "-Wno-missing-field-initializers",
18         "-Werror",
19         "-Wno-long-long",
20         "-Wshadow",
21         "-Wundef",
22         "-Wconversion",
23         "-Wno-sign-conversion",
24     ],
27 TEST_COPTS = COMMON_COPTS + [
28 ] + select({
29     "@platforms//os:windows": [
30         # Disable C4503 "decorated name length exceeded" warning,
31         # triggered by some heavily templated types.
32         # We don't care much about that in test code.
33         # Important to do since we have warnings-as-errors.
34         "/wd4503",
35     ],
36     "//conditions:default": [
37         "-Wno-undef",
38         "-Wno-self-assign",
39         "-Wno-shadow",
40         "-Wno-unused-parameter",
41     ],
44 def incompatible_with(incompatible_constraints):
45     return select(_merge_dicts([{"//conditions:default": []}, {
46         constraint: ["@platforms//:incompatible"]
47         for constraint in incompatible_constraints
48     }]))
50 DEBUGINFO_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_ext_inst_debuginfo_grammar_unified1"
51 CLDEBUGINFO100_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_ext_inst_opencl_debuginfo_100_grammar_unified1"
52 SHDEBUGINFO100_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_ext_inst_nonsemantic_shader_debuginfo_100_grammar_unified1"
54 def _merge_dicts(dicts):
55     merged = {}
56     for d in dicts:
57         merged.update(d)
58     return merged
60 def generate_core_tables(version):
61     if not version:
62         fail("Must specify version", "version")
64     grammars = dict(
65         core_grammar = "@spirv_headers//:spirv_core_grammar_{}".format(version),
66         debuginfo_grammar = DEBUGINFO_GRAMMAR_JSON_FILE,
67         cldebuginfo_grammar = CLDEBUGINFO100_GRAMMAR_JSON_FILE,
68     )
70     outs = dict(
71         core_insts_output = "core.insts-{}.inc".format(version),
72         operand_kinds_output = "operand.kinds-{}.inc".format(version),
73     )
75     cmd = (
76         "$(location :generate_grammar_tables)" +
77         " --spirv-core-grammar=$(location {core_grammar})" +
78         " --extinst-debuginfo-grammar=$(location {debuginfo_grammar})" +
79         " --extinst-cldebuginfo100-grammar=$(location {cldebuginfo_grammar})" +
80         " --core-insts-output=$(location {core_insts_output})" +
81         " --operand-kinds-output=$(location {operand_kinds_output})" +
82         " --output-language=c++"
83     ).format(**_merge_dicts([grammars, outs]))
85     native.genrule(
86         name = "gen_core_tables_" + version,
87         srcs = grammars.values(),
88         outs = outs.values(),
89         cmd = cmd,
90         cmd_bat = cmd,
91         tools = [":generate_grammar_tables"],
92         visibility = ["//visibility:private"],
93     )
95 def generate_enum_string_mapping(version):
96     if not version:
97         fail("Must specify version", "version")
99     grammars = dict(
100         core_grammar = "@spirv_headers//:spirv_core_grammar_{}".format(version),
101         debuginfo_grammar = DEBUGINFO_GRAMMAR_JSON_FILE,
102         cldebuginfo_grammar = CLDEBUGINFO100_GRAMMAR_JSON_FILE,
103     )
105     outs = dict(
106         extension_enum_ouput = "extension_enum.inc",
107         enum_string_mapping_output = "enum_string_mapping.inc",
108     )
110     cmd = (
111         "$(location :generate_grammar_tables)" +
112         " --spirv-core-grammar=$(location {core_grammar})" +
113         " --extinst-debuginfo-grammar=$(location {debuginfo_grammar})" +
114         " --extinst-cldebuginfo100-grammar=$(location {cldebuginfo_grammar})" +
115         " --extension-enum-output=$(location {extension_enum_ouput})" +
116         " --enum-string-mapping-output=$(location {enum_string_mapping_output})" +
117         " --output-language=c++"
118     ).format(**_merge_dicts([grammars, outs]))
120     native.genrule(
121         name = "gen_enum_string_mapping",
122         srcs = grammars.values(),
123         outs = outs.values(),
124         cmd = cmd,
125         cmd_bat = cmd,
126         tools = [":generate_grammar_tables"],
127         visibility = ["//visibility:private"],
128     )
130 def generate_opencl_tables(version):
131     if not version:
132         fail("Must specify version", "version")
134     grammars = dict(
135         opencl_grammar = "@spirv_headers//:spirv_opencl_grammar_{}".format(version),
136     )
138     outs = dict(
139         opencl_insts_output = "opencl.std.insts.inc",
140     )
142     cmd = (
143         "$(location :generate_grammar_tables)" +
144         " --extinst-opencl-grammar=$(location {opencl_grammar})" +
145         " --opencl-insts-output=$(location {opencl_insts_output})"
146     ).format(**_merge_dicts([grammars, outs]))
148     native.genrule(
149         name = "gen_opencl_tables_" + version,
150         srcs = grammars.values(),
151         outs = outs.values(),
152         cmd = cmd,
153         cmd_bat = cmd,
154         tools = [":generate_grammar_tables"],
155         visibility = ["//visibility:private"],
156     )
158 def generate_glsl_tables(version):
159     if not version:
160         fail("Must specify version", "version")
162     grammars = dict(
163         gsls_grammar = "@spirv_headers//:spirv_glsl_grammar_{}".format(version),
164     )
165     outs = dict(
166         gsls_insts_outs = "glsl.std.450.insts.inc",
167     )
169     cmd = (
170         "$(location :generate_grammar_tables)" +
171         " --extinst-glsl-grammar=$(location {gsls_grammar})" +
172         " --glsl-insts-output=$(location {gsls_insts_outs})" +
173         " --output-language=c++"
174     ).format(**_merge_dicts([grammars, outs]))
176     native.genrule(
177         name = "gen_glsl_tables_" + version,
178         srcs = grammars.values(),
179         outs = outs.values(),
180         cmd = cmd,
181         cmd_bat = cmd,
182         tools = [":generate_grammar_tables"],
183         visibility = ["//visibility:private"],
184     )
186 def generate_vendor_tables(extension, operand_kind_prefix = ""):
187     if not extension:
188         fail("Must specify extension", "extension")
190     extension_rule = extension.replace("-", "_").replace(".", "_")
191     grammars = dict(
192         vendor_grammar = "@spirv_headers//:spirv_ext_inst_{}_grammar_unified1".format(extension_rule),
193     )
194     outs = dict(
195         vendor_insts_output = "{}.insts.inc".format(extension),
196     )
197     cmd = (
198         "$(location :generate_grammar_tables)" +
199         " --extinst-vendor-grammar=$(location {vendor_grammar})" +
200         " --vendor-insts-output=$(location {vendor_insts_output})" +
201         " --vendor-operand-kind-prefix={operand_kind_prefix}"
202     ).format(operand_kind_prefix = operand_kind_prefix, **_merge_dicts([grammars, outs]))
204     native.genrule(
205         name = "gen_vendor_tables_" + extension_rule,
206         srcs = grammars.values(),
207         outs = outs.values(),
208         cmd = cmd,
209         cmd_bat = cmd,
210         tools = [":generate_grammar_tables"],
211         visibility = ["//visibility:private"],
212     )
214 def generate_extinst_lang_headers(name, grammar = None):
215     if not grammar:
216         fail("Must specify grammar", "grammar")
217     outs = dict(
218         extinst_output_path = name + ".h",
219     )
220     cmd = (
221         "$(location :generate_language_headers)" +
222         " --extinst-grammar=$<" +
223         " --extinst-output-path=$(location {extinst_output_path})"
224     ).format(**outs)
226     native.genrule(
227         name = "gen_extinst_lang_headers_{}".format(name),
228         srcs = [grammar],
229         outs = outs.values(),
230         cmd = cmd,
231         cmd_bat = cmd,
232         tools = [":generate_language_headers"],
233         visibility = ["//visibility:private"],
234     )