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 #147

Draft
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.0.0
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@
#
.vscode/
bazel-*

# Ignore Go binary files but keep the .go files.
**/*
!**/*.go
!**/
21 changes: 21 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,26 @@

load("@bazel_gazelle//:def.bzl", "gazelle")

# 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/bootz
# gazelle:prefix github.com/openconfig/bootz
# gazelle:resolve go github.com/openconfig/bootz/proto/bootz //proto:bootz
# gazelle:resolve proto go github.com/openconfig/gnsi/authz/authz.proto @openconfig_gnsi//authz:authz_go_proto
# gazelle:resolve proto github.com/openconfig/gnsi/authz/authz.proto @openconfig_gnsi//authz:authz_proto
# gazelle:resolve proto go github.com/openconfig/gnsi/certz/certz.proto @openconfig_gnsi//certz:certz_go_proto
# gazelle:resolve proto github.com/openconfig/gnsi/certz/certz.proto @openconfig_gnsi//certz:certz_proto
# gazelle:resolve proto go github.com/openconfig/gnsi/credentialz/credentialz.proto @openconfig_gnsi//credentialz:credentialz_go_proto
# gazelle:resolve proto github.com/openconfig/gnsi/credentialz/credentialz.proto @openconfig_gnsi//credentialz:credentialz_proto
# gazelle:resolve proto go github.com/openconfig/gnsi/pathz/pathz.proto @openconfig_gnsi//pathz:pathz_go_proto
# gazelle:resolve proto github.com/openconfig/gnsi/pathz/pathz.proto @openconfig_gnsi//pathz:pathz_proto
gazelle(name = "gazelle")

gazelle(
name = "gazelle_update_repos",
args = [
"-from_file=go.mod",
"-to_macro=bootz_go_deps.bzl%bootz_go_deps",
"-prune",
],
command = "update-repos",
)
35 changes: 35 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module(
name = "openconfig_bootz",
)

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.0.0")
bazel_dep(name = "openconfig_gnsi", version = "0.0.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, "com_github_coredhcp_coredhcp", "com_github_golang_glog", "com_github_google_go_cmp", "com_github_h_fam_errdiff", "com_github_insomniacslk_dhcp", "org_golang_google_grpc", "org_golang_google_grpc_cmd_protoc_gen_go_grpc", "org_golang_google_protobuf", "org_mozilla_go_pkcs7")

go_deps_dev = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps", dev_dependency = True)
go_deps_dev.gazelle_override(
build_file_generation = "clean",
path = "github.com/h-fam/errdiff",
)

git_override(
module_name = "openconfig_gnmi",
commit = "66ccc5027ea9b69376978a6eeb079ba5907249b7",
remote = "https://github.com/bstoll/gnmi",
)

git_override(
module_name = "openconfig_gnsi",
commit = "57ecb02511c1541195a212b571ddde05bc635a0a",
remote = "https://github.com/bstoll/gnsi",
)
299 changes: 299 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

78 changes: 23 additions & 55 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,83 +13,51 @@
# limitations under the License.
workspace(name = "com_github_openconfig_bootz")

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 = "fb7fc7a3c19a92b2f15ed7c4ffb2983e956625c1436f57a3430b897ba9864059",
strip_prefix = "rules_proto_grpc-4.3.0",
urls = ["https://github.com/rules-proto-grpc/rules_proto_grpc/archive/4.3.0.tar.gz"],
)
load("//:bootz_deps.bzl", "bootz_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"],
)
bootz_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("@bazel_features//:deps.bzl", "bazel_features_deps")

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

rules_proto_dependencies()

rules_proto_toolchains()

### Golang
io_bazel_rules_go()
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("//:bootz_go_deps.bzl", "bootz_go_deps")

go_rules_dependencies()
# gazelle:repository_macro bootz_go_deps.bzl%bootz_go_deps
bootz_go_deps()

go_register_toolchains(go_version = "1.19")
go_rules_dependencies()

# gazelle:repo bazel_gazelle
bazel_gazelle()
go_register_toolchains(version = "1.23.4")

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
gazelle_dependencies()

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

local_repository(
name = "local_repo_root",
path = "./",
)
protobuf_deps()

load("@rules_proto_grpc//go:repositories.bzl", rules_proto_grpc_go_repos = "go_repos")
load("//:deps.bzl", "go_dependencies")
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")

# gazelle:repository_macro deps.bzl%go_dependencies
go_dependencies()
grpc_deps()

rules_proto_grpc_go_repos()
# 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")

# 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()
py_repositories()

load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
apple_rules_dependencies(ignore_version_differences = False)

grpc_deps()
apple_support_dependencies()
Empty file added WORKSPACE.bzlmod
Empty file.
18 changes: 18 additions & 0 deletions bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package(
default_visibility = ["//visibility:public"],
licenses = ["notice"],
)
24 changes: 24 additions & 0 deletions bazel/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build tools

// Package bazel contains imports to keep go.mod entries for packages that are
// referenced in BUILD files, but not in Go code.
package bazel

import (
_ "google.golang.org/grpc/cmd/protoc-gen-go-grpc" // protoc-gen-go-grpc
_ "google.golang.org/protobuf/cmd/protoc-gen-go" // protoc-gen-go
)
98 changes: 98 additions & 0 deletions bootz_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Dependencies to build bootz."""

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

def bootz_deps():
"""Declare the third-party dependencies necessary to build bootz"""
if not native.existing_rule("bazel_features"):
http_archive(
name = "bazel_features",
sha256 = "af3d4fb1cf4f25942cb4a933b1ad93a0ea9fe9ee70c2af7f369fb72a67c266e5",
strip_prefix = "bazel_features-1.21.0",
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.21.0/bazel_features-v1.21.0.tar.gz",
)
if not native.existing_rule("bazel_gazelle"):
http_archive(
name = "bazel_gazelle",
sha256 = "aefbf2fc7c7616c9ed73aa3d51c77100724d5b3ce66cfa16406e8c13e87c8b52",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.41.0/bazel-gazelle-v0.41.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.41.0/bazel-gazelle-v0.41.0.tar.gz",
],
)
if not native.existing_rule("com_github_grpc_grpc"):
http_archive(
name = "com_github_grpc_grpc",
url = "https://github.com/grpc/grpc/archive/refs/tags/v1.69.0.tar.gz",
strip_prefix = "grpc-1.69.0",
sha256 = "cd256d91781911d46a57506978b3979bfee45d5086a1b6668a3ae19c5e77f8dc",
)
if not native.existing_rule("com_google_googleapis"):
http_archive(
name = "com_google_googleapis",
sha256 = "0513f0f40af63bd05dc789cacc334ab6cec27cc89db596557cb2dfe8919463e4",
strip_prefix = "googleapis-fe8ba054ad4f7eca946c2d14a63c3f07c0b586a0",
urls = ["https://github.com/googleapis/googleapis/archive/fe8ba054ad4f7eca946c2d14a63c3f07c0b586a0.tar.gz"],
)
if not native.existing_rule("com_google_protobuf"):
http_archive(
name = "com_google_protobuf",
url = "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v29.3.zip",
strip_prefix = "protobuf-29.3",
sha256 = "85803e01f347141e16a2f770213a496f808fff9f0138c7c0e0c9dfa708b0da92",
repo_mapping = {
"@proto_bazel_features": "@bazel_features",
},
)
if not native.existing_rule("bazel_skylib"):
http_archive(
name = "bazel_skylib",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
],
sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
)
if not native.existing_rule("io_bazel_rules_go"):
http_archive(
name = "io_bazel_rules_go",
sha256 = "0936c9bc3c4321ee372cb8f66dd972d368cb940ed01a9ba9fd7debcf0093f09b",
urls = [
"https://github.com/bazelbuild/rules_go/releases/download/v0.51.0/rules_go-v0.51.0.zip",
],
)
if not native.existing_rule("rules_proto"):
http_archive(
name = "rules_proto",
sha256 = "0e5c64a2599a6e26c6a03d6162242d231ecc0de219534c38cb4402171def21e8",
strip_prefix = "rules_proto-7.0.2",
url = "https://github.com/bazelbuild/rules_proto/releases/download/7.0.2/rules_proto-7.0.2.tar.gz",
)
if not native.existing_rule("openconfig_gnmi"):
http_archive(
name = "openconfig_gnmi",
sha256 = "5930b29b7f0b5aeec4502d5b2b1b82bb97c218b2752422cfe9a0462e39aa8370",
strip_prefix = "gnmi-66ccc5027ea9b69376978a6eeb079ba5907249b7",
url = "https://github.com/bstoll/gnmi/archive/66ccc5027ea9b69376978a6eeb079ba5907249b7.zip",
)
if not native.existing_rule("openconfig_gnsi"):
http_archive(
name = "openconfig_gnsi",
sha256 = "9752a0fdbbc98ef7cbeb40a89074ad035b127f8f939204427a407a3569e5157e",
strip_prefix = "gnsi-57ecb02511c1541195a212b571ddde05bc635a0a",
url = "https://github.com/bstoll/gnsi/archive/57ecb02511c1541195a212b571ddde05bc635a0a.zip",
)
Loading
Loading