Skip to content
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
16 changes: 16 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ pip.parse(
use_repo(pip, "python_deps")

# Protobuf dependencies
# toolchains_protoc must be declared before protobuf so its toolchain registration wins
bazel_dep(name = "toolchains_protoc", version = "0.6.1")

protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc")
protoc.toolchain(version = "v32.1")
use_repo(
protoc,
"toolchains_protoc_hub",
"toolchains_protoc_hub.linux_aarch_64",
"toolchains_protoc_hub.linux_x86_64",
"toolchains_protoc_hub.osx_aarch_64",
"toolchains_protoc_hub.osx_x86_64",
)

register_toolchains("@toolchains_protoc_hub//:all")

bazel_dep(
name = "protobuf",
version = "32.1",
Expand Down
15 changes: 15 additions & 0 deletions bazel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ write_info_file_var(
visibility = ["//visibility:public"],
)

# Prebuilt protoc binary, selected by exec platform.
# Used in cargo_build_script rules instead of @protobuf//:protoc to avoid
# compiling protoc from C++ source on every build.
# Platform config_settings are defined in //:BUILD.bazel alongside platform() rules.
alias(
name = "protoc",
actual = select({
"@bazel_tools//src/conditions:linux_x86_64": "@toolchains_protoc_hub.linux_x86_64//:bin/protoc",
"@bazel_tools//src/conditions:linux_aarch64": "@toolchains_protoc_hub.linux_aarch_64//:bin/protoc",
"@bazel_tools//src/conditions:darwin_x86_64": "@toolchains_protoc_hub.osx_x86_64//:bin/protoc",
"@bazel_tools//src/conditions:darwin_arm64": "@toolchains_protoc_hub.osx_aarch_64//:bin/protoc",
}),
visibility = ["//visibility:public"],
)

exports_files(
[
"prost_generator.sh",
Expand Down
4 changes: 4 additions & 0 deletions bazel/conf/.bazelrc.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# lockfile for MODULE.bazel
common --lockfile_mode=off

# Use prebuilt protoc binary via toolchain resolution instead of compiling from C++ source.
# See https://github.com/protocolbuffers/protobuf/issues/19558
common --incompatible_enable_proto_toolchain_resolution

# Use hermetic JDK
# See https://bazel.build/docs/bazel-and-java#hermetic-testing
build --java_runtime_version=remotejdk_17
Expand Down
10 changes: 4 additions & 6 deletions bazel/prost.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ def generated_files_check(name, srcs, deps, data, manifest_dir):
srcs = srcs,
data = data + [
"@rules_rust//rust/toolchain:current_rustfmt_files",
"@protobuf//:protoc",
"//bazel:protoc",
"@protobuf//:descriptor_proto_srcs",
"@protobuf//:protobuf_headers",
"@protobuf//:well_known_type_protos",
],
env = {
"PROTOC": "$(rootpath @protobuf//:protoc)",
"PROTOC": "$(rootpath //bazel:protoc)",
"PROTOC_INCLUDE": PROTOC_INCLUDE,
"CARGO_MANIFEST_DIR": manifest_dir,
"RUSTFMT": "$(rootpath @rules_rust//rust/toolchain:current_rustfmt_files)",
Expand All @@ -44,13 +43,12 @@ def protobuf_generator(name, srcs, manifest_dir, deps = [], data = []):
":" + binary_name,
"@protobuf//:well_known_type_protos",
"@protobuf//:descriptor_proto_srcs",
"@protobuf//:protoc",
"@protobuf//:protobuf_headers",
"//bazel:protoc",
"@rules_rust//rust/toolchain:current_rustfmt_files",
],
srcs = ["//bazel:prost_generator.sh"],
env = {
"PROTOC": "$(location @protobuf//:protoc)",
"PROTOC": "$(location //bazel:protoc)",
"PROTOC_INCLUDE": PROTOC_INCLUDE,
"CARGO_MANIFEST_DIR": manifest_dir,
"GENERATOR": "$(location :%s)" % binary_name,
Expand Down
4 changes: 2 additions & 2 deletions rs/bitcoin/service/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ cargo_build_script(
srcs = ["build.rs"],
build_script_env = {
"CARGO_MANIFEST_DIR": "rs/bitcoin/service",
"PROTOC": "$(execpath @protobuf//:protoc)",
"PROTOC": "$(execpath //bazel:protoc)",
"RUSTFMT": "$(execpath @rules_rust//rust/toolchain:current_rustfmt_files)",
},
data = [
"proto/btc_service/v1/proto.proto",
"@rules_rust//rust/toolchain:current_rustfmt_files",
],
tools = [
"@protobuf//:protoc",
"//bazel:protoc",
],
deps = [
# Keep sorted.
Expand Down
4 changes: 2 additions & 2 deletions rs/https_outcalls/service/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ cargo_build_script(
srcs = ["build.rs"],
build_script_env = {
"CARGO_MANIFEST_DIR": "rs/https_outcalls/service",
"PROTOC": "$(execpath @protobuf//:protoc)",
"PROTOC": "$(execpath //bazel:protoc)",
"RUSTFMT": "$(execpath @rules_rust//rust/toolchain:current_rustfmt_files)",
},
data = [
"proto/https_outcalls_service/v1/proto.proto",
"@rules_rust//rust/toolchain:current_rustfmt_files",
],
tools = [
"@protobuf//:protoc",
"//bazel:protoc",
],
deps = [
# Keep sorted.
Expand Down
6 changes: 4 additions & 2 deletions rs/ic_os/guest_upgrade/shared/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ cargo_build_script(
srcs = ["build.rs"],
build_script_env = {
"CARGO_MANIFEST_DIR": "rs/ic_os/guest_upgrade/shared",
"PROTOC": "$(execpath @protobuf//:protoc)",
"PROTOC": "$(execpath //bazel:protoc)",
"RUSTFMT": "$(execpath @rules_rust//rust/toolchain:current_rustfmt_files)",
},
data = [
"proto/api.proto",
"//rs/ic_os/sev/attestation:proto/attestation.proto",
"@protobuf//:protoc",
"@rules_rust//rust/toolchain:current_rustfmt_files",
],
tools = [
"//bazel:protoc",
],
deps = [
"@crate_index//:tonic-build",
],
Expand Down
6 changes: 4 additions & 2 deletions rs/ic_os/remote_attestation/shared/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ cargo_build_script(
srcs = ["build.rs"],
build_script_env = {
"CARGO_MANIFEST_DIR": "rs/ic_os/remote_attestation/shared",
"PROTOC": "$(execpath @protobuf//:protoc)",
"PROTOC": "$(execpath //bazel:protoc)",
"RUSTFMT": "$(execpath @rules_rust//rust/toolchain:current_rustfmt_files)",
},
data = [
"proto/remote_attestation.proto",
"//rs/ic_os/sev/attestation:proto/attestation.proto",
"@protobuf//:protoc",
"@rules_rust//rust/toolchain:current_rustfmt_files",
],
tools = [
"//bazel:protoc",
],
deps = [
"@crate_index//:tonic-build",
],
Expand Down
4 changes: 2 additions & 2 deletions rs/monitoring/adapter_metrics/service/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ cargo_build_script(
name = "build_script",
srcs = ["build.rs"],
build_script_env = {
"PROTOC": "$(execpath @protobuf//:protoc)",
"PROTOC": "$(execpath //bazel:protoc)",
"RUSTFMT": "$(execpath @rules_rust//rust/toolchain:current_rustfmt_files)",
},
data = [
"proto/adapter_metrics/v1/proto.proto",
"@rules_rust//rust/toolchain:current_rustfmt_files",
],
tools = [
"@protobuf//:protoc",
"//bazel:protoc",
],
deps = [
# Keep sorted.
Expand Down
Loading