diff --git a/.bazelignore b/.bazelignore index 6a84e48ef75..89502586e76 100644 --- a/.bazelignore +++ b/.bazelignore @@ -2,3 +2,4 @@ control-plane/p4runtime test/frameworks/gtest bazel/example +build diff --git a/.github/workflows/ci-bazel.yml b/.github/workflows/ci-bazel.yml index 279afdd9743..407d7540d15 100644 --- a/.github/workflows/ci-bazel.yml +++ b/.github/workflows/ci-bazel.yml @@ -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 @@ -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 diff --git a/BUILD.bazel b/BUILD.bazel index 265df6cef26..2bc3c72d0f7 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -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( @@ -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", ], ) diff --git a/backends/p4tools/BUILD.bazel b/backends/p4tools/BUILD.bazel index 8cb29ed66f6..bc910f54ee9 100644 --- a/backends/p4tools/BUILD.bazel +++ b/backends/p4tools/BUILD.bazel @@ -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", @@ -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( @@ -133,3 +142,10 @@ cc_binary( "//:lib", ], ) + +build_test( + name = "p4testgen_build_test", + targets = [ + ":p4testgen", + ], +) diff --git a/bazel/example/.bazelversion b/bazel/example/.bazelversion index 8a30e8f94a3..e69de29bb2d 100644 --- a/bazel/example/.bazelversion +++ b/bazel/example/.bazelversion @@ -1 +0,0 @@ -5.4.0 diff --git a/bazel/example/BUILD.bazel b/bazel/example/BUILD.bazel index d67a1dca771..7fbee2d8c4e 100644 --- a/bazel/example/BUILD.bazel +++ b/bazel/example/BUILD.bazel @@ -1,5 +1,5 @@ filegroup( - name = "ir_extensions", + name = "ir_extension", srcs = glob(["*.def"]), visibility = ["//visibility:public"], # So p4c can compile these. ) diff --git a/bazel/example/WORKSPACE.bazel b/bazel/example/WORKSPACE.bazel index 9fa17a9571e..5faf6087ec0 100644 --- a/bazel/example/WORKSPACE.bazel +++ b/bazel/example/WORKSPACE.bazel @@ -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", }, ) diff --git a/bazel/p4c_deps.bzl b/bazel/p4c_deps.bzl index 58c399621cb..96d380d884c 100644 --- a/bazel/p4c_deps.bzl +++ b/bazel/p4c_deps.bzl @@ -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. @@ -15,7 +15,7 @@ def p4c_deps(): path = ".", build_file_content = """ filegroup( - name = "ir_extensions", + name = "ir_extension", srcs = [], visibility = ["//visibility:public"], )