Skip to content

Commit 80a409f

Browse files
Move Bazel workspace root, refactor BUILD files, and add aliases
- Moved Bazel workspace files (MODULE.bazel, WORKSPACE.bazel, .bazelrc, etc.) from `proto/` to the repository root. - Refactored `proto/BUILD.bazel` by splitting targets into colocated BUILD files in `proto/p4/config/v1/BUILD.bazel` and `proto/p4/v1/BUILD.bazel`. - Added `strip_import_prefix = "/proto"` to proto_library targets. - Added aliases in the root `BUILD.bazel` to maintain backward compatibility for users who update their workspace root. - Added aliases in `proto/BUILD.bazel` to maintain backward compatibility for users who do not update their workspace root. - Added removal TODOs for aliases pointing to issue #576. - Split `proto_build_test` into per-package build tests and aggregated them in a root `test_suite`. - Updated example projects to use the new canonical targets and workspace root. Fixes #571.
1 parent aeb9bac commit 80a409f

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

BUILD.bazel

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exports_files(["LICENSE", "p4runtime_deps.bzl"])
1616

1717
# Aliases for backward compatibility with the old workspace structure
1818
# where proto/ was the root.
19-
19+
# TODO(https://github.com/p4lang/p4runtime/issues/576): Remove in 2.0.
2020
alias(name = "p4types_proto", actual = "//proto/p4/config/v1:p4types_proto")
2121
alias(name = "p4info_proto", actual = "//proto/p4/config/v1:p4info_proto")
2222
alias(name = "p4data_proto", actual = "//proto/p4/v1:p4data_proto")
@@ -38,4 +38,10 @@ alias(name = "p4runtime_go_proto", actual = "//proto/p4/v1:p4runtime_go_proto")
3838
alias(name = "p4runtime_cc_grpc", actual = "//proto/p4/v1:p4runtime_cc_grpc")
3939
alias(name = "p4runtime_py_grpc", actual = "//proto/p4/v1:p4runtime_py_grpc")
4040

41-
test_suite(name = "proto_build_test", tests = ["//proto:proto_build_test"])
41+
test_suite(
42+
name = "proto_build_test",
43+
tests = [
44+
"//proto/p4/config/v1:proto_build_test",
45+
"//proto/p4/v1:proto_build_test",
46+
],
47+
)

proto/BUILD.bazel

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
load("@bazel_skylib//rules:build_test.bzl", "build_test")
21
load("@rules_license//rules:license.bzl", "license")
32

43
package(
@@ -15,6 +14,7 @@ license(
1514
exports_files(["LICENSE"])
1615

1716
# Aliases for backward compatibility
17+
# TODO(https://github.com/p4lang/p4runtime/issues/576): Remove in 2.0.
1818
alias(name = "p4types_proto", actual = "//proto/p4/config/v1:p4types_proto")
1919
alias(name = "p4info_proto", actual = "//proto/p4/config/v1:p4info_proto")
2020
alias(name = "p4data_proto", actual = "//proto/p4/v1:p4data_proto")
@@ -35,15 +35,3 @@ alias(name = "p4runtime_go_proto", actual = "//proto/p4/v1:p4runtime_go_proto")
3535

3636
alias(name = "p4runtime_cc_grpc", actual = "//proto/p4/v1:p4runtime_cc_grpc")
3737
alias(name = "p4runtime_py_grpc", actual = "//proto/p4/v1:p4runtime_py_grpc")
38-
39-
build_test(
40-
name = "proto_build_test",
41-
targets = [
42-
"//proto/p4/v1:p4data_proto",
43-
"//proto/p4/config/v1:p4info_proto",
44-
"//proto/p4/v1:p4runtime_cc_grpc",
45-
"//proto/p4/v1:p4runtime_proto",
46-
"//proto/p4/v1:p4runtime_py_grpc",
47-
"//proto/p4/config/v1:p4types_proto",
48-
],
49-
)

proto/p4/config/v1/BUILD.bazel

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load("@rules_proto//proto:defs.bzl", "proto_library")
22
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
33
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_proto_library")
4+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
45

56
package(
67
default_visibility = ["//visibility:public"],
@@ -51,3 +52,16 @@ go_proto_library(
5152
":p4types_proto",
5253
],
5354
)
55+
56+
build_test(
57+
name = "proto_build_test",
58+
targets = [
59+
":p4info_proto",
60+
":p4types_proto",
61+
":p4types_cc_proto",
62+
":p4info_cc_proto",
63+
":p4types_py_proto",
64+
":p4info_py_proto",
65+
":p4info_go_proto",
66+
],
67+
)

proto/p4/v1/BUILD.bazel

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load("@rules_proto//proto:defs.bzl", "proto_library")
22
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
33
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
44
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library")
5+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
56

67
package(
78
default_visibility = ["//visibility:public"],
@@ -71,3 +72,18 @@ py_grpc_library(
7172
srcs = [":p4runtime_proto"],
7273
deps = [":p4runtime_py_proto"],
7374
)
75+
76+
build_test(
77+
name = "proto_build_test",
78+
targets = [
79+
":p4data_proto",
80+
":p4runtime_proto",
81+
":p4data_cc_proto",
82+
":p4runtime_cc_proto",
83+
":p4data_py_proto",
84+
":p4runtime_py_proto",
85+
":p4runtime_go_proto",
86+
":p4runtime_cc_grpc",
87+
":p4runtime_py_grpc",
88+
],
89+
)

0 commit comments

Comments
 (0)