diff options
author | Tobias Thiel <tobias011@gmail.com> | 2023-10-11 07:15:13 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@github.mail.kapsi.fi> | 2023-10-11 20:56:15 +0300 |
commit | 33383170274e89d9c7cb73b12d5f30d7239f3532 (patch) | |
tree | dcf848520535933be3f7791b8c5191cd83409409 | |
parent | de01880fdcf1506279802963dcc6ce36f61b9f9a (diff) |
Add support for .options files in bazel rules
-rw-r--r-- | extra/bazel/nanopb_deps.bzl | 1 | ||||
-rw-r--r-- | extra/bazel/rules_proto_grpc.patch | 30 |
2 files changed, 31 insertions, 0 deletions
diff --git a/extra/bazel/nanopb_deps.bzl b/extra/bazel/nanopb_deps.bzl index aaed90c..7a752e4 100644 --- a/extra/bazel/nanopb_deps.bzl +++ b/extra/bazel/nanopb_deps.bzl @@ -32,6 +32,7 @@ def nanopb_deps(): if "rules_proto_grpc" not in native.existing_rules(): http_archive( name = "rules_proto_grpc", + patches = ["//extra/bazel:rules_proto_grpc.patch"], sha256 = "507e38c8d95c7efa4f3b1c0595a8e8f139c885cb41a76cab7e20e4e67ae87731", strip_prefix = "rules_proto_grpc-4.1.1", urls = ["https://github.com/rules-proto-grpc/rules_proto_grpc/archive/4.1.1.tar.gz"], diff --git a/extra/bazel/rules_proto_grpc.patch b/extra/bazel/rules_proto_grpc.patch new file mode 100644 index 0000000..641f4dc --- /dev/null +++ b/extra/bazel/rules_proto_grpc.patch @@ -0,0 +1,30 @@ +diff --git internal/compile.bzl internal/compile.bzl +index 0f060f8..2e7f960 100644 +--- internal/compile.bzl ++++ internal/compile.bzl +@@ -39,6 +39,11 @@ proto_compile_attrs = { + values = ["PREFIXED", "NO_PREFIX"], + doc = "The output mode for the target. PREFIXED (the default) will output to a directory named by the target within the current package root, NO_PREFIX will output directly to the current package. Using NO_PREFIX may lead to conflicting writes", + ), ++ "nanopb_options_file": attr.label( ++ doc = "Optional Nanopb options file for nanopb specfiically since options files couldn't be found by Bazel", ++ allow_single_file = True, ++ mandatory = False, ++ ) + } + + def proto_compile_impl(ctx): +@@ -58,10 +63,13 @@ def proto_compile_impl(ctx): + # Load attrs that we pass as args + # This is done to allow writing rules that can call proto_compile with mutable attributes, + # such as in doc_template_compile + options = ctx.attr.options + extra_protoc_args = getattr(ctx.attr, "extra_protoc_args", []) + extra_protoc_files = ctx.files.extra_protoc_files + ++ if ctx.file.nanopb_options_file: ++ extra_protoc_args = extra_protoc_args + ["--nanopb_plugin_opt=-f{}".format(ctx.file.nanopb_options_file.path)] ++ extra_protoc_files = ctx.files.extra_protoc_files + [ctx.file.nanopb_options_file] + # Execute with extracted attrs + return proto_compile(ctx, options, extra_protoc_args, extra_protoc_files) + |