forked from KhronosGroup/SPIRV-Tools
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_defs.bzl
More file actions
174 lines (157 loc) · 5.77 KB
/
build_defs.bzl
File metadata and controls
174 lines (157 loc) · 5.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
"""Constants and macros for spirv-tools BUILD."""
COMMON_COPTS = [
"-DSPIRV_CHECK_CONTEXT",
"-DSPIRV_COLOR_TERMINAL",
] + select({
"@platforms//os:windows": [],
"//conditions:default": [
"-DSPIRV_LINUX",
"-DSPIRV_TIMER_ENABLED",
"-fvisibility=hidden",
"-fno-exceptions",
"-fno-rtti",
"-Wall",
"-Wextra",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-Werror",
"-Wno-long-long",
"-Wshadow",
"-Wundef",
"-Wconversion",
"-Wno-sign-conversion",
],
}) + select({
"//:enable_rust_target_env": ["-DSPIRV_RUST_TARGET_ENV"],
"//conditions:default": [],
}) + select({
"//:prefer_cpp_validator_default": ["-DSPIRV_PREFER_RUST_VALIDATOR_DEFAULT=0"],
"//conditions:default": ["-DSPIRV_PREFER_RUST_VALIDATOR_DEFAULT=1"],
})
TEST_COPTS = COMMON_COPTS + [
] + select({
"@platforms//os:windows": [
# Disable C4503 "decorated name length exceeded" warning,
# triggered by some heavily templated types.
# We don't care much about that in test code.
# Important to do since we have warnings-as-errors.
"/wd4503",
],
"//conditions:default": [
"-Wno-undef",
"-Wno-self-assign",
"-Wno-shadow",
"-Wno-unused-parameter",
# Work around looseness in protobuf parse table generated code
"-Wno-implicit-int-conversion",
],
})
def incompatible_with(incompatible_constraints):
return select(_merge_dicts([{"//conditions:default": []}, {
constraint: ["@platforms//:incompatible"]
for constraint in incompatible_constraints
}]))
SPIRV_CORE_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_core_grammar_unified1"
DEBUGINFO_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_ext_inst_debuginfo_grammar_unified1"
CLDEBUGINFO100_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_ext_inst_opencl_debuginfo_100_grammar_unified1"
SHDEBUGINFO100_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_ext_inst_nonsemantic_shader_debuginfo_100_grammar_unified1"
def _merge_dicts(dicts):
merged = {}
for d in dicts:
merged.update(d)
return merged
def ExtInst(name, target = "", prefix = ""):
"""
Returns a dictionary specifying the info needed to
process an extended instruction set.
Args:
name: The extension name; forms part of the .json grammar file.
target: if non-empty, the name of the bazel target in spirv-headers
that names the JSON grammar file for the extended instrution set.
If empty, the target name is derived from 'name'.
prefix: The optional prefix for names of operand enums.
Returns a dictionary with keys 'name', 'target', 'prefix' and the
corresponding values.
"""
return {"name": name, "target": target, "prefix": prefix}
def _extinst_grammar_target(e):
"""
Args: e, as returned from extinst
Returns the SPIRV-Headers target for the given extended instruction set spec.
"""
target = e["target"]
name = e["name"]
if len(target) > 0:
return "@spirv_headers//:{}".format(target)
name_part = name.replace("-", "_").replace(".", "_")
return "@spirv_headers//:spirv_ext_inst_{}_grammar_unified1".format(name_part)
def create_grammar_tables_target(name, extinsts):
"""
Creates a ":gen_compressed_tables" target for SPIR-V instruction
set grammar tables.
Args:
name: unused. Required by convention.
extinsts: list of extended instruction specs.
Each spec is a dictionary, as returned from 'extinst'.
"""
grammars = dict(
core_grammar = SPIRV_CORE_GRAMMAR_JSON_FILE,
)
outs = dict(
core_tables_header_output = "core_tables_header.inc",
core_tables_body_output = "core_tables_body.inc",
)
extinst_args = []
for e in extinsts:
extinst_args.append("--extinst={},$(location {})".format(e["prefix"], _extinst_grammar_target(e)))
cmd = (
"$(location :ggt)" +
" --spirv-core-grammar=$(location {core_grammar})" +
" --core-tables-body-output=$(location {core_tables_body_output})" +
" --core-tables-header-output=$(location {core_tables_header_output})" +
" " + " ".join(extinst_args)
).format(**_merge_dicts([grammars, outs]))
native.genrule(
name = "gen_compressed_tables",
srcs = grammars.values() + [_extinst_grammar_target(e) for e in extinsts],
outs = outs.values(),
cmd = cmd,
cmd_bat = cmd,
tools = [":ggt"],
visibility = ["//visibility:private"],
)
def generate_extinst_lang_headers(name, grammar = None):
"""
Creates a :gen_extinst_lang_headers_* target for a C++ header
the enums in a SPIR-V extended instruction set.
Args:
name: the basename of the emitted header file.
grammar: the path to the JSON grammar file for the extended
instruction set.
"""
if not grammar:
fail("Must specify grammar", "grammar")
outs = dict(
extinst_output_path = name + ".h",
)
cmd = (
"$(location :generate_language_headers)" +
" --extinst-grammar=$<" +
" --extinst-output-path=$(location {extinst_output_path})"
).format(**outs)
native.genrule(
name = "gen_extinst_lang_headers_{}".format(name),
srcs = [grammar],
outs = outs.values(),
cmd = cmd,
cmd_bat = cmd,
tools = [":generate_language_headers"],
visibility = ["//visibility:private"],
)
def build_rust_cmd(profile):
"""Returns the command to build the Rust FFI library."""
return (
"$(location :build_rust_ffi) " +
"--manifest-path $(location rust/Cargo.toml) " +
"--profile {profile} --target-dir $(@D)/cargo --output $@"
).format(profile = profile)