Skip to content
Open
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
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ build:ci --announce_rc
# C++17 standard required for newer protobuf and grpc versions
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17

# Enable source_code_info in proto descriptors for buf linting
build --protocopt=--include_source_info
31 changes: 31 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@rules_buf//buf:defs.bzl", "buf_format", "buf_lint_test")

# Buf configuration files
exports_files([
"buf.yaml",
"buf.lock",
])

# Buf lint test for the entire repository
buf_lint_test(
name = "buf_lint_test",
config = ":buf.yaml",
targets = [
"//udpa/annotations:pkg",
"//udpa/data/orca/v1:pkg",
"//udpa/service/orca/v1:pkg",
"//udpa/type/v1:pkg",
"//xds/annotations/v3:pkg",
"//xds/core/v3:pkg",
"//xds/data/orca/v3:pkg",
"//xds/service/orca/v3:pkg",
"//xds/type/v3:pkg",
"//xds/type/matcher/v3:pkg",
],
)

# Buf format rule - run with: bazel run //:buf_format
# This formats all proto files in the workspace
buf_format(
name = "buf_format",
)
24 changes: 24 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,27 @@ Run the following command to update the generated files and commit them with you
bazel build //...
tools/generate_go_protobuf.py
```

## Buf tools

### Format proto files

To format all proto files in the workspace:

```sh
bazel run //:buf_format
```

To check if proto files are formatted correctly (used in CI):

```sh
bazel run //:buf_format -- -d
```

### Linting

Buf linting is automatically run as part of the test suite:

```sh
bazel test //...
```
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bazel_dep(name = "grpc", version = "1.68.0", repo_name = "com_github_grpc_grpc")
bazel_dep(name = "protobuf", version = "29.3", repo_name = "com_google_protobuf")
bazel_dep(name = "protoc-gen-validate", version = "1.2.1.bcr.1", repo_name = "com_envoyproxy_protoc_gen_validate")
bazel_dep(name = "re2", version = "2024-07-02", repo_name = "com_googlesource_code_re2")
bazel_dep(name = "rules_buf", version = "0.5.2")
bazel_dep(name = "rules_cc", version = "0.0.17")
bazel_dep(name = "rules_go", version = "0.53.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_python", version = "1.6.3")
Expand Down
17 changes: 17 additions & 0 deletions bazel/api_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("@com_github_grpc_grpc//bazel:python_rules.bzl", _py_proto_library = "py_pr
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_grpc_library", "go_proto_library")
load("@rules_buf//buf:defs.bzl", "buf_lint_test")
load("@rules_cc//cc:cc_test.bzl", "cc_test")
load(
"//bazel:external_proto_deps.bzl",
Expand Down Expand Up @@ -101,6 +102,15 @@ def xds_proto_package(
deps = [],
has_services = False,
visibility = ["//visibility:public"]):
"""Builds proto targets and creates tests for linting.

Args:
name: Name of the proto package (default: "pkg")
srcs: List of proto source files
deps: Dependencies on other proto_library targets
has_services: Whether this package contains gRPC services
visibility: Target visibility
"""
if srcs == []:
srcs = native.glob(["*.proto"])

Expand Down Expand Up @@ -136,6 +146,13 @@ def xds_proto_package(
]).to_list(),
)

# Add buf linting test for proto files
buf_lint_test(
name = name + "_buf_lint_test",
config = "//:buf.yaml",
targets = [":" + name],
)

def xds_cc_test(name, **kwargs):
cc_test(
name = name,
Expand Down
5 changes: 5 additions & 0 deletions bazel/dependency_imports.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@com_envoyproxy_protoc_gen_validate//bazel:repositories.bzl", "pgv_depende
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@rules_buf//buf:repositories.bzl", "rules_buf_dependencies", "rules_buf_toolchains")
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")

# go version for rules_go
Expand All @@ -18,6 +19,10 @@ def xds_dependency_imports(go_version = GO_VERSION):
gazelle_dependencies(go_sdk = "go_sdk")
pgv_dependencies()

# Initialize rules_buf for WORKSPACE mode
rules_buf_dependencies()
rules_buf_toolchains(version = "v1.47.2")

# Initialize rules_python for WORKSPACE mode
py_repositories()
python_register_toolchains(
Expand Down
4 changes: 4 additions & 0 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def xds_api_dependencies():
"rules_cc",
locations = REPOSITORY_LOCATIONS,
)
xds_http_archive(
"rules_buf",
locations = REPOSITORY_LOCATIONS,
)

# Old name for backward compatibility.
# TODO(roth): Remove once all callers are updated to use the new name.
Expand Down
5 changes: 5 additions & 0 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ REPOSITORY_LOCATIONS = dict(
strip_prefix = "rules_python-1.6.3",
urls = ["https://github.com/bazelbuild/rules_python/archive/1.6.3.tar.gz"],
),
rules_buf = dict(
sha256 = "19d845cedf32c0e74a01af8d0bd904872bddc7905f087318d00b332aa36d3929",
strip_prefix = "rules_buf-0.5.2",
urls = ["https://github.com/bufbuild/rules_buf/archive/refs/tags/v0.5.2.tar.gz"],
),
)
12 changes: 12 additions & 0 deletions buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generated by buf. DO NOT EDIT.
version: v2
deps:
- name: buf.build/envoyproxy/protoc-gen-validate
commit: daf171c6cdb54629b5f51e345a79e4dd
digest: b5:c745e1521879f43740230b1df673d0729f55704efefdcfc489d4a0a2d40c92a26cacfeab62813403040a8b180142d53b398c7ca784a065e43823605ee49681de
- name: buf.build/google/cel-spec
commit: 96eff7bcf453468dbd44b80598bfe1bf
digest: b5:660c244ec1e8a0f26c5431e1901f1d52d322c7ee3fd240cb6832f44d0694384a36ded008af457a9e5268c73adfa00170e972ac4fe44752a693424b3479f30b82
- name: buf.build/googleapis/googleapis
commit: 004180b77378443887d3b55cabc00384
digest: b5:e8f475fe3330f31f5fd86ac689093bcd274e19611a09db91f41d637cb9197881ce89882b94d13a58738e53c91c6e4bae7dc1feba85f590164c975a89e25115dc
46 changes: 46 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: v2
modules:
- path: .
excludes:
- bazel-bin
- bazel-out
- bazel-testlogs
- bazel-xds
deps:
- buf.build/envoyproxy/protoc-gen-validate
- buf.build/googleapis/googleapis
- buf.build/google/cel-spec
lint:
use:
- STANDARD
ignore_only:
# ENUM_VALUE_PREFIX: Legacy enums with established names that cannot be changed for compatibility
ENUM_VALUE_PREFIX:
- udpa/annotations/status.proto # PackageVersionStatus enum
- xds/annotations/v3/status.proto # PackageVersionStatus enum
- xds/core/v3/resource_locator.proto # Scheme enum
# ENUM_ZERO_VALUE_SUFFIX: Legacy enum zero values that predate _UNSPECIFIED convention
ENUM_ZERO_VALUE_SUFFIX:
- udpa/annotations/status.proto # PackageVersionStatus.UNKNOWN
- xds/annotations/v3/status.proto # PackageVersionStatus.UNKNOWN
- xds/core/v3/resource_locator.proto # Scheme.XDSTP
# PACKAGE_VERSION_SUFFIX: udpa.annotations package is legacy and predates versioning requirements
PACKAGE_VERSION_SUFFIX:
- udpa/annotations/migrate.proto
- udpa/annotations/security.proto
- udpa/annotations/sensitive.proto
- udpa/annotations/status.proto
- udpa/annotations/versioning.proto
# RPC naming: ORCA service uses established naming convention that predates buf standards
RPC_REQUEST_RESPONSE_UNIQUE:
- udpa/service/orca/v1/orca.proto # StreamCoreMetrics RPC
- xds/service/orca/v3/orca.proto # StreamCoreMetrics RPC
RPC_REQUEST_STANDARD_NAME:
- udpa/service/orca/v1/orca.proto # StreamCoreMetrics RPC
- xds/service/orca/v3/orca.proto # StreamCoreMetrics RPC
RPC_RESPONSE_STANDARD_NAME:
- udpa/service/orca/v1/orca.proto # StreamCoreMetrics RPC
- xds/service/orca/v3/orca.proto # StreamCoreMetrics RPC
breaking:
use:
- FILE
1 change: 1 addition & 0 deletions ci/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
path: $(Agent.TempDirectory)/tmp

- bash: ci/check.sh
displayName: 'Run Bazel tests (includes buf linting)'
env:
TEST_TMPDIR: $(Agent.TempDirectory)/tmp

Expand Down
10 changes: 10 additions & 0 deletions ci/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

set -e

# Check buf format - this runs buf format in diff mode to verify formatting
echo "Checking proto file formatting with buf..."
bazel run //:buf_format -- -d || {
echo "ERROR: Proto files are not properly formatted."
echo "Run 'bazel run //:buf_format' to fix formatting issues."
exit 1
}
echo "Proto formatting check passed."

# Run all tests including buf_lint_test via Bazel
bazel test --config=ci //...

rm -rf go/xds go/udpa
Expand Down
25 changes: 18 additions & 7 deletions go/udpa/annotations/migrate.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 17 additions & 6 deletions go/udpa/annotations/security.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions go/udpa/annotations/sensitive.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 17 additions & 6 deletions go/udpa/annotations/status.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading