From df399c1f90eb0b864ac4d1e0f08f63b2603185f4 Mon Sep 17 00:00:00 2001 From: Markus Hofbauer Date: Thu, 21 Aug 2025 13:26:21 -0700 Subject: [PATCH] Fix flags presets --- MODULE.bazel | 1 + protoc/flags.bzl | 38 ++++++++++++++++++++++---------------- tests/BUILD.bazel | 7 +++++++ 3 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 tests/BUILD.bazel diff --git a/MODULE.bazel b/MODULE.bazel index c98de63..ddaa68c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -12,6 +12,7 @@ bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "aspect_bazel_lib", version = "2.8.1", dev_dependency = True) bazel_dep(name = "buildifier_prebuilt", version = "6.1.2", dev_dependency = True) +bazel_dep(name = "bazelrc-preset.bzl", version = "1.2.0", dev_dependency = True) protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc") protoc.toolchain( diff --git a/protoc/flags.bzl b/protoc/flags.bzl index 88bc01c..23eaed4 100644 --- a/protoc/flags.bzl +++ b/protoc/flags.bzl @@ -8,20 +8,26 @@ PROTOC_TOOLCHAIN_FLAGS = { That flag ALSO decouples how each built-in language rule (Java, Python, C++, etc.) locates the runtime. """, ), - "per_file_copt": struct( - default = "external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT", - description = "Make sure protobuf is not built from source", - ), - "host_per_file_copt": struct( - default = "external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT", - description = "Make sure protobuf is not built from source", - ), - "per_file_copt": struct( - default = "external/.*grpc.*@--GRPC_WAS_NOT_SUPPOSED_TO_BE_BUILT", - description = "Make sure grpc is not built from source", - ), - "host_per_file_copt": struct( - default = "external/.*grpc.*@--GRPC_WAS_NOT_SUPPOSED_TO_BE_BUILT", - description = "Make sure grpc is not built from source", - ), + "per_file_copt": [ + struct( + default = "external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT", + description = "Make sure protobuf is not built from source", + ), + struct( + default = "external/.*grpc.*@--GRPC_WAS_NOT_SUPPOSED_TO_BE_BUILT", + description = "Make sure grpc is not built from source", + allow_repeated = True, + ), + ], + "host_per_file_copt": [ + struct( + default = "external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT", + description = "Make sure protobuf is not built from source", + ), + struct( + default = "external/.*grpc.*@--GRPC_WAS_NOT_SUPPOSED_TO_BE_BUILT", + description = "Make sure grpc is not built from source", + allow_repeated = True, + ), + ], } diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel new file mode 100644 index 0000000..09a9d15 --- /dev/null +++ b/tests/BUILD.bazel @@ -0,0 +1,7 @@ +load("@bazelrc-preset.bzl", "bazelrc_preset_test") +load("//protoc:flags.bzl", "PROTOC_TOOLCHAIN_FLAGS") + +bazelrc_preset_test( + name = "test_protoc_toolchain_flags", + extra_presets = PROTOC_TOOLCHAIN_FLAGS, +)