Skip to content

Commit c719c96

Browse files
committed
Fix workspace and replace compile_protos with regenerate-files
1 parent 9646a98 commit c719c96

File tree

9 files changed

+865
-52
lines changed

9 files changed

+865
-52
lines changed

.bazelversion

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

WORKSPACE.bazel renamed to WORKSPACE

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,22 @@ workspace(name = "com_github_openconfig_gnpsi")
1616

1717
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
1818

19-
# -- Load Dependencies ---------------------------------------------------------
20-
load("gnpsi_deps.bzl", "gnpsi_deps")
19+
### Bazel rules for many languages to compile PROTO into gRPC libraries
20+
# Note: any version of this which is less than 4.3.0 requires bazel version 5.4.0 (set in .bazelversion file)
21+
http_archive(
22+
name = "rules_proto_grpc",
23+
sha256 = "c0d718f4d892c524025504e67a5bfe83360b3a982e654bc71fed7514eb8ac8ad",
24+
strip_prefix = "rules_proto_grpc-4.6.0",
25+
urls = ["https://github.com/rules-proto-grpc/rules_proto_grpc/archive/4.6.0.tar.gz"],
26+
)
2127

22-
gnpsi_deps()
28+
# googleapis has not had a release since 2016 - take the master version as of 4-jan-23
29+
http_archive(
30+
name = "com_google_googleapis",
31+
sha256 = "9fc03150d86501d7da35eefa989d5553bdd77a95cfe4373cdafe8eee92f6bfb1",
32+
strip_prefix = "googleapis-870a5ed7e141b4faf70e2a0858854e9b5bb18612",
33+
urls = ["https://github.com/googleapis/googleapis/archive/870a5ed7e141b4faf70e2a0858854e9b5bb18612.tar.gz"],
34+
)
2335

2436
# -- Load GRPC Dependencies ----------------------------------------------------
2537
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
@@ -31,37 +43,50 @@ switched_rules_by_language(
3143
go = True,
3244
)
3345

34-
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
46+
load(
47+
"@rules_proto_grpc//:repositories.bzl",
48+
"bazel_gazelle",
49+
"io_bazel_rules_go",
50+
"rules_proto_grpc_repos",
51+
"rules_proto_grpc_toolchains",
52+
)
3553

36-
grpc_deps()
54+
rules_proto_grpc_toolchains()
55+
rules_proto_grpc_repos()
3756

38-
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
57+
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
3958

40-
grpc_extra_deps()
59+
rules_proto_dependencies()
60+
rules_proto_toolchains()
4161

42-
# -- Load Protobuf -------------------------------------------------------------
62+
### Golang
63+
io_bazel_rules_go()
64+
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
65+
go_rules_dependencies()
66+
go_register_toolchains(go_version = "1.20")
4367

44-
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
68+
# gazelle:repo bazel_gazelle
69+
bazel_gazelle()
4570

46-
protobuf_deps()
71+
# -- Load Dependencies ---------------------------------------------------------
72+
load("gnpsi_deps.bzl", "gnpsi_deps")
4773

48-
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
74+
gnpsi_deps()
4975

50-
rules_proto_dependencies()
76+
load("@rules_proto_grpc//go:repositories.bzl", rules_proto_grpc_go_repos = "go_repos")
5177

52-
rules_proto_toolchains()
78+
rules_proto_grpc_go_repos()
5379

80+
### C++
81+
load("@rules_proto_grpc//cpp:repositories.bzl", rules_proto_grpc_cpp_repos = "cpp_repos")
5482

83+
rules_proto_grpc_cpp_repos()
5584

56-
### Bazel rules for many languages to compile PROTO into gRPC libraries
57-
http_archive(
58-
name = "rules_proto_grpc",
59-
sha256 = "bbe4db93499f5c9414926e46f9e35016999a4e9f6e3522482d3760dc61011070",
60-
strip_prefix = "rules_proto_grpc-4.2.0",
61-
urls = ["https://github.com/rules-proto-grpc/rules_proto_grpc/archive/4.2.0.tar.gz"],
62-
)
85+
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
6386

64-
load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_repos", "rules_proto_grpc_toolchains")
87+
grpc_deps()
6588

66-
rules_proto_grpc_toolchains()
67-
rules_proto_grpc_repos()
89+
# Load gazelle_dependencies last, so that the newer version of org_golang_google_grpc is used.
90+
# see https://github.com/rules-proto-grpc/rules_proto_grpc/issues/160
91+
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
92+
gazelle_dependencies()

common.bzl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
load("@io_bazel_rules_go//proto:compiler.bzl", "go_proto_compiler")
2+
load("@io_bazel_rules_go//proto/wkt:well_known_types.bzl", "PROTO_RUNTIME_DEPS", "WELL_KNOWN_TYPES_APIV2")
3+
4+
def use_new_compilers():
5+
go_proto_compiler(
6+
name = "go_protoc_gen_go",
7+
options = [
8+
"paths=source_relative",
9+
],
10+
plugin = "@org_golang_google_protobuf//cmd/protoc-gen-go",
11+
suffix = ".pb.go",
12+
visibility = ["//visibility:public"],
13+
deps = PROTO_RUNTIME_DEPS + WELL_KNOWN_TYPES_APIV2,
14+
)
15+
go_proto_compiler(
16+
name = "go_protoc_gen_go_grpc",
17+
options = [
18+
"paths=source_relative",
19+
],
20+
plugin = "@org_golang_google_grpc_cmd_protoc_gen_go_grpc//:protoc-gen-go-grpc",
21+
suffix = "_grpc.pb.go",
22+
visibility = ["//visibility:public"],
23+
deps = PROTO_RUNTIME_DEPS + [
24+
"@org_golang_google_grpc//:go_default_library",
25+
"@org_golang_google_grpc//codes:go_default_library",
26+
"@org_golang_google_grpc//status:go_default_library",
27+
],
28+
)
29+

compile_protos.sh

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

proto/gnpsi/BUILD.bazel

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
#
15-
1615
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
17-
16+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
17+
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
18+
load("@rules_proto//proto:defs.bzl", "proto_library")
19+
load("//:common.bzl", "use_new_compilers")
1820
# gnpsi defines a gRPC-based network packet sampling interface implemented on
1921
# vendor network elements. It provides mechanisms for streaming packet
2022
# samples/updates from the network element.
@@ -23,6 +25,8 @@ package(
2325
licenses = ["notice"],
2426
)
2527

28+
use_new_compilers()
29+
2630
proto_library(
2731
name = "gnpsi_proto",
2832
srcs = ["gnpsi.proto"],
@@ -44,3 +48,19 @@ cc_grpc_library(
4448
grpc_only = ["True"],
4549
deps = [":gnpsi_cc_proto"],
4650
)
51+
52+
go_proto_library(
53+
name = "gnpsi_go_proto",
54+
compilers = [
55+
"go_protoc_gen_go",
56+
"go_protoc_gen_go_grpc",
57+
],
58+
importpath = "github.com/openconfig/gnpsi/proto/gnpsi",
59+
proto = ":gnpsi_proto",
60+
)
61+
62+
go_library(
63+
name = "gnpsi",
64+
embed = [":gnpsi_go_proto"],
65+
importpath = "github.com/openconfig/gnpsi/proto/gnpsi",
66+
)

0 commit comments

Comments
 (0)