Skip to content

Commit bd2a626

Browse files
committed
Restore WORKSPACE support without strip_import_prefix (Bazel 6-7)
Like bazel-workspace-support, but with the workspace root at proto/ and no strip_import_prefix. This makes the repo consumable via http_archive with strip_prefix=".../proto" without any path conflicts. Signed-off-by: Steffen Smolka <steffen.smolka@gmail.com>
1 parent cf148d2 commit bd2a626

9 files changed

Lines changed: 84 additions & 127 deletions

File tree

BUILD.bazel

Lines changed: 0 additions & 74 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

proto/BUILD.bazel

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,103 +11,78 @@ license(
1111
license_text = "LICENSE",
1212
)
1313

14-
exports_files(["LICENSE"])
14+
exports_files(["LICENSE", "p4runtime_deps.bzl"])
1515

1616
# -- Aliases for backward compatibility --------------------------------------
1717
# TODO(https://github.com/p4lang/p4runtime/issues/576): Remove in 2.0.
1818

1919
alias(
2020
name = "p4types_proto",
21-
actual = "//proto/p4/config/v1:p4types_proto",
22-
deprecation = "Please use @p4runtime//proto/p4/config/v1:p4types_proto instead.",
21+
actual = "//p4/config/v1:p4types_proto",
22+
deprecation = "Please use @p4runtime//p4/config/v1:p4types_proto instead.",
2323
)
2424

2525
alias(
2626
name = "p4info_proto",
27-
actual = "//proto/p4/config/v1:p4info_proto",
28-
deprecation = "Please use @p4runtime//proto/p4/config/v1:p4info_proto instead.",
27+
actual = "//p4/config/v1:p4info_proto",
28+
deprecation = "Please use @p4runtime//p4/config/v1:p4info_proto instead.",
2929
)
3030

3131
alias(
3232
name = "p4data_proto",
33-
actual = "//proto/p4/v1:p4data_proto",
34-
deprecation = "Please use @p4runtime//proto/p4/v1:p4data_proto instead.",
33+
actual = "//p4/v1:p4data_proto",
34+
deprecation = "Please use @p4runtime//p4/v1:p4data_proto instead.",
3535
)
3636

3737
alias(
3838
name = "p4runtime_proto",
39-
actual = "//proto/p4/v1:p4runtime_proto",
40-
deprecation = "Please use @p4runtime//proto/p4/v1:p4runtime_proto instead.",
39+
actual = "//p4/v1:p4runtime_proto",
40+
deprecation = "Please use @p4runtime//p4/v1:p4runtime_proto instead.",
4141
)
4242

4343
alias(
4444
name = "p4types_cc_proto",
45-
actual = "//proto/p4/config/v1:p4types_cc_proto",
46-
deprecation = "Please use @p4runtime//proto/p4/config/v1:p4types_cc_proto instead.",
45+
actual = "//p4/config/v1:p4types_cc_proto",
46+
deprecation = "Please use @p4runtime//p4/config/v1:p4types_cc_proto instead.",
4747
)
4848

4949
alias(
5050
name = "p4info_cc_proto",
51-
actual = "//proto/p4/config/v1:p4info_cc_proto",
52-
deprecation = "Please use @p4runtime//proto/p4/config/v1:p4info_cc_proto instead.",
51+
actual = "//p4/config/v1:p4info_cc_proto",
52+
deprecation = "Please use @p4runtime//p4/config/v1:p4info_cc_proto instead.",
5353
)
5454

5555
alias(
5656
name = "p4data_cc_proto",
57-
actual = "//proto/p4/v1:p4data_cc_proto",
58-
deprecation = "Please use @p4runtime//proto/p4/v1:p4data_cc_proto instead.",
57+
actual = "//p4/v1:p4data_cc_proto",
58+
deprecation = "Please use @p4runtime//p4/v1:p4data_cc_proto instead.",
5959
)
6060

