From f8cfc76c619f93444e9cc10a2834e70c3e21e4bc Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 4 Jun 2025 13:41:55 -0700 Subject: [PATCH 1/8] refactor: use pre-built protoc binary Saves a bunch of time in analysis and execution when there is a cache miss on protoc, as well as avoiding a bunch of gcc logspam. --- .bazelrc | 5 +++++ MODULE.bazel | 9 +++++++++ MODULE.bazel.lock | 2 ++ 3 files changed, 16 insertions(+) diff --git a/.bazelrc b/.bazelrc index 23d1c5b6..3953cdb3 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1 +1,6 @@ run --workspace_status_command="bash tools/workspace-status.sh" + +# Don't build protoc from the cc_binary, it's slow and spammy when cache miss +common --per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT +common --host_per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT +common --incompatible_enable_proto_toolchain_resolution diff --git a/MODULE.bazel b/MODULE.bazel index 2e4df22a..52f22239 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -14,6 +14,7 @@ bazel_dep(name = "rules_oci", version = "2.2.5") bazel_dep(name = "rules_pkg", version = "1.0.1") bazel_dep(name = "rules_proto", version = "7.1.0") bazel_dep(name = "toolchains_llvm", version = "1.3.0") +bazel_dep(name = "toolchains_protoc", version = "0.4.2") git_override( module_name = "bazel_remote_apis", @@ -31,6 +32,14 @@ single_version_override( patches = ["//:patches/jsonnet/bazel-8.diff"], ) +protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc") + +# Match protobuf above, until it ships a pre-built binary toolchain itself +protoc.toolchain(version = "v29.3") +use_repo(protoc, "toolchains_protoc_hub") + +register_toolchains("@toolchains_protoc_hub//:all") + go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") go_sdk.download(version = "1.24.0") diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 1a68e132..d8e5ca0f 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -247,6 +247,8 @@ "https://bcr.bazel.build/modules/stardoc/0.7.1/source.json": "b6500ffcd7b48cd72c29bb67bcac781e12701cc0d6d55d266a652583cfcdab01", "https://bcr.bazel.build/modules/toolchains_llvm/1.3.0/MODULE.bazel": "6e02731e51f7eb2ec4b01c5e79e722bf738a631f6e03d9b4917cbf2cb027bee1", "https://bcr.bazel.build/modules/toolchains_llvm/1.3.0/source.json": "4ce0373a89c6df34dd37cd67285bb871d8e225d30dcb67dd093e077a04bbbb71", + "https://bcr.bazel.build/modules/toolchains_protoc/0.4.2/MODULE.bazel": "05a00ffcc77a1bb9bec936621a29865953e8a2fe06f9476bd050b10e9ea84ca3", + "https://bcr.bazel.build/modules/toolchains_protoc/0.4.2/source.json": "ddbdfcdc65c4b1e2533d3b8ca0b4b8975b921147d7501e9b556e3d3689f6e427", "https://bcr.bazel.build/modules/upb/0.0.0-20211020-160625a/MODULE.bazel": "6cced416be2dc5b9c05efd5b997049ba795e5e4e6fafbe1624f4587767638928", "https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/MODULE.bazel": "7298990c00040a0e2f121f6c32544bab27d4452f80d9ce51349b1a28f3005c43", "https://bcr.bazel.build/modules/upb/0.0.0-20230516-61a97ef/MODULE.bazel": "c0df5e35ad55e264160417fd0875932ee3c9dda63d9fccace35ac62f45e1b6f9", From af562e903655d9f9d0fa9b16339e372e604514b9 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Sun, 8 Jun 2025 14:59:32 -0700 Subject: [PATCH 2/8] remove unneeded lines --- .bazelrc | 4 ---- MODULE.bazel | 2 -- 2 files changed, 6 deletions(-) diff --git a/.bazelrc b/.bazelrc index 3953cdb3..0bd0e6ed 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,6 +1,2 @@ run --workspace_status_command="bash tools/workspace-status.sh" - -# Don't build protoc from the cc_binary, it's slow and spammy when cache miss -common --per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT -common --host_per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT common --incompatible_enable_proto_toolchain_resolution diff --git a/MODULE.bazel b/MODULE.bazel index 52f22239..85743acd 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -36,9 +36,7 @@ protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc") # Match protobuf above, until it ships a pre-built binary toolchain itself protoc.toolchain(version = "v29.3") -use_repo(protoc, "toolchains_protoc_hub") -register_toolchains("@toolchains_protoc_hub//:all") go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") go_sdk.download(version = "1.24.0") From 40aa8076fe9aa5161e384aedebd1220ed15e2b16 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Sun, 8 Jun 2025 15:16:20 -0700 Subject: [PATCH 3/8] temporarily verify no protoc compiles --- .bazelrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bazelrc b/.bazelrc index 0bd0e6ed..dae8611b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,2 +1,4 @@ run --workspace_status_command="bash tools/workspace-status.sh" common --incompatible_enable_proto_toolchain_resolution +common --per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT +common --host_per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT From 20deed1ba6348ac2ba219a5b1c9e4b70333e1958 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Sun, 8 Jun 2025 22:27:44 +0000 Subject: [PATCH 4/8] Move no-compile assertion to CI-only --- .bazelrc | 2 -- .github/workflows/ci.bazelrc | 2 ++ .github/workflows/master.yaml | 2 +- .github/workflows/pull-requests.yaml | 2 +- tools/github_workflows/workflows_template.libsonnet | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/ci.bazelrc diff --git a/.bazelrc b/.bazelrc index dae8611b..0bd0e6ed 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,4 +1,2 @@ run --workspace_status_command="bash tools/workspace-status.sh" common --incompatible_enable_proto_toolchain_resolution -common --per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT -common --host_per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT diff --git a/.github/workflows/ci.bazelrc b/.github/workflows/ci.bazelrc new file mode 100644 index 00000000..58e9ce8a --- /dev/null +++ b/.github/workflows/ci.bazelrc @@ -0,0 +1,2 @@ +common --per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT +common --host_per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT diff --git a/.github/workflows/master.yaml b/.github/workflows/master.yaml index 984ebd88..9568627d 100644 --- a/.github/workflows/master.yaml +++ b/.github/workflows/master.yaml @@ -9,7 +9,7 @@ }, { "name": "Installing Bazel", - "run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}" + "run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH} && ( [ -e .github/workflows/ci.bazelrc ] && cp .github/workflows/ci.bazelrc ~/.bazelrc )" }, { "name": "Bazel mod tidy", diff --git a/.github/workflows/pull-requests.yaml b/.github/workflows/pull-requests.yaml index 78d34da2..a55eb1a5 100644 --- a/.github/workflows/pull-requests.yaml +++ b/.github/workflows/pull-requests.yaml @@ -9,7 +9,7 @@ }, { "name": "Installing Bazel", - "run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}" + "run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH} && ( [ -e .github/workflows/ci.bazelrc ] && cp .github/workflows/ci.bazelrc ~/.bazelrc )" }, { "name": "Bazel mod tidy", diff --git a/tools/github_workflows/workflows_template.libsonnet b/tools/github_workflows/workflows_template.libsonnet index 89861ab7..f3000cbf 100644 --- a/tools/github_workflows/workflows_template.libsonnet +++ b/tools/github_workflows/workflows_template.libsonnet @@ -66,7 +66,7 @@ }, { name: 'Installing Bazel', - run: 'v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}', + run: 'v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH} && ( [ -e .github/workflows/ci.bazelrc ] && cp .github/workflows/ci.bazelrc ~/.bazelrc )', }, { name: 'Bazel mod tidy', From d025d52bee4d2bf643eb7b0a93e21d9ff3a931b7 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Sun, 8 Jun 2025 22:39:01 +0000 Subject: [PATCH 5/8] add back needed register_toolchains --- MODULE.bazel | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MODULE.bazel b/MODULE.bazel index 85743acd..52f22239 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -36,7 +36,9 @@ protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc") # Match protobuf above, until it ships a pre-built binary toolchain itself protoc.toolchain(version = "v29.3") +use_repo(protoc, "toolchains_protoc_hub") +register_toolchains("@toolchains_protoc_hub//:all") go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") go_sdk.download(version = "1.24.0") From 1ce429217e942cdb297687be95c1e4a27fdc95b2 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Tue, 10 Jun 2025 08:54:36 -0700 Subject: [PATCH 6/8] debugging why we compile protoc without register_toolchains --- .bazelrc | 3 +++ .github/workflows/ci.bazelrc | 2 -- .github/workflows/master.yaml | 2 +- .github/workflows/pull-requests.yaml | 2 +- MODULE.bazel | 8 ++------ tools/github_workflows/workflows_template.libsonnet | 2 +- 6 files changed, 8 insertions(+), 11 deletions(-) delete mode 100644 .github/workflows/ci.bazelrc diff --git a/.bazelrc b/.bazelrc index 0bd0e6ed..10ac6023 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,2 +1,5 @@ run --workspace_status_command="bash tools/workspace-status.sh" common --incompatible_enable_proto_toolchain_resolution +# Ensure that we don't accidentally build protobuf +common --per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT +common --host_per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT diff --git a/.github/workflows/ci.bazelrc b/.github/workflows/ci.bazelrc deleted file mode 100644 index 58e9ce8a..00000000 --- a/.github/workflows/ci.bazelrc +++ /dev/null @@ -1,2 +0,0 @@ -common --per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT -common --host_per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT diff --git a/.github/workflows/master.yaml b/.github/workflows/master.yaml index 9568627d..984ebd88 100644 --- a/.github/workflows/master.yaml +++ b/.github/workflows/master.yaml @@ -9,7 +9,7 @@ }, { "name": "Installing Bazel", - "run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH} && ( [ -e .github/workflows/ci.bazelrc ] && cp .github/workflows/ci.bazelrc ~/.bazelrc )" + "run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}" }, { "name": "Bazel mod tidy", diff --git a/.github/workflows/pull-requests.yaml b/.github/workflows/pull-requests.yaml index a55eb1a5..78d34da2 100644 --- a/.github/workflows/pull-requests.yaml +++ b/.github/workflows/pull-requests.yaml @@ -9,7 +9,7 @@ }, { "name": "Installing Bazel", - "run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH} && ( [ -e .github/workflows/ci.bazelrc ] && cp .github/workflows/ci.bazelrc ~/.bazelrc )" + "run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}" }, { "name": "Bazel mod tidy", diff --git a/MODULE.bazel b/MODULE.bazel index 52f22239..373c2dea 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -7,6 +7,7 @@ bazel_dep(name = "gazelle", version = "0.42.0") bazel_dep(name = "googleapis", version = "0.0.0-20240819-fe8ba054a") bazel_dep(name = "jsonnet_go", version = "0.20.0") bazel_dep(name = "opentelemetry-proto", version = "1.5.0") +bazel_dep(name = "toolchains_protoc", version = "0.4.2") # must come BEFORE protobuf so the toolchain registration wins bazel_dep(name = "protobuf", version = "29.3") bazel_dep(name = "rules_go", version = "0.53.0") bazel_dep(name = "rules_jsonnet", version = "0.6.0") @@ -14,7 +15,6 @@ bazel_dep(name = "rules_oci", version = "2.2.5") bazel_dep(name = "rules_pkg", version = "1.0.1") bazel_dep(name = "rules_proto", version = "7.1.0") bazel_dep(name = "toolchains_llvm", version = "1.3.0") -bazel_dep(name = "toolchains_protoc", version = "0.4.2") git_override( module_name = "bazel_remote_apis", @@ -32,13 +32,9 @@ single_version_override( patches = ["//:patches/jsonnet/bazel-8.diff"], ) -protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc") - # Match protobuf above, until it ships a pre-built binary toolchain itself +protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc") protoc.toolchain(version = "v29.3") -use_repo(protoc, "toolchains_protoc_hub") - -register_toolchains("@toolchains_protoc_hub//:all") go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") go_sdk.download(version = "1.24.0") diff --git a/tools/github_workflows/workflows_template.libsonnet b/tools/github_workflows/workflows_template.libsonnet index f3000cbf..89861ab7 100644 --- a/tools/github_workflows/workflows_template.libsonnet +++ b/tools/github_workflows/workflows_template.libsonnet @@ -66,7 +66,7 @@ }, { name: 'Installing Bazel', - run: 'v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH} && ( [ -e .github/workflows/ci.bazelrc ] && cp .github/workflows/ci.bazelrc ~/.bazelrc )', + run: 'v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}', }, { name: 'Bazel mod tidy', From 97ab05f54844e65c51923374b93418d6adc2092b Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Tue, 10 Jun 2025 09:35:12 -0700 Subject: [PATCH 7/8] Update MODULE.bazel --- MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 373c2dea..5c1cca48 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -7,7 +7,7 @@ bazel_dep(name = "gazelle", version = "0.42.0") bazel_dep(name = "googleapis", version = "0.0.0-20240819-fe8ba054a") bazel_dep(name = "jsonnet_go", version = "0.20.0") bazel_dep(name = "opentelemetry-proto", version = "1.5.0") -bazel_dep(name = "toolchains_protoc", version = "0.4.2") # must come BEFORE protobuf so the toolchain registration wins +bazel_dep(name = "toolchains_protoc", version = "0.4.2") # must come BEFORE protobuf so the toolchain registration wins bazel_dep(name = "protobuf", version = "29.3") bazel_dep(name = "rules_go", version = "0.53.0") bazel_dep(name = "rules_jsonnet", version = "0.6.0") From 03eef2bde4b5d9d52e140d13479d8ac3b4dba3cd Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Tue, 10 Jun 2025 09:40:41 -0700 Subject: [PATCH 8/8] Update .bazelrc --- .bazelrc | 3 --- 1 file changed, 3 deletions(-) diff --git a/.bazelrc b/.bazelrc index 10ac6023..0bd0e6ed 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,5 +1,2 @@ run --workspace_status_command="bash tools/workspace-status.sh" common --incompatible_enable_proto_toolchain_resolution -# Ensure that we don't accidentally build protobuf -common --per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT -common --host_per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT