Skip to content

Commit 5ba4dc4

Browse files
committed
Restore WORKSPACE support for backwards compatibility (Bazel 6-7)
Signed-off-by: Steffen Smolka <steffen.smolka@gmail.com>
1 parent dc05994 commit 5ba4dc4

9 files changed

Lines changed: 109 additions & 152 deletions

File tree

.bazelrc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
# Use Bzlmod (`MODULE.bazel`) instead of `WORKSPACE.bazel`.
2-
common --enable_bzlmod
3-
common --noenable_workspace
4-
5-
# In Bazel 9, native C++ rules are no longer injected into the global namespace
6-
# by default. Two files in grpc 1.76.0 still use native.cc_*:
7-
# bazel/cython_library.bzl (native.cc_binary)
8-
# third_party/address_sorting/address_sorting.bzl (native.cc_library)
9-
# Restore the autoload until grpc 1.76.0.bcr.2 lands. No-op on Bazel 7/8.
10-
build --incompatible_autoload_externally=+cc_library,+cc_binary
11-
121
# Use C++17 (required for recent gRPC versions).
132
build --cxxopt=-std=c++17
143
build --host_cxxopt=-std=c++17

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9.0.0
1+
6.6.0

BUILD.bazel

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -72,45 +72,3 @@ alias(
7272
actual = "//proto/p4/v1:p4runtime_cc_grpc",
7373
deprecation = "Please use @p4runtime//proto/p4/v1:p4runtime_cc_grpc instead.",
7474
)
75-
76-
alias(
77-
name = "p4types_py_proto",
78-
actual = "//proto/p4/config/v1:p4types_py_proto",
79-
deprecation = "Please use @p4runtime//proto/p4/config/v1:p4types_py_proto instead.",
80-
)
81-
82-
alias(
83-
name = "p4info_py_proto",
84-
actual = "//proto/p4/config/v1:p4info_py_proto",
85-
deprecation = "Please use @p4runtime//proto/p4/config/v1:p4info_py_proto instead.",
86-
)
87-
88-
alias(
89-
name = "p4data_py_proto",
90-
actual = "//proto/p4/v1:p4data_py_proto",
91-
deprecation = "Please use @p4runtime//proto/p4/v1:p4data_py_proto instead.",
92-
)
93-
94-
alias(
95-
name = "p4runtime_py_proto",
96-
actual = "//proto/p4/v1:p4runtime_py_proto",
97-
deprecation = "Please use @p4runtime//proto/p4/v1:p4runtime_py_proto instead.",
98-
)
99-
100-
alias(
101-
name = "p4runtime_py_grpc",
102-
actual = "//proto/p4/v1:p4runtime_py_grpc",
103-
deprecation = "Please use @p4runtime//proto/p4/v1:p4runtime_py_grpc instead.",
104-
)
105-
106-
alias(
107-
name = "p4info_go_proto",
108-
actual = "//proto/p4/config/v1:p4info_go_proto",
109-
deprecation = "Please use @p4runtime//proto/p4/config/v1:p4info_go_proto instead.",
110-
)
111-
112-
alias(
113-
name = "p4runtime_go_proto",
114-
actual = "//proto/p4/v1:p4runtime_go_proto",
115-
deprecation = "Please use @p4runtime//proto/p4/v1:p4runtime_go_proto instead.",
116-
)

MODULE.bazel

Lines changed: 0 additions & 25 deletions
This file was deleted.

WORKSPACE.bazel

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
workspace(name = "com_github_p4lang_p4runtime")
2+
3+
load("//:p4runtime_deps.bzl", "p4runtime_deps")
4+
5+
p4runtime_deps()
6+
7+
# -- Load gRPC (before protobuf to get correct transitive dep versions) --------
8+
9+
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
10+
11+
switched_rules_by_language(
12+
name = "com_google_googleapis_imports",
13+
cc = True,
14+
grpc = True,
15+
)
16+
17+
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
18+
19+
grpc_deps()
20+
21+
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
22+
23+
grpc_extra_deps()
24+
25+
# -- Load Protobuf -------------------------------------------------------------
26+
27+
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
28+
29+
protobuf_deps()
30+
31+
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
32+
33+
rules_proto_dependencies()
34+
35+
rules_proto_toolchains()
36+
37+
# -- Load Bazel Skylib ---------------------------------------------------------
38+
39+
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
40+
41+
bazel_skylib_workspace()

WORKSPACE.bzlmod

Lines changed: 0 additions & 5 deletions
This file was deleted.

p4runtime_deps.bzl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""Load dependencies needed to compile p4runtime as a 3rd-party consumer."""
2+
3+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
4+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5+
6+
def p4runtime_deps():
7+
"""Loads dependencies needed to compile p4runtime."""
8+
if not native.existing_rule("com_google_protobuf"):
9+
http_archive(
10+
name = "com_google_protobuf",
11+
url = "https://github.com/protocolbuffers/protobuf/releases/download/v28.2/protobuf-28.2.tar.gz",
12+
strip_prefix = "protobuf-28.2",
13+
sha256 = "b2340aa47faf7ef10a0328190319d3f3bee1b24f426d4ce8f4253b6f27ce16db",
14+
)
15+
if not native.existing_rule("rules_proto"):
16+
http_archive(
17+
name = "rules_proto",
18+
sha256 = "6fb6767d1bef535310547e03247f7518b03487740c11b6c6adb7952033fe1295",
19+
strip_prefix = "rules_proto-6.0.2",
20+
url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.2/rules_proto-6.0.2.tar.gz",
21+
)
22+
# rules_go is provided transitively by grpc_deps/grpc_extra_deps.
23+
if not native.existing_rule("com_google_googleapis"):
24+
git_repository(
25+
name = "com_google_googleapis",
26+
remote = "https://github.com/googleapis/googleapis",
27+
commit = "c0fcb35628690e9eb15dcefae41c651c67cd050b",
28+
)
29+
if not native.existing_rule("com_github_grpc_grpc"):
30+
http_archive(
31+
name = "com_github_grpc_grpc",
32+
url = "https://github.com/grpc/grpc/archive/refs/tags/v1.63.0.tar.gz",
33+
strip_prefix = "grpc-1.63.0",
34+
sha256 = "493d9905aa09124c2f44268b66205dd013f3925a7e82995f36745974e97af609",
35+
)
36+
if not native.existing_rule("bazel_skylib"):
37+
http_archive(
38+
name = "bazel_skylib",
39+
sha256 = "3b5b49006181f5f8ff626ef8ddceaa95e9bb8ad294f7b5d7b11ea9f7ddaf8c59",
40+
urls = [
41+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.9.0/bazel-skylib-1.9.0.tar.gz",
42+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.9.0/bazel-skylib-1.9.0.tar.gz",
43+
],
44+
)
45+
if not native.existing_rule("rules_license"):
46+
http_archive(
47+
name = "rules_license",
48+
urls = [
49+
"https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/1.0.0/rules_license-1.0.0.tar.gz",
50+
"https://github.com/bazelbuild/rules_license/releases/download/1.0.0/rules_license-1.0.0.tar.gz",
51+
],
52+
sha256 = "26d4021f6898e23b82ef953078389dd49ac2b5618ac564ade4ef87cced147b38",
53+
)
54+
if not native.existing_rule("com_google_re2"):
55+
http_archive(
56+
name = "com_google_re2",
57+
url = "https://github.com/google/re2/releases/download/2024-07-02/re2-2024-07-02.tar.gz",
58+
strip_prefix = "re2-2024-07-02",
59+
sha256 = "eb2df807c781601c14a260a507a5bb4509be1ee626024cb45acbd57cb9d4032b",
60+
)

proto/p4/config/v1/BUILD.bazel

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
load("@bazel_skylib//rules:build_test.bzl", "build_test")
2-
load("@grpc//bazel:python_rules.bzl", "py_proto_library")
3-
load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
4-
load("@protobuf//bazel:proto_library.bzl", "proto_library")
5-
load("@rules_go//proto:def.bzl", "go_proto_library")
2+
load("@rules_proto//proto:defs.bzl", "proto_library")
63

74
package(
85
default_visibility = ["//visibility:public"],
@@ -20,8 +17,8 @@ proto_library(
2017
strip_import_prefix = "/proto",
2118
deps = [
2219
":p4types_proto",
23-
"@protobuf//:any_proto",
24-
"@protobuf//:descriptor_proto",
20+
"@com_google_protobuf//:any_proto",
21+
"@com_google_protobuf//:descriptor_proto",
2522
],
2623
)
2724

@@ -35,34 +32,12 @@ cc_proto_library(
3532
deps = [":p4info_proto"],
3633
)
3734

38-
py_proto_library(
39-
name = "p4types_py_proto",
40-
deps = [":p4types_proto"],
41-
)
42-
43-
py_proto_library(
44-
name = "p4info_py_proto",
45-
deps = [":p4info_proto"],
46-
)
47-
48-
go_proto_library(
49-
name = "p4info_go_proto",
50-
importpath = "github.com/p4lang/p4runtime/go/p4/config/v1",
51-
protos = [
52-
":p4info_proto",
53-
":p4types_proto",
54-
],
55-
)
56-
5735
build_test(
5836
name = "proto_build_test",
5937
targets = [
6038
":p4info_proto",
6139
":p4types_proto",
6240
":p4types_cc_proto",
6341
":p4info_cc_proto",
64-
":p4types_py_proto",
65-
":p4info_py_proto",
66-
":p4info_go_proto",
6742
],
6843
)

proto/p4/v1/BUILD.bazel

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
load("@bazel_skylib//rules:build_test.bzl", "build_test")
2-
load("@grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
3-
load("@grpc//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library")
4-
load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
5-
load("@protobuf//bazel:proto_library.bzl", "proto_library")
6-
load("@rules_go//proto:def.bzl", "go_proto_library")
2+
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
3+
load("@rules_proto//proto:defs.bzl", "proto_library")
74

85
package(
96
default_visibility = ["//visibility:public"],
@@ -22,8 +19,8 @@ proto_library(
2219
deps = [
2320
":p4data_proto",
2421
"//proto/p4/config/v1:p4info_proto",
25-
"@googleapis//google/rpc:status_proto",
26-
"@protobuf//:any_proto",
22+
"@com_google_googleapis//google/rpc:status_proto",
23+
"@com_google_protobuf//:any_proto",
2724
],
2825
)
2926

@@ -37,29 +34,6 @@ cc_proto_library(
3734
deps = [":p4runtime_proto"],
3835
)
3936

40-
py_proto_library(
41-
name = "p4data_py_proto",
42-
deps = [":p4data_proto"],
43-
)
44-
45-
py_proto_library(
46-
name = "p4runtime_py_proto",
47-
deps = [":p4runtime_proto"],
48-
)
49-
50-
go_proto_library(
51-
name = "p4runtime_go_proto",
52-
importpath = "github.com/p4lang/p4runtime/go/p4/v1",
53-
protos = [
54-
":p4data_proto",
55-
":p4runtime_proto",
56-
],
57-
deps = [
58-
"//proto/p4/config/v1:p4info_go_proto",
59-
"@googleapis//google/rpc:status_go_proto",
60-
],
61-
)
62-
6337
cc_grpc_library(
6438
name = "p4runtime_cc_grpc",
6539
srcs = [":p4runtime_proto"],
@@ -68,23 +42,13 @@ cc_grpc_library(
6842
deps = [":p4runtime_cc_proto"],
6943
)
7044

71-
py_grpc_library(
72-
name = "p4runtime_py_grpc",
73-
srcs = [":p4runtime_proto"],
74-
deps = [":p4runtime_py_proto"],
75-
)
76-
7745
build_test(
7846
name = "proto_build_test",
7947
targets = [
8048
":p4data_proto",
8149
":p4runtime_proto",
8250
":p4data_cc_proto",
8351
":p4runtime_cc_proto",
84-
":p4data_py_proto",
85-
":p4runtime_py_proto",
86-
":p4runtime_go_proto",
8752
":p4runtime_cc_grpc",
88-
":p4runtime_py_grpc",
8953
],
9054
)

0 commit comments

Comments
 (0)