forked from AdarshRawat1/P4c-Documentation-Hosting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BUILD.bazel
502 lines (462 loc) · 13.3 KB
/
BUILD.bazel
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
load("@rules_license//rules:license.bzl", "license")
load("//:bazel/flex.bzl", "genlex")
load("//:bazel/bison.bzl", "genyacc")
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
)
license(
name = "license",
package_name = "com_github_p4lang_p4c",
license_kinds = ["@rules_license//licenses/spdx:Apache-2.0"],
license_text = "LICENSE",
)
exports_files(["LICENSE"])
filegroup(
name = "p4include",
srcs = glob(["p4include/**/*.p4"]),
)
genrule(
name = "sed_config_h",
srcs = ["cmake/config.h.cmake"],
outs = ["config.h"],
# TODO: We should actually check these properly instead of just #undefing them.
# Maybe select() can help here?
cmd = "sed -e 's|cmakedefine|define|g' \
-e 's|define HAVE_LIBGC 1|undef HAVE_LIBGC|g' \
-e 's|define HAVE_LIBBACKTRACE 1|undef HAVE_LIBBACKTRACE|g' \
-e 's|define HAVE_MM_MALLOC_H 1|undef HAVE_MM_MALLOC_H|g' \
< $(SRCS) > $(OUTS)",
visibility = ["//visibility:private"],
)
cc_library(
name = "config_h",
hdrs = ["config.h"],
include_prefix = ".",
deps = [":sed_config_h"],
)
cc_library(
name = "lib",
srcs = glob(["lib/*.cpp"]),
hdrs = glob(["lib/*.h"]),
deps = [
":config_h",
"@boost//:format",
"@boost//:multiprecision",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:node_hash_set",
"@com_google_absl//absl/numeric:bits",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_googletest//:gtest",
],
)
genyacc(
name = "p4_parser_yacc",
src = "frontends/parsers/p4/p4parser.ypp",
extra_outs = ["frontends/parsers/p4/stack.hh"],
header_out = "frontends/parsers/p4/p4parser.hpp",
source_out = "frontends/parsers/p4/p4parser.cc",
visibility = ["//visibility:private"],
)
genyacc(
name = "v1_parser_yacc",
src = "frontends/parsers/v1/v1parser.ypp",
extra_outs = ["frontends/parsers/v1/stack.hh"],
header_out = "frontends/parsers/v1/v1parser.hpp",
source_out = "frontends/parsers/v1/v1parser.cc",
visibility = ["//visibility:private"],
)
genrule(
name = "p4lexer_lex",
srcs = ["frontends/parsers/p4/p4lexer.ll"],
outs = ["frontends/parsers/p4/p4lexer.lex"],
cmd = "sed '/%option outfile=\"lex.yy.c\"/d' $(SRCS) > $(OUTS)",
visibility = ["//visibility:private"],
)
genlex(
name = "p4lexer",
src = "frontends/parsers/p4/p4lexer.lex",
out = "frontends/parsers/p4/p4lexer.cc",
prefix = "yy",
visibility = ["//visibility:private"],
)
genrule(
name = "v1lexer_lex",
srcs = ["frontends/parsers/v1/v1lexer.ll"],
outs = ["frontends/parsers/v1/v1lexer.lex"],
cmd = "sed '/%option outfile=\"lex.yy.c\"/d' $(SRCS) > $(OUTS)",
visibility = ["//visibility:private"],
)
genlex(
name = "v1lexer",
src = "frontends/parsers/v1/v1lexer.lex",
out = "frontends/parsers/v1/v1lexer.cc",
prefix = "yy",
visibility = ["//visibility:private"],
)
# The ir-generator tool uses a parser built by these genlex and genyacc rules.
genlex(
name = "ir_generator_lex",
src = "tools/ir-generator/ir-generator-lex.l",
out = "tools/ir-generator/ir-generator-lex.c",
prefix = "yy",
visibility = ["//visibility:private"],
)
genyacc(
name = "ir_generator_yacc",
src = "tools/ir-generator/ir-generator.ypp",
header_out = "tools/ir-generator/ir-generator-yacc.hh",
source_out = "tools/ir-generator/ir-generator-yacc.cc",
visibility = ["//visibility:private"],
)
# This cc_library contains the ir-generator tool sources, including the
# ir-generator parser source from the lex/yacc output. The srcs attribute
# excludes generator.cpp since it is part of the cc_binary.
cc_library(
name = "ir_generator_lib",
srcs = glob(
include = ["tools/ir-generator/*.cpp"],
exclude = ["tools/ir-generator/generator.cpp"],
) + [
"tools/ir-generator/ir-generator-yacc.cc",
],
hdrs = glob(["tools/ir-generator/*.h"]),
textual_hdrs = [
":ir_generator_lex",
":ir_generator_yacc",
],
visibility = ["//visibility:private"],
deps = [
":lib",
],
)
# The next rule builds the ir-generator tool binary.
cc_binary(
name = "ir_generator",
srcs = ["tools/ir-generator/generator.cpp"],
deps = [
":ir_generator_lib",
":lib",
],
)
filegroup(
name = "ir_extra_defs",
srcs = [
"frontends/p4-14/ir-v1.def",
"backends/bmv2/bmv2.def",
"backends/dpdk/dpdk.def",
"//backends/p4tools:ir_extension",
# p4c extensions may set this target to a `filegroup` containing
# additional .def files.
"@com_github_p4lang_p4c_extension//:ir_extension",
],
)
genrule(
name = "ir_generated_files",
srcs = glob(["ir/*.def"]) + [":ir_extra_defs"],
outs = [
"ir/gen-tree-macro.h",
"ir/ir-generated.cpp",
"ir/ir-generated.h",
],
cmd = """
$(location :ir_generator) \
-t $(RULEDIR)/ir/gen-tree-macro.h \
-i $(RULEDIR)/ir/ir-generated.cpp \
-o $(RULEDIR)/ir/ir-generated.h \
$(location ir/base.def) \
$(location ir/type.def) \
$(location ir/expression.def) \
$(location ir/ir.def) \
$(location ir/v1.def) \
$(locations :ir_extra_defs)
""",
tools = [":ir_generator"],
visibility = ["//visibility:private"],
)
# It would be better to build these modules separately, but they have cyclic
# dependencies.
cc_library(
name = "ir_frontend_midend_control_plane",
srcs = glob([
"ir/**/*.cpp",
"frontends/**/*.cpp",
"midend/**/*.cpp",
"control-plane/**/*.cpp",
]) + [
"frontends/parsers/p4/p4parser.cc",
"frontends/parsers/v1/v1parser.cc",
"frontends/parsers/p4/p4lexer.cc",
"frontends/parsers/v1/v1lexer.cc",
"ir/ir-generated.cpp",
"backends/dpdk/spec.cpp",
"backends/dpdk/dbprint-dpdk.cpp",
"backends/dpdk/printUtils.cpp",
],
copts = [
# Where p4c should look for p4include at runtime.
("-DCONFIG_PKGDATADIR=\\\"external/%s\\\"" % repository_name()),
# This will work only if the binary is executed by Bazel. For a general
# solution, we would need to make p4c aware of Bazel, specifically:
# https://github.com/bazelbuild/bazel/blob/master/tools/cpp/runfiles/runfiles_src.h
],
textual_hdrs = glob([
"ir/**/*.h",
"frontends/**/*.h",
"frontends/**/*.hpp",
"midend/**/*.h",
"control-plane/**/*.h",
"backends/**/*.h",
]) + [
":p4_parser_yacc",
":v1_parser_yacc",
":p4lexer",
":v1lexer",
":ir_generated_files",
],
deps = [
":config_h",
":lib",
":p4info_dpdk_cc_proto",
"@boost//:algorithm",
"@boost//:functional",
"@boost//:iostreams",
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
"@com_github_p4lang_p4runtime//:p4types_cc_proto",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/container:inlined_vector",
"@com_google_absl//absl/strings",
"@com_google_protobuf//:protobuf",
],
)
cc_library(
name = "test_helpers",
srcs = ["test/gtest/helpers.cpp"],
hdrs = ["test/gtest/helpers.h"],
data = ["test"],
deps = [
":ir_frontend_midend_control_plane",
"@com_google_googletest//:gtest",
],
)
cc_library(
name = "p4c_backends_common_lib",
srcs = glob(["backends/common/*.cpp"]),
hdrs = glob(["backends/common/*.h"]),
deps = [
":ir_frontend_midend_control_plane",
":lib",
],
)
cc_library(
name = "p4c_bmv2_common_lib",
srcs = glob(["backends/bmv2/common/*.cpp"]),
hdrs = glob(["backends/bmv2/common/*.h"]),
deps = [
":ir_frontend_midend_control_plane",
":lib",
":p4c_backends_common_lib",
],
)
cc_library(
name = "p4c_bmv2_simple_lib",
srcs = glob(
["backends/bmv2/simple_switch/*.cpp"],
exclude = ["backends/bmv2/simple_switch/main.cpp"],
),
hdrs = glob(["backends/bmv2/simple_switch/*.h"]),
deps = [
":ir_frontend_midend_control_plane",
":lib",
":p4c_backends_common_lib",
":p4c_bmv2_common_lib",
],
)
genrule(
name = "p4c_bmv2_version",
srcs = ["backends/bmv2/simple_switch/version.h.cmake"],
outs = ["backends/bmv2/simple_switch/version.h"],
cmd = "sed 's|@P4C_VERSION@|0.0.0.0|g' $(SRCS) > $(OUTS)",
visibility = ["//visibility:private"],
)
cc_binary(
name = "p4c_bmv2",
srcs = [
"backends/bmv2/simple_switch/main.cpp",
"backends/bmv2/simple_switch/version.h",
],
data = [":p4include"],
deps = [
":ir_frontend_midend_control_plane",
":lib",
":p4c_backends_common_lib",
":p4c_bmv2_common_lib",
":p4c_bmv2_simple_lib",
],
)
# dpdk backend
genrule(
name = "dest_dir_dpdk",
srcs = ["backends/dpdk/control-plane/proto/p4info.proto"],
outs = ["backends/dpdk/p4/config/p4info.proto"],
cmd = "mkdir -p p4/config/dpdk; cp $(SRCS) $(OUTS)",
visibility = ["//visibility:private"],
)
proto_library(
name = "p4info_dpdk_proto",
srcs = ["backends/dpdk/p4/config/p4info.proto"],
deps = [
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:descriptor_proto",
],
)
cc_proto_library(
name = "p4info_dpdk_cc_proto",
deps = [":p4info_dpdk_proto"],
)
cc_library(
name = "p4c_dpdk_lib",
srcs = glob(
[
"backends/dpdk/*.cpp",
"backends/dpdk/control-plane/*.cpp",
],
exclude = [
"backends/dpdk/main.cpp",
"backends/dpdk/spec.cpp",
"backends/dpdk/printUtils.cpp",
"backends/dpdk/dbprint-dpdk.cpp",
],
) + ["backends/bmv2/common/lower.cpp"],
hdrs = glob([
"backends/dpdk/*.h",
"backends/dpdk/control-plane/*.h",
]) + ["backends/bmv2/common/lower.h"],
deps = [
":ir_frontend_midend_control_plane",
":lib",
":p4info_dpdk_cc_proto",
],
)
genrule(
name = "p4c_dpdk_version",
srcs = ["backends/dpdk/version.h.cmake"],
outs = ["backends/dpdk/version.h"],
cmd = "sed 's|@P4C_VERSION@|0.0.0.0|g' $(SRCS) > $(OUTS)",
visibility = ["//visibility:private"],
)
cc_binary(
name = "p4c_dpdk",
srcs = [
"backends/dpdk/main.cpp",
"backends/dpdk/version.h",
],
data = [":p4include"],
deps = [
":ir_frontend_midend_control_plane",
":lib",
":p4c_dpdk_lib",
],
)
# This builds the p4test backend.
cc_binary(
name = "p4c_backend_p4test",
srcs = [
"backends/p4test/p4test.cpp",
],
deps = [
":ir_frontend_midend_control_plane",
":lib",
":p4c_backend_p4test_lib",
],
)
genrule(
name = "p4c_p4test_version",
srcs = ["backends/p4test/version.h.cmake"],
outs = ["backends/p4test/version.h"],
cmd = "sed 's|@P4C_VERSION@|0.0.0.0|g' $(SRCS) > $(OUTS)",
visibility = ["//visibility:private"],
)
cc_library(
name = "p4c_backend_p4test_lib",
srcs = [
"backends/p4test/midend.cpp",
],
hdrs = [
"backends/p4test/midend.h",
"backends/p4test/version.h",
],
deps = [
":ir_frontend_midend_control_plane",
":lib",
],
)
# These rules build the graphs backend
cc_binary(
name = "p4c_graphs",
srcs = [
"backends/graphs/p4c-graphs.cpp",
],
data = [":p4include"],
deps = [
":config_h",
":ir_frontend_midend_control_plane",
":lib",
":p4c_backend_graphs_lib",
],
)
genrule(
name = "p4c_graphs_version",
srcs = ["backends/graphs/version.h.cmake"],
outs = ["backends/graphs/version.h"],
cmd = "sed 's|@P4C_VERSION@|0.0.0.0|g' $(SRCS) > $(OUTS)",
visibility = ["//visibility:private"],
)
cc_library(
name = "p4c_backend_graphs_lib",
srcs = [
"backends/graphs/controls.cpp",
"backends/graphs/graph_visitor.cpp",
"backends/graphs/graphs.cpp",
"backends/graphs/p4c-graphs.cpp",
"backends/graphs/parsers.cpp",
],
hdrs = [
"backends/graphs/controls.h",
"backends/graphs/graph_visitor.h",
"backends/graphs/graphs.h",
"backends/graphs/parsers.h",
"backends/graphs/version.h",
],
defines = [
# Disable ADL for boost, otherwise the method resolution for
# `ordered_map` and `graph` clash on method `boost::get`
"BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP",
],
deps = [
":config_h",
":ir_frontend_midend_control_plane",
":lib",
"@boost//:graph",
],
)
buildifier(
name = "buildifier_check",
diff_command = "diff -u",
exclude_patterns = [
"./build/*",
],
lint_mode = "warn",
mode = "diff",
)
buildifier(
name = "buildifier_fix",
exclude_patterns = [
"./build/*",
],
lint_mode = "fix",
)