Skip to content

Commit

Permalink
Update the Bazel build files (#4190)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
fruffy-g authored Oct 12, 2023
1 parent d79e2e8 commit ac0d049
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 18 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
control-plane/p4runtime
test/frameworks/gtest
bazel/example
build
4 changes: 2 additions & 2 deletions .github/workflows/ci-bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Install bazelisk
run: |
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.7.1/$BAZEL"
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.18.0/$BAZEL"
chmod +x $BAZEL
sudo mv $BAZEL /usr/local/bin/bazel
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Install bazelisk
run: |
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.4.0/$BAZEL"
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.18.0/$BAZEL"
chmod +x $BAZEL
sudo mv $BAZEL /usr/local/bin/bazel
Expand Down
16 changes: 13 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
load("@rules_license//rules:license.bzl", "license")
load("//:bazel/flex.bzl", "genlex")
load("//:bazel/bison.bzl", "genyacc")

package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
licenses = ["notice"],
)

license(
name = "license",
package_name = "com_github_p4lang_p4c",
license_kinds = [
"@rules_license//licenses/spdx:Apache-2.0",
],
license_text = "LICENSE",
)

filegroup(
Expand Down Expand Up @@ -146,10 +156,10 @@ filegroup(
"frontends/p4-14/ir-v1.def",
"backends/bmv2/bmv2.def",
"backends/dpdk/dpdk.def",
"//backends/p4tools:p4tools.def",
"//backends/p4tools:ir_extension",
# p4c extensions may set this target to a `filegroup` containing
# additional .def files.
"@com_github_p4lang_p4c_extension//:ir_extensions",
"@com_github_p4lang_p4c_extension//:ir_extension",
],
)

Expand Down
32 changes: 24 additions & 8 deletions backends/p4tools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# The BUILD file for p4testgen, inspired by the tool's cmake build rules.

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

package(
default_applicable_licenses = ["//:license"],
licenses = ["notice"],
)

# Extend the list with the name of the desired targets (in "modules/testgen/targets/).
TESTGEN_TARGETS = [
"bmv2",
]
TESTGEN_TARGETS = ["bmv2"]

filegroup(
name = "ir_extension",
srcs = ["p4tools.def"],
visibility = ["//visibility:public"], # So p4c can compile these.
)

genrule(
name = "version",
Expand Down Expand Up @@ -72,10 +77,14 @@ genrule(
filegroup(
name = "testgen_targets_src",
srcs =
glob(["modules/testgen/targets/%s/**/*.h" % target for target in TESTGEN_TARGETS],
exclude = ["modules/testgen/targets/%s/test/**" % target for target in TESTGEN_TARGETS]) +
glob(["modules/testgen/targets/%s/**/*.cpp" % target for target in TESTGEN_TARGETS],
exclude = ["modules/testgen/targets/%s/test/**" % target for target in TESTGEN_TARGETS]),
glob(
["modules/testgen/targets/%s/**/*.h" % target for target in TESTGEN_TARGETS],
exclude = ["modules/testgen/targets/%s/test/**" % target for target in TESTGEN_TARGETS],
) +
glob(
["modules/testgen/targets/%s/**/*.cpp" % target for target in TESTGEN_TARGETS],
exclude = ["modules/testgen/targets/%s/test/**" % target for target in TESTGEN_TARGETS],
),
)

cc_library(
Expand Down Expand Up @@ -133,3 +142,10 @@ cc_binary(
"//:lib",
],
)

build_test(
name = "p4testgen_build_test",
targets = [
":p4testgen",
],
)
1 change: 0 additions & 1 deletion bazel/example/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
5.4.0
2 changes: 1 addition & 1 deletion bazel/example/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
filegroup(
name = "ir_extensions",
name = "ir_extension",
srcs = glob(["*.def"]),
visibility = ["//visibility:public"], # So p4c can compile these.
)
Expand Down
2 changes: 1 addition & 1 deletion bazel/example/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local_repository(
path = "../..",
# This part is optional: only needed for custom backends with IR extensions.
repo_mapping = {
# Tells p4c where to look for `:ir_extensions` target: in this project.
# Tells p4c where to look for `:ir_extension` target: in this project.
"@com_github_p4lang_p4c_extension" : "@example_p4_project",
},
)
Expand Down
4 changes: 2 additions & 2 deletions bazel/p4c_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
def p4c_deps():
"""Loads dependencies need to compile p4c."""
# Third party projects can define the target
# @com_github_p4lang_p4c_extension:ir_extensions with a `filegroup`
# @com_github_p4lang_p4c_extension:ir_extension with a `filegroup`
# containing their custom .def files.
if not native.existing_rule("com_github_p4lang_p4c_extension"):
# By default, no IR extensions.
Expand All @@ -15,7 +15,7 @@ def p4c_deps():
path = ".",
build_file_content = """
filegroup(
name = "ir_extensions",
name = "ir_extension",
srcs = [],
visibility = ["//visibility:public"],
)
Expand Down

0 comments on commit ac0d049

Please sign in to comment.