Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build to support Bazel 8/bzlmod #220

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .bazelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.4.0
8.0.0
16 changes: 15 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_test")

# gazelle:go_grpc_compilers @io_bazel_rules_go//proto:go_grpc_v2, @io_bazel_rules_go//proto:go_proto
# gazelle:proto_import_prefix github.com/openconfig/gnsi
# gazelle:prefix github.com/openconfig/gnsi
# gazelle:resolve proto go github.com/openconfig/gnmi/proto/gnmi/gnmi.proto @openconfig_gnmi//proto/gnmi:gnmi_go_proto
# gazelle:resolve proto github.com/openconfig/gnmi/proto/gnmi/gnmi.proto @openconfig_gnmi//proto/gnmi:gnmi_proto
gazelle(name = "gazelle")

gazelle(
name = "gazelle_update_repos",
args = [
"-from_file=go.mod",
"-to_macro=gnsi_go_deps.bzl%gnsi_go_deps",
"-prune",
],
command = "update-repos",
)

alias(
name = "authz_go",
actual = "//authz:authz",
Expand Down
17 changes: 17 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module(
name = "openconfig_gnsi",
version = "0.0.0",
)

bazel_dep(name = "gazelle", version = "0.41.0", repo_name = "bazel_gazelle")
bazel_dep(name = "grpc", version = "1.69.0", repo_name = "com_github_grpc_grpc")
bazel_dep(name = "protobuf", version = "29.3", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_go", version = "0.51.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "openconfig_gnmi", version = "0.13.0")

go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.4")

go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(go_deps, "org_golang_google_grpc", "org_golang_google_grpc_cmd_protoc_gen_go_grpc", "org_golang_google_protobuf")
726 changes: 726 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

98 changes: 23 additions & 75 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,102 +1,50 @@
workspace(name = "com_github_openconfig_gnsi")

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

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

# googleapis has not had a release since 2016 - take the master version as of 4-jan-23
http_archive(
name = "com_google_googleapis",
sha256 = "9fc03150d86501d7da35eefa989d5553bdd77a95cfe4373cdafe8eee92f6bfb1",
strip_prefix = "googleapis-870a5ed7e141b4faf70e2a0858854e9b5bb18612",
urls = ["https://github.com/googleapis/googleapis/archive/870a5ed7e141b4faf70e2a0858854e9b5bb18612.tar.gz"],
)
gnsi_deps()

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

switched_rules_by_language(
name = "com_google_googleapis_imports",
cc = True,
go = True,
grpc = True,
)

load(
"@rules_proto_grpc//:repositories.bzl",
"bazel_gazelle",
"io_bazel_rules_go",
"rules_proto_grpc_repos",
"rules_proto_grpc_toolchains",
)

rules_proto_grpc_toolchains()

rules_proto_grpc_repos()

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

rules_proto_dependencies()

rules_proto_toolchains()

### Golang
io_bazel_rules_go()

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()
load("@bazel_features//:deps.bzl", "bazel_features_deps")

go_register_toolchains(go_version = "1.20")

# gazelle:repo bazel_gazelle
bazel_gazelle()
bazel_features_deps()

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("//:gnsi_go_deps.bzl", "gnsi_go_deps")

load("//:deps.bzl", "gnsi_deps")

gnsi_deps()
# gazelle:repository_macro gnsi_go_deps.bzl%gnsi_go_deps
gnsi_go_deps()

load("@rules_proto_grpc//go:repositories.bzl", rules_proto_grpc_go_repos = "go_repos")
go_rules_dependencies()

rules_proto_grpc_go_repos()
go_register_toolchains(version = "1.23.4")

# Load gazelle_dependencies last, so that the newer version of org_golang_google_grpc is used.
# see https://github.com/rules-proto-grpc/rules_proto_grpc/issues/160
gazelle_dependencies()

### C++
load("@rules_proto_grpc//cpp:repositories.bzl", rules_proto_grpc_cpp_repos = "cpp_repos")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

rules_proto_grpc_cpp_repos()
protobuf_deps()

load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")

grpc_deps()

# open-config YANG files
http_archive(
name = "github_openconfig_yang",
build_file_content = """exports_files(glob(["release/models/**/*.yang"]), visibility = ["//visibility:public"])""",
sha256 = "f6b2b6c0ffe0b66881287bcd43241a57583f353cc5cc41cba973601c32232f45",
strip_prefix = "public-bf737a5567ec248456cb528efcd63cab15e8fc69",
urls = [
"https://github.com/openconfig/public/archive/bf737a5567ec248456cb528efcd63cab15e8fc69.zip",
],
)
# Required by grpc
load("@build_bazel_apple_support//lib:repositories.bzl", "apple_support_dependencies")
load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies")
load("@rules_python//python:repositories.bzl", "py_repositories")

# YANG files from other standard bodies.
http_archive(
name = "github_yang",
build_file_content = """exports_files(glob(["standard/**/*.yang"]), visibility = ["//visibility:public"])""",
sha256 = "55913058f64a1ec7fe9e6e70d7128f08e66b20c859803b1fb02dbaf7eef2c64d",
strip_prefix = "yang-2fa291d6bdb4b281d4e1b3dfa3254ffa7257d800",
urls = [
"https://github.com/YangModels/yang/archive/2fa291d6bdb4b281d4e1b3dfa3254ffa7257d800.zip",
],
)
py_repositories()

apple_rules_dependencies(ignore_version_differences = False)

apple_support_dependencies()
Empty file added WORKSPACE.bzlmod
Empty file.
25 changes: 14 additions & 11 deletions acctz/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_proto_grpc//cpp:defs.bzl", "cpp_grpc_library")
load("//:common.bzl", "use_new_compilers")

package(default_visibility = ["//visibility:public"])

use_new_compilers()

proto_library(
name = "acctz_proto",
srcs = ["acctz.proto"],
Expand All @@ -21,11 +19,16 @@ proto_library(
##############################################################################
# C++
##############################################################################
cpp_grpc_library(
cc_proto_library(
name = "acctz_cc_proto",
protos = [
":acctz_proto",
],
deps = [":acctz_proto"],
)

cc_grpc_library(
name = "acctz_cc_grpc_proto",
srcs = [":acctz_proto"],
grpc_only = True,
deps = [":acctz_cc_proto"],
)

##############################################################################
Expand All @@ -34,8 +37,8 @@ cpp_grpc_library(
go_proto_library(
name = "acctz_go_proto",
compilers = [
"go_protoc_gen_go",
"go_protoc_gen_go_grpc",
"@io_bazel_rules_go//proto:go_grpc_v2",
"@io_bazel_rules_go//proto:go_proto",
],
importpath = "github.com/openconfig/gnsi/acctz",
proto = ":acctz_proto",
Expand Down
Loading