From 0da087d0ac9831725e2e09522413f2c99f275288 Mon Sep 17 00:00:00 2001 From: zirain Date: Fri, 14 Feb 2025 22:20:28 +0800 Subject: [PATCH 1/5] fix format-api not working on macos with llvm19 Signed-off-by: zirain --- ci/do_ci.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 0881dcac23dd..2e3fe1aed254 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -322,7 +322,9 @@ case $CI_TARGET in ;; format-api|check_and_fix_proto_format) - setup_clang_toolchain + if [[ -z "$CLANG_TOOLCHAIN_SETUP" ]]; then + setup_clang_toolchain + fi echo "Check and fix proto format ..." "${ENVOY_SRCDIR}/ci/check_and_fix_format.sh" ;; From 96ceee730757c9f5f5fd245c331c231655a52f32 Mon Sep 17 00:00:00 2001 From: zirain Date: Wed, 19 Feb 2025 22:36:28 +0800 Subject: [PATCH 2/5] use rules_buf Signed-off-by: zirain --- WORKSPACE | 4 +++ api/bazel/repositories.bzl | 24 +++-------------- api/bazel/repository_locations.bzl | 26 +++++++++---------- .../api_proto_breaking_change_detector/BUILD | 6 ++--- .../detector_test.py | 2 +- tools/proto_format/proto_format.sh | 2 +- 6 files changed, 25 insertions(+), 39 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index e4460bfc5475..06d01eba7a20 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -8,6 +8,10 @@ load("//bazel:api_repositories.bzl", "envoy_api_dependencies") envoy_api_dependencies() +load("@rules_buf//buf:repositories.bzl", "rules_buf_toolchains") + +rules_buf_toolchains(version = "v1.50.0") + load("//bazel:repo.bzl", "envoy_repo") envoy_repo() diff --git a/api/bazel/repositories.bzl b/api/bazel/repositories.bzl index 0ec7f2faf7c8..8669544cdf26 100644 --- a/api/bazel/repositories.bzl +++ b/api/bazel/repositories.bzl @@ -27,15 +27,16 @@ def api_dependencies(): external_http_archive( name = "com_google_googleapis", ) - external_http_archive( name = "com_github_cncf_xds", ) - external_http_archive( name = "prometheus_metrics_model", build_file_content = PROMETHEUSMETRICS_BUILD_CONTENT, ) + external_http_archive( + name = "rules_buf", + ) external_http_archive( name = "rules_proto", ) @@ -47,14 +48,9 @@ def api_dependencies(): name = "opentelemetry_proto", build_file_content = OPENTELEMETRY_BUILD_CONTENT, ) - external_http_archive( - name = "com_github_bufbuild_buf", - build_file_content = BUF_BUILD_CONTENT, - ) external_http_archive( name = "dev_cel", ) - external_http_archive( name = "com_github_chrusty_protoc_gen_jsonschema", ) @@ -387,17 +383,3 @@ go_grpc_library( ], ) """ - -BUF_BUILD_CONTENT = """ -package( - default_visibility = ["//visibility:public"], -) - -filegroup( - name = "buf", - srcs = [ - "@com_github_bufbuild_buf//:bin/buf", - ], - tags = ["manual"], # buf is downloaded as a linux binary; tagged manual to prevent build for non-linux users -) -""" diff --git a/api/bazel/repository_locations.bzl b/api/bazel/repository_locations.bzl index 8e1bba046cbf..21bddaa62266 100644 --- a/api/bazel/repository_locations.bzl +++ b/api/bazel/repository_locations.bzl @@ -101,6 +101,19 @@ REPOSITORY_LOCATIONS_SPEC = dict( license = "Apache-2.0", license_url = "https://github.com/prometheus/client_model/blob/v{version}/LICENSE", ), + rules_buf = dict( + project_name = "Bazel rules for Buf", + project_desc = "Bazel rules for Buf", + project_url = "https://github.com/bufbuild/rules_buf", + version = "0.3.0", + sha256 = "89c6d6e6523802ee7f1210340a69fab4ee0b47554953a1ecbe359319fd3f93dc", + release_date = "2024-05-23", + strip_prefix = "rules_buf-{version}", + urls = ["https://github.com/bufbuild/rules_buf/archive/refs/tags/v{version}.tar.gz"], + use_category = ["api"], + license = "Apache-2.0", + license_url = "https://github.com/bufbuild/rules_buf/blob/{version}/LICENSE", + ), rules_proto = dict( project_name = "Protobuf Rules for Bazel", project_desc = "Protocol buffer rules for Bazel", @@ -127,19 +140,6 @@ REPOSITORY_LOCATIONS_SPEC = dict( license = "Apache-2.0", license_url = "https://github.com/open-telemetry/opentelemetry-proto/blob/v{version}/LICENSE", ), - com_github_bufbuild_buf = dict( - project_name = "buf", - project_desc = "A new way of working with Protocol Buffers.", # Used for breaking change detection in API protobufs - project_url = "https://buf.build", - version = "1.50.0", - sha256 = "80c1211dfc4844499c6ddad341bb21206579883fd33cea0a2c40c82befd70602", - strip_prefix = "buf", - urls = ["https://github.com/bufbuild/buf/releases/download/v{version}/buf-Linux-x86_64.tar.gz"], - release_date = "2025-01-17", - use_category = ["api"], - license = "Apache-2.0", - license_url = "https://github.com/bufbuild/buf/blob/v{version}/LICENSE", - ), com_github_chrusty_protoc_gen_jsonschema = dict( project_name = "protoc-gen-jsonschema", project_desc = "Protobuf to JSON-Schema compiler", diff --git a/tools/api_proto_breaking_change_detector/BUILD b/tools/api_proto_breaking_change_detector/BUILD index 6e67be896659..b95128b3d97a 100644 --- a/tools/api_proto_breaking_change_detector/BUILD +++ b/tools/api_proto_breaking_change_detector/BUILD @@ -9,7 +9,7 @@ py_binary( "detector.py", ], data = [ - "@com_github_bufbuild_buf//:buf", + "@rules_buf_toolchains//:buf", "@envoy_api//:proto_breaking_change_detector_buf_config", ], main = "detector.py", @@ -25,9 +25,9 @@ py_binary( srcs = [ "detector_ci.py", ], - args = ["$(location @com_github_bufbuild_buf//:buf)"], + args = ["$(location @rules_buf_toolchains//:buf)"], data = [ - "@com_github_bufbuild_buf//:buf", + "@rules_buf_toolchains//:buf", ], deps = [ ":detector", diff --git a/tools/api_proto_breaking_change_detector/detector_test.py b/tools/api_proto_breaking_change_detector/detector_test.py index 0417f21c3fd9..89542a5d5f9a 100644 --- a/tools/api_proto_breaking_change_detector/detector_test.py +++ b/tools/api_proto_breaking_change_detector/detector_test.py @@ -85,7 +85,7 @@ def test_remove_and_reserve_field(self): class BufTests(TestAllowedChanges, TestBreakingChanges, unittest.TestCase): - _buf_path = runfiles.Create().Rlocation("com_github_bufbuild_buf/bin/buf") + _buf_path = runfiles.Create().Rlocation("rules_buf_toolchains/buf") @classmethod def _run_command_print_error(cls, cmd): diff --git a/tools/proto_format/proto_format.sh b/tools/proto_format/proto_format.sh index 57ac3f721b77..fa4ff3b2cc08 100755 --- a/tools/proto_format/proto_format.sh +++ b/tools/proto_format/proto_format.sh @@ -33,5 +33,5 @@ bazel "${BAZEL_STARTUP_OPTIONS[@]}" run "${BAZEL_BUILD_OPTIONS[@]}" \ if [[ -n "$CI_BRANCH" ]] || [[ "${FORCE_PROTO_FORMAT}" == "yes" ]]; then echo "Run buf tests" cd api/ || exit 1 - bazel "${BAZEL_STARTUP_OPTIONS[@]}" run "${BAZEL_BUILD_OPTIONS[@]}" @com_github_bufbuild_buf//:bin/buf lint + bazel "${BAZEL_STARTUP_OPTIONS[@]}" run "${BAZEL_BUILD_OPTIONS[@]}" @rules_buf_toolchains//:buf lint fi From cb13cc6c625fd9c4884a2b25864d7280e2ff7be9 Mon Sep 17 00:00:00 2001 From: zirain Date: Thu, 20 Feb 2025 11:20:59 +0800 Subject: [PATCH 3/5] fix format Signed-off-by: zirain --- tools/api_proto_breaking_change_detector/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/api_proto_breaking_change_detector/BUILD b/tools/api_proto_breaking_change_detector/BUILD index b95128b3d97a..e157bb599611 100644 --- a/tools/api_proto_breaking_change_detector/BUILD +++ b/tools/api_proto_breaking_change_detector/BUILD @@ -9,8 +9,8 @@ py_binary( "detector.py", ], data = [ - "@rules_buf_toolchains//:buf", "@envoy_api//:proto_breaking_change_detector_buf_config", + "@rules_buf_toolchains//:buf", ], main = "detector.py", tags = ["manual"], From 2e93ef0f8511caadb911ff197016ffd5406c4b94 Mon Sep 17 00:00:00 2001 From: zirain Date: Thu, 20 Feb 2025 11:31:41 +0800 Subject: [PATCH 4/5] fix deps Signed-off-by: zirain --- api/bazel/repository_locations.bzl | 2 +- ci/do_ci.sh | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/api/bazel/repository_locations.bzl b/api/bazel/repository_locations.bzl index 21bddaa62266..9bbe59b49fd0 100644 --- a/api/bazel/repository_locations.bzl +++ b/api/bazel/repository_locations.bzl @@ -107,7 +107,7 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_url = "https://github.com/bufbuild/rules_buf", version = "0.3.0", sha256 = "89c6d6e6523802ee7f1210340a69fab4ee0b47554953a1ecbe359319fd3f93dc", - release_date = "2024-05-23", + release_date = "2024-05-22", strip_prefix = "rules_buf-{version}", urls = ["https://github.com/bufbuild/rules_buf/archive/refs/tags/v{version}.tar.gz"], use_category = ["api"], diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 2e3fe1aed254..16ceaa8c56e2 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -29,6 +29,9 @@ else fi setup_clang_toolchain() { + if [[ -n "${CLANG_TOOLCHAIN_SETUP}" ]]; then + return + fi CONFIG_PARTS=() if [[ -n "${ENVOY_RBE}" ]]; then CONFIG_PARTS+=("remote") @@ -209,9 +212,7 @@ function bazel_envoy_api_build() { } function bazel_envoy_api_go_build() { - if [[ -z "$CLANG_TOOLCHAIN_SETUP" ]]; then - setup_clang_toolchain - fi + setup_clang_toolchain GO_IMPORT_BASE="github.com/envoyproxy/go-control-plane" GO_TARGETS=(@envoy_api//...) read -r -a GO_PROTOS <<< "$(bazel query "${BAZEL_GLOBAL_OPTIONS[@]}" "kind('go_proto_library', ${GO_TARGETS[*]})" | tr '\n' ' ')" @@ -322,9 +323,7 @@ case $CI_TARGET in ;; format-api|check_and_fix_proto_format) - if [[ -z "$CLANG_TOOLCHAIN_SETUP" ]]; then - setup_clang_toolchain - fi + setup_clang_toolchain echo "Check and fix proto format ..." "${ENVOY_SRCDIR}/ci/check_and_fix_format.sh" ;; From d5000297f5aa7ad348ecc826def70da1119bf1a9 Mon Sep 17 00:00:00 2001 From: zirain Date: Thu, 20 Feb 2025 19:21:29 +0800 Subject: [PATCH 5/5] move to envoy_dependency_imports Signed-off-by: zirain --- WORKSPACE | 4 ---- bazel/dependency_imports.bzl | 7 ++++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 06d01eba7a20..e4460bfc5475 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -8,10 +8,6 @@ load("//bazel:api_repositories.bzl", "envoy_api_dependencies") envoy_api_dependencies() -load("@rules_buf//buf:repositories.bzl", "rules_buf_toolchains") - -rules_buf_toolchains(version = "v1.50.0") - load("//bazel:repo.bzl", "envoy_repo") envoy_repo() diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index c68eb4bf3ed2..0baedf3ee0c7 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -10,6 +10,7 @@ load("@emsdk//:emscripten_deps.bzl", "emscripten_deps") load("@fuzzing_pip3//:requirements.bzl", pip_fuzzing_dependencies = "install_deps") load("@io_bazel_rules_go//go:deps.bzl", "go_download_sdk", "go_register_toolchains", "go_rules_dependencies") load("@proxy_wasm_rust_sdk//bazel:dependencies.bzl", "proxy_wasm_rust_sdk_dependencies") +load("@rules_buf//buf:repositories.bzl", "rules_buf_toolchains") load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies") load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") @@ -25,7 +26,9 @@ GO_VERSION = "1.23.1" JQ_VERSION = "1.7" YQ_VERSION = "4.24.4" -def envoy_dependency_imports(go_version = GO_VERSION, jq_version = JQ_VERSION, yq_version = YQ_VERSION): +BUF_VERSION = "v1.50.0" + +def envoy_dependency_imports(go_version = GO_VERSION, jq_version = JQ_VERSION, yq_version = YQ_VERSION, buf_version = BUF_VERSION): rules_foreign_cc_dependencies() go_rules_dependencies() go_register_toolchains(go_version) @@ -66,6 +69,8 @@ def envoy_dependency_imports(go_version = GO_VERSION, jq_version = JQ_VERSION, y register_yq_toolchains(version = yq_version) parser_deps() + rules_buf_toolchains(version = buf_version) + # These dependencies, like most of the Go in this repository, exist only for the API. # These repos also have transient dependencies - `build_external` allows them to use them. # TODO(phlax): remove `build_external` and pin all transients