Skip to content

Commit d4a0a6c

Browse files
authored
Update build to support Bazel 8/bzlmod (#192)
* Update GNMI to support Bazel 8 * Mark gazelle overrides as dev dependencies * Fix comment position * Set version number in MODULE.bazel. * Update GitHub actions to trigger properly and add go/linter actions. * Add bazel test and remove go/staticcheck analysis for now. * Keep bazel build cache. * Fix syntax error with bazel cache
1 parent d34ac37 commit d4a0a6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+4471
-4469
lines changed

.bazelversion

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

.github/workflows/ci-cpp-build-gnmi.yml

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ name: "bazel build"
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [ master ]
66
pull_request:
7-
branches: [ main ]
87
schedule:
98
- cron: "0 0 * * *"
109

@@ -14,24 +13,19 @@ jobs:
1413
env:
1514
BAZEL: bazelisk-linux-amd64
1615
steps:
17-
- uses: actions/checkout@v2
18-
with:
19-
submodules: recursive
20-
- name: Mount bazel cache
21-
uses: actions/cache@v2
22-
with:
23-
# See https://docs.bazel.build/versions/master/output_directories.html
24-
path: "~/.cache/bazel"
25-
# Create a new cache entry whenever Bazel files change.
26-
# See https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
27-
key: bazel-${{ runner.os }}-build-${{ hashFiles('**/*.bzl', '**/*.bazel') }}
28-
restore-keys: |
29-
bazel-${{ runner.os }}-build-
30-
- name: Install bazelisk
31-
run: |
32-
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.8.1/$BAZEL"
33-
chmod +x $BAZEL
34-
sudo mv $BAZEL /usr/local/bin/bazel
35-
- name: Build
36-
run: bazel build //...
37-
16+
- uses: actions/checkout@v4
17+
with:
18+
submodules: recursive
19+
- name: Mount bazel cache
20+
uses: actions/cache@v2
21+
with:
22+
path: "~/.cache/bazel"
23+
key: bazel-${{ runner.os }}-build-${{ hashFiles('**/*.bzl', '**/*.bazel') }}
24+
restore-keys: |
25+
bazel-${{ runner.os }}-build-
26+
- name: Setup Bazel
27+
uses: bazelbuild/setup-bazelisk@v3
28+
- name: Build
29+
run: bazel build //...
30+
- name: Test
31+
run: bazel test //...

.gitignore

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

BUILD.bazel

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,31 @@
1414
#
1515
# Supporting infrastructure for implementing and testing PINS.
1616

17+
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_test")
18+
1719
package(
1820
default_visibility = ["//visibility:public"],
1921
licenses = ["notice"],
2022
)
2123

2224
exports_files(["LICENSE"])
25+
26+
# gazelle:go_grpc_compilers @io_bazel_rules_go//proto:go_grpc_v2, @io_bazel_rules_go//proto:go_proto
27+
# gazelle:proto_import_prefix github.com/openconfig/gnmi
28+
# gazelle:prefix github.com/openconfig/gnmi
29+
gazelle(name = "gazelle")
30+
31+
gazelle(
32+
name = "gazelle_update_repos",
33+
args = [
34+
"-from_file=go.mod",
35+
"-to_macro=gnmi_go_deps.bzl%gnmi_go_deps",
36+
"-prune",
37+
],
38+
command = "update-repos",
39+
)
40+
41+
gazelle_test(
42+
name = "gazelle_test",
43+
workspace = "//:BUILD.bazel",
44+
)

MODULE.bazel

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module(
2+
name = "openconfig_gnmi",
3+
version = "0.13.0",
4+
)
5+
6+
bazel_dep(name = "gazelle", version = "0.41.0", repo_name = "bazel_gazelle")
7+
bazel_dep(name = "grpc", version = "1.69.0", repo_name = "com_github_grpc_grpc")
8+
bazel_dep(name = "protobuf", version = "29.3", repo_name = "com_google_protobuf")
9+
bazel_dep(name = "rules_go", version = "0.51.0", repo_name = "io_bazel_rules_go")
10+
11+
go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
12+
go_sdk.download(version = "1.23.4")
13+
14+
go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
15+
go_deps.from_file(go_mod = "//:go.mod")
16+
use_repo(go_deps, "com_github_cenkalti_backoff_v4", "com_github_golang_glog", "com_github_google_go_cmp", "com_github_kylelemons_godebug", "com_github_openconfig_grpctunnel", "com_github_openconfig_ygot", "com_github_protocolbuffers_txtpbfmt", "org_bitbucket_creachadair_stringset", "org_golang_google_grpc", "org_golang_google_grpc_cmd_protoc_gen_go_grpc", "org_golang_google_protobuf", "org_golang_x_crypto", "org_golang_x_net")
17+
18+
go_deps_dev = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps", dev_dependency = True)
19+
go_deps_dev.gazelle_override(
20+
directives = [
21+
"gazelle:proto disable", # keep
22+
"gazelle:resolve go github.com/openconfig/gnmi/errlist @openconfig_gnmi//errlist:errlist", # keep
23+
],
24+
path = "github.com/openconfig/grpctunnel",
25+
)
26+
go_deps_dev.gazelle_override(
27+
directives = [
28+
"gazelle:resolve go github.com/openconfig/gnmi/proto/gnmi @openconfig_gnmi//proto/gnmi:gnmi", # keep
29+
"gazelle:resolve go github.com/openconfig/gnmi/errlist @openconfig_gnmi//errlist:errlist", # keep
30+
"gazelle:resolve go github.com/openconfig/gnmi/value @openconfig_gnmi//value:value", # keep
31+
],
32+
path = "github.com/openconfig/ygot",
33+
)
34+
35+
inject_repo(go_deps, "openconfig_gnmi")

MODULE.bazel.lock

Lines changed: 724 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WORKSPACE

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
workspace(name = "gnmi")
16+
17+
load("//:gnmi_deps.bzl", "gnmi_deps")
18+
19+
gnmi_deps()
20+
21+
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
22+
23+
switched_rules_by_language(
24+
name = "com_google_googleapis_imports",
25+
cc = True,
26+
go = True,
27+
grpc = True,
28+
)
29+
30+
load("@bazel_features//:deps.bzl", "bazel_features_deps")
31+
32+
bazel_features_deps()
33+
34+
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
35+
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
36+
load("//:gnmi_go_deps.bzl", "gnmi_go_deps")
37+
38+
# gazelle:repository_macro gnmi_go_deps.bzl%gnmi_go_deps
39+
gnmi_go_deps()
40+
41+
go_rules_dependencies()
42+
43+
go_register_toolchains(version = "1.23.4")
44+
45+
gazelle_dependencies()
46+
47+
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
48+
49+
protobuf_deps()
50+
51+
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
52+
53+
grpc_deps()
54+
55+
# Required by grpc
56+
load("@build_bazel_apple_support//lib:repositories.bzl", "apple_support_dependencies")
57+
load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies")
58+
load("@rules_python//python:repositories.bzl", "py_repositories")
59+
60+
py_repositories()
61+
62+
apple_rules_dependencies(ignore_version_differences = False)
63+
64+
apple_support_dependencies()

WORKSPACE.bazel

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

WORKSPACE.bzlmod

Whitespace-only changes.

bazel/BUILD.bazel

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
package(
16+
default_visibility = ["//visibility:public"],
17+
licenses = ["notice"],
18+
)

0 commit comments

Comments
 (0)