Skip to content

Commit da08e66

Browse files
committed
Bazel build support.
Signed-off-by: fruffy <fruffy@nyu.edu>
1 parent b22b690 commit da08e66

File tree

1 file changed

+65
-23
lines changed

1 file changed

+65
-23
lines changed

BUILD.bazel

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ package(
1010
default_visibility = ["//visibility:public"],
1111
)
1212

13+
# Configuration setting to enable P4-14 support via --define=SUPPORT_P4_14=true
14+
config_setting(
15+
name = "p4_14_enabled",
16+
define_values = {
17+
"SUPPORT_P4_14": "true",
18+
},
19+
visibility = ["//visibility:public"],
20+
)
21+
1322
license(
1423
name = "license",
1524
package_name = "com_github_p4lang_p4c",
@@ -71,6 +80,7 @@ cc_library(
7180
],
7281
)
7382

83+
# P4-16 parser.
7484
genyacc(
7585
name = "p4_parser_yacc",
7686
src = "frontends/parsers/p4/p4parser.ypp",
@@ -80,6 +90,7 @@ genyacc(
8090
visibility = ["//visibility:private"],
8191
)
8292

93+
# P4-14 parser.
8394
genyacc(
8495
name = "v1_parser_yacc",
8596
src = "frontends/parsers/v1/v1parser.ypp",
@@ -89,6 +100,7 @@ genyacc(
89100
visibility = ["//visibility:private"],
90101
)
91102

103+
# P4-16 lexer.
92104
genrule(
93105
name = "p4lexer_lex",
94106
srcs = ["frontends/parsers/p4/p4lexer.ll"],
@@ -97,6 +109,7 @@ genrule(
97109
visibility = ["//visibility:private"],
98110
)
99111

112+
# P4-16 lexer.
100113
genlex(
101114
name = "p4lexer",
102115
src = "frontends/parsers/p4/p4lexer.lex",
@@ -105,6 +118,7 @@ genlex(
105118
visibility = ["//visibility:private"],
106119
)
107120

121+
# P4-14 lexer.
108122
genrule(
109123
name = "v1lexer_lex",
110124
srcs = ["frontends/parsers/v1/v1lexer.ll"],
@@ -113,6 +127,7 @@ genrule(
113127
visibility = ["//visibility:private"],
114128
)
115129

130+
# P4-14 lexer.
116131
genlex(
117132
name = "v1lexer",
118133
src = "frontends/parsers/v1/v1lexer.lex",
@@ -172,8 +187,11 @@ cc_binary(
172187

173188
filegroup(
174189
name = "ir_extra_defs",
175-
srcs = [
176-
"frontends/p4-14/ir-v1.def",
190+
srcs = select({
191+
# Conditionally include the P4-14 IR definition file.
192+
":p4_14_enabled": ["frontends/p4-14/ir-v1.def"],
193+
"//conditions:default": [],
194+
}) + [
177195
"backends/bmv2/bmv2.def",
178196
"backends/dpdk/dpdk.def",
179197
"//backends/p4tools:ir_extension",
@@ -205,25 +223,47 @@ genrule(
205223
visibility = ["//visibility:private"],
206224
)
207225

208-
# It would be better to build these modules separately, but they have cyclic
209-
# dependencies.
210-
cc_library(
211-
name = "ir_frontend_midend_control_plane",
212-
srcs = glob([
226+
# Define the srcs list in a variable for readability
227+
IR_FRONTEND_MIDEND_CONTROL_PLANE_SRCS = glob(
228+
[
213229
"ir/**/*.cpp",
214-
"frontends/**/*.cpp",
215230
"midend/**/*.cpp",
216231
"control-plane/**/*.cpp",
217-
]) + [
218-
"backends/dpdk/dbprint-dpdk.cpp",
219-
"backends/dpdk/printUtils.cpp",
220-
"backends/dpdk/spec.cpp",
221-
"frontends/parsers/p4/p4lexer.cc",
222-
"frontends/parsers/p4/p4parser.cc",
223-
"frontends/parsers/v1/v1lexer.cc",
224-
"frontends/parsers/v1/v1parser.cc",
225-
"ir/ir-generated.cpp",
226232
],
233+
) + [
234+
# Back end files.
235+
"backends/dpdk/dbprint-dpdk.cpp",
236+
"backends/dpdk/printUtils.cpp",
237+
"backends/dpdk/spec.cpp",
238+
"frontends/parsers/p4/p4lexer.cc",
239+
"frontends/parsers/p4/p4parser.cc",
240+
"ir/ir-generated.cpp",
241+
] + select({
242+
# Conditionally select the glob for frontend C++ files.
243+
":p4_14_enabled": glob(
244+
["frontends/**/*.cpp"],
245+
),
246+
"//conditions:default": glob(
247+
["frontends/**/*.cpp"],
248+
exclude = [
249+
"frontends/parsers/v1/v1lexer.cc",
250+
"frontends/parsers/v1/v1parser.cc",
251+
"frontends/p4-14/**/*.cpp",
252+
"frontends/parsers/v1/**/*.cpp",
253+
],
254+
),
255+
})
256+
257+
# It would be better to build these modules separately, but they have cyclic
258+
# dependencies.
259+
cc_library(
260+
name = "ir_frontend_midend_control_plane",
261+
srcs = IR_FRONTEND_MIDEND_CONTROL_PLANE_SRCS,
262+
defines = select({
263+
# Define SUPPORT_P4_14 for C++ code when the flag is set.
264+
":p4_14_enabled": ["SUPPORT_P4_14"],
265+
"//conditions:default": [],
266+
}),
227267
textual_hdrs = glob([
228268
"ir/**/*.h",
229269
"frontends/**/*.h",
@@ -233,11 +273,16 @@ cc_library(
233273
"backends/**/*.h",
234274
]) + [
235275
":p4_parser_yacc",
236-
":v1_parser_yacc",
237276
":p4lexer",
238-
":v1lexer",
239277
":ir_generated_files",
240-
],
278+
] + select({
279+
# Conditionally include the P4-14 IR definition file.
280+
":p4_14_enabled": [
281+
":v1_parser_yacc",
282+
":v1lexer",
283+
],
284+
"//conditions:default": [],
285+
}),
241286
deps = [
242287
":config_h",
243288
":lib",
@@ -476,9 +521,6 @@ cc_library(
476521
"backends/graphs/version.h",
477522
],
478523
defines = [
479-
# Disable ADL for boost, otherwise the method resolution for
480-
# `ordered_map` and `graph` clash on method `boost::get`
481-
"BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP",
482524
],
483525
deps = [
484526
":config_h",

0 commit comments

Comments
 (0)