Skip to content

Commit ac0d049

Browse files
authored
Update the Bazel build files (#4190)
* Add license function to Bazel build files. * Patch up the P4Tools build files. * Update Bazelisk version. * Remove Bazel version restriction for the indirect build. * Fix up IR Extension for example project. * Restore removed comment.
1 parent d79e2e8 commit ac0d049

File tree

8 files changed

+44
-18
lines changed

8 files changed

+44
-18
lines changed

.bazelignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
control-plane/p4runtime
33
test/frameworks/gtest
44
bazel/example
5+
build

.github/workflows/ci-bazel.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
3535
- name: Install bazelisk
3636
run: |
37-
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.7.1/$BAZEL"
37+
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.18.0/$BAZEL"
3838
chmod +x $BAZEL
3939
sudo mv $BAZEL /usr/local/bin/bazel
4040
@@ -66,7 +66,7 @@ jobs:
6666
6767
- name: Install bazelisk
6868
run: |
69-
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.4.0/$BAZEL"
69+
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.18.0/$BAZEL"
7070
chmod +x $BAZEL
7171
sudo mv $BAZEL /usr/local/bin/bazel
7272

BUILD.bazel

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
load("@rules_license//rules:license.bzl", "license")
12
load("//:bazel/flex.bzl", "genlex")
23
load("//:bazel/bison.bzl", "genyacc")
34

45
package(
6+
default_applicable_licenses = ["//:license"],
57
default_visibility = ["//visibility:public"],
6-
licenses = ["notice"],
8+
)
9+
10+
license(
11+
name = "license",
12+
package_name = "com_github_p4lang_p4c",
13+
license_kinds = [
14+
"@rules_license//licenses/spdx:Apache-2.0",
15+
],
16+
license_text = "LICENSE",
717
)
818

919
filegroup(
@@ -146,10 +156,10 @@ filegroup(
146156
"frontends/p4-14/ir-v1.def",
147157
"backends/bmv2/bmv2.def",
148158
"backends/dpdk/dpdk.def",
149-
"//backends/p4tools:p4tools.def",
159+
"//backends/p4tools:ir_extension",
150160
# p4c extensions may set this target to a `filegroup` containing
151161
# additional .def files.
152-
"@com_github_p4lang_p4c_extension//:ir_extensions",
162+
"@com_github_p4lang_p4c_extension//:ir_extension",
153163
],
154164
)
155165

backends/p4tools/BUILD.bazel

+24-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
# The BUILD file for p4testgen, inspired by the tool's cmake build rules.
22

3-
exports_files(["p4tools.def"])
3+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
44

55
package(
6+
default_applicable_licenses = ["//:license"],
67
licenses = ["notice"],
78
)
89

910
# Extend the list with the name of the desired targets (in "modules/testgen/targets/).
10-
TESTGEN_TARGETS = [
11-
"bmv2",
12-
]
11+
TESTGEN_TARGETS = ["bmv2"]
12+
13+
filegroup(
14+
name = "ir_extension",
15+
srcs = ["p4tools.def"],
16+
visibility = ["//visibility:public"], # So p4c can compile these.
17+
)
1318

1419
genrule(
1520
name = "version",
@@ -72,10 +77,14 @@ genrule(
7277
filegroup(
7378
name = "testgen_targets_src",
7479
srcs =
75-
glob(["modules/testgen/targets/%s/**/*.h" % target for target in TESTGEN_TARGETS],
76-
exclude = ["modules/testgen/targets/%s/test/**" % target for target in TESTGEN_TARGETS]) +
77-
glob(["modules/testgen/targets/%s/**/*.cpp" % target for target in TESTGEN_TARGETS],
78-
exclude = ["modules/testgen/targets/%s/test/**" % target for target in TESTGEN_TARGETS]),
80+
glob(
81+
["modules/testgen/targets/%s/**/*.h" % target for target in TESTGEN_TARGETS],
82+
exclude = ["modules/testgen/targets/%s/test/**" % target for target in TESTGEN_TARGETS],
83+
) +
84+
glob(
85+
["modules/testgen/targets/%s/**/*.cpp" % target for target in TESTGEN_TARGETS],
86+
exclude = ["modules/testgen/targets/%s/test/**" % target for target in TESTGEN_TARGETS],
87+
),
7988
)
8089

8190
cc_library(
@@ -133,3 +142,10 @@ cc_binary(
133142
"//:lib",
134143
],
135144
)
145+
146+
build_test(
147+
name = "p4testgen_build_test",
148+
targets = [
149+
":p4testgen",
150+
],
151+
)

bazel/example/.bazelversion

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
5.4.0

bazel/example/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
filegroup(
2-
name = "ir_extensions",
2+
name = "ir_extension",
33
srcs = glob(["*.def"]),
44
visibility = ["//visibility:public"], # So p4c can compile these.
55
)

bazel/example/WORKSPACE.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local_repository(
66
path = "../..",
77
# This part is optional: only needed for custom backends with IR extensions.
88
repo_mapping = {
9-
# Tells p4c where to look for `:ir_extensions` target: in this project.
9+
# Tells p4c where to look for `:ir_extension` target: in this project.
1010
"@com_github_p4lang_p4c_extension" : "@example_p4_project",
1111
},
1212
)

bazel/p4c_deps.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
66
def p4c_deps():
77
"""Loads dependencies need to compile p4c."""
88
# Third party projects can define the target
9-
# @com_github_p4lang_p4c_extension:ir_extensions with a `filegroup`
9+
# @com_github_p4lang_p4c_extension:ir_extension with a `filegroup`
1010
# containing their custom .def files.
1111
if not native.existing_rule("com_github_p4lang_p4c_extension"):
1212
# By default, no IR extensions.
@@ -15,7 +15,7 @@ def p4c_deps():
1515
path = ".",
1616
build_file_content = """
1717
filegroup(
18-
name = "ir_extensions",
18+
name = "ir_extension",
1919
srcs = [],
2020
visibility = ["//visibility:public"],
2121
)

0 commit comments

Comments
 (0)