6161
alias(
6262
name = "p4runtime_cc_proto",
63-
actual = "//proto/p4/v1:p4runtime_cc_proto",
64-
deprecation = "Please use @p4runtime//proto/p4/v1:p4runtime_cc_proto instead.",
63+
actual = "//p4/v1:p4runtime_cc_proto",
64+
deprecation = "Please use @p4runtime//p4/v1:p4runtime_cc_proto instead.",
6565
)
6666

6767
alias(
6868
name = "p4runtime_cc_grpc",
69-
actual = "//proto/p4/v1:p4runtime_cc_grpc",
70-
deprecation = "Please use @p4runtime//proto/p4/v1:p4runtime_cc_grpc instead.",
69+
actual = "//p4/v1:p4runtime_cc_grpc",
70+
deprecation = "Please use @p4runtime//p4/v1:p4runtime_cc_grpc instead.",
7171
)
7272

73-
alias(
74-
name = "p4types_py_proto",
75-
actual = "//proto/p4/config/v1:p4types_py_proto",
76-
deprecation = "Please use @p4runtime//proto/p4/config/v1:p4types_py_proto instead.",
77-
)
7873

79-
alias(
80-
name = "p4info_py_proto",
81-
actual = "//proto/p4/config/v1:p4info_py_proto",
82-
deprecation = "Please use @p4runtime//proto/p4/config/v1:p4info_py_proto instead.",
83-
)
8474

85-
alias(
86-
name = "p4data_py_proto",
87-
actual = "//proto/p4/v1:p4data_py_proto",
88-
deprecation = "Please use @p4runtime//proto/p4/v1:p4data_py_proto instead.",
89-
)
9075

91-
alias(
92-
name = "p4runtime_py_proto",
93-
actual = "//proto/p4/v1:p4runtime_py_proto",
94-
deprecation = "Please use @p4runtime//proto/p4/v1:p4runtime_py_proto instead.",
95-
)
9676

97-
alias(
98-
name = "p4runtime_py_grpc",
99-
actual = "//proto/p4/v1:p4runtime_py_grpc",
100-
deprecation = "Please use @p4runtime//proto/p4/v1:p4runtime_py_grpc instead.",
101-
)
77+
78+
10279

10380
alias(
10481
name = "p4info_go_proto",
105-
actual = "//proto/p4/config/v1:p4info_go_proto",
106-
deprecation = "Please use @p4runtime//proto/p4/config/v1:p4info_go_proto instead.",
82+
actual = "//p4/config/v1:p4info_go_proto",
10783
)
10884

10985
alias(
11086
name = "p4runtime_go_proto",
111-
actual = "//proto/p4/v1:p4runtime_go_proto",
112-
deprecation = "Please use @p4runtime//proto/p4/v1:p4runtime_go_proto instead.",
87+
actual = "//p4/v1:p4runtime_go_proto",
11388
)

proto/WORKSPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
WORKSPACE.bazel

WORKSPACE.bazel renamed to proto/WORKSPACE.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,24 @@ load("//:p4runtime_deps.bzl", "p4runtime_deps")
44

55
p4runtime_deps()
66

7+
# -- Load Go rules (before grpc to use our pinned version) --------------------
8+
9+
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies")
10+
11+
go_rules_dependencies()
12+
13+
load("@bazel_features//:deps.bzl", "bazel_features_deps")
14+
15+
bazel_features_deps()
16+
717
# -- Load gRPC (before protobuf to get correct transitive dep versions) --------
818

919
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
1020

1121
switched_rules_by_language(
1222
name = "com_google_googleapis_imports",
1323
cc = True,
24+
go = True,
1425
grpc = True,
1526
)
1627

proto/p4/config/v1/BUILD.bazel

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@bazel_skylib//rules:build_test.bzl", "build_test")
2+
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
23
load("@rules_proto//proto:defs.bzl", "proto_library")
34

45
package(
@@ -8,13 +9,11 @@ package(
89
proto_library(
910
name = "p4types_proto",
1011
srcs = ["p4types.proto"],
11-
strip_import_prefix = "/proto",
1212
)
1313

1414
proto_library(
1515
name = "p4info_proto",
1616
srcs = ["p4info.proto"],
17-
strip_import_prefix = "/proto",
1817
deps = [
1918
":p4types_proto",
2019
"@com_google_protobuf//:any_proto",
@@ -32,12 +31,22 @@ cc_proto_library(
3231
deps = [":p4info_proto"],
3332
)
3433

34+
go_proto_library(
35+
name = "p4info_go_proto",
36+
importpath = "github.com/p4lang/p4runtime/go/p4/config/v1",
37+
protos = [
38+
":p4info_proto",
39+
":p4types_proto",
40+
],
41+
)
42+
3543
build_test(
3644
name = "proto_build_test",
3745
targets = [
3846
":p4info_proto",
3947
":p4types_proto",
4048
":p4types_cc_proto",
4149
":p4info_cc_proto",
50+
":p4info_go_proto",
4251
],
4352
)

proto/p4/v1/BUILD.bazel

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("@bazel_skylib//rules:build_test.bzl", "build_test")
22
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
3+
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
34
load("@rules_proto//proto:defs.bzl", "proto_library")
45

56
package(
@@ -9,16 +10,14 @@ package(
910
proto_library(
1011
name = "p4data_proto",
1112
srcs = ["p4data.proto"],
12-
strip_import_prefix = "/proto",
1313
)
1414

1515
proto_library(
1616
name = "p4runtime_proto",
1717
srcs = ["p4runtime.proto"],
18-
strip_import_prefix = "/proto",
1918
deps = [
2019
":p4data_proto",
21-
"//proto/p4/config/v1:p4info_proto",
20+
"//p4/config/v1:p4info_proto",
2221
"@com_google_googleapis//google/rpc:status_proto",
2322
"@com_google_protobuf//:any_proto",
2423
],
@@ -42,6 +41,19 @@ cc_grpc_library(
4241
deps = [":p4runtime_cc_proto"],
4342
)
4443

44+
go_proto_library(
45+
name = "p4runtime_go_proto",
46+
importpath = "github.com/p4lang/p4runtime/go/p4/v1",
47+
protos = [
48+
":p4data_proto",
49+
":p4runtime_proto",
50+
],
51+
deps = [
52+
"//p4/config/v1:p4info_go_proto",
53+
"@com_google_googleapis//google/rpc:status_go_proto",
54+
],
55+
)
56+
4557
build_test(
4658
name = "proto_build_test",
4759
targets = [
@@ -50,5 +62,6 @@ build_test(
5062
":p4data_cc_proto",
5163
":p4runtime_cc_proto",
5264
":p4runtime_cc_grpc",
65+
":p4runtime_go_proto",
5366
],
5467
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,25 @@ def p4runtime_deps():
4141
],
4242
sha256 = "26d4021f6898e23b82ef953078389dd49ac2b5618ac564ade4ef87cced147b38",
4343
)
44+
if not native.existing_rule("io_bazel_rules_go"):
45+
http_archive(
46+
name = "io_bazel_rules_go",
47+
sha256 = "f4a9314518ca6acfa16cc4ab43b0b8ce1e4ea64b81c38d8a3772883f153346b8",
48+
urls = [
49+
"https://github.com/bazelbuild/rules_go/releases/download/v0.50.1/rules_go-v0.50.1.zip",
50+
],
51+
)
52+
if not native.existing_rule("rules_proto"):
53+
http_archive(
54+
name = "rules_proto",
55+
sha256 = "6fb6767d1bef535310547e03247f7518b03487740c11b6c6adb7952033fe1295",
56+
strip_prefix = "rules_proto-6.0.2",
57+
url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.2/rules_proto-6.0.2.tar.gz",
58+
)
59+
if not native.existing_rule("bazel_features"):
60+
http_archive(
61+
name = "bazel_features",
62+
sha256 = "0f23d75c7623d6dba1fd30513a94860447de87c8824570521fcc966eda3151c2",
63+
strip_prefix = "bazel_features-1.4.1",
64+
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.4.1/bazel_features-v1.4.1.tar.gz",
65+
)

0 commit comments

Comments
 (0)