| // Copyright 2022 The Pigweed Authors |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| // use this file except in compliance with the License. You may obtain a copy of |
| // the License at |
| // |
| // https://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| // License for the specific language governing permissions and limitations under |
| // the License. |
| |
| package { |
| default_applicable_licenses: ["external_pigweed_license"], |
| } |
| |
| cc_library_static { |
| name: "pw_protobuf", |
| cpp_std: "c++20", |
| vendor_available: true, |
| export_include_dirs: ["public"], |
| defaults: [ |
| "pw_android_common_backends", |
| ], |
| header_libs: [ |
| "fuchsia_sdk_lib_fit", |
| "fuchsia_sdk_lib_stdcompat", |
| "pw_assert", |
| "pw_log", |
| ], |
| export_header_lib_headers: [ |
| "pw_assert", |
| "pw_log", |
| ], |
| host_supported: true, |
| srcs: [ |
| "decoder.cc", |
| "encoder.cc", |
| "find.cc", |
| "map_utils.cc", |
| "message.cc", |
| "stream_decoder.cc", |
| ], |
| static_libs: [ |
| "pw_bytes", |
| "pw_containers", |
| "pw_function", |
| "pw_polyfill", |
| "pw_preprocessor", |
| "pw_result", |
| "pw_span", |
| "pw_status", |
| "pw_stream", |
| "pw_string", |
| "pw_toolchain", |
| "pw_varint", |
| ], |
| export_static_lib_headers: [ |
| "pw_bytes", |
| "pw_containers", |
| "pw_function", |
| "pw_preprocessor", |
| "pw_result", |
| "pw_span", |
| "pw_status", |
| "pw_stream", |
| "pw_toolchain", |
| "pw_varint", |
| ], |
| } |
| |
| cc_library_headers { |
| name: "pw_protobuf_pwpb", |
| cpp_std: "c++20", |
| vendor_available: true, |
| host_supported: true, |
| generated_headers: [ |
| "google_protobuf_descriptor_pwpb_h", |
| "pw_protobuf_protos_common_pwpb_h", |
| ], |
| export_generated_headers: [ |
| "google_protobuf_descriptor_pwpb_h", |
| "pw_protobuf_protos_common_pwpb_h", |
| ], |
| } |
| |
| genrule { |
| name: "pw_protobuf_protos_common_nanopb_h", |
| srcs: [":pw_protobuf_common_proto_with_prefix"], |
| cmd: "python3 $(location pw_protobuf_compiler_py) " + |
| "--proto-path=external/pigweed/pw_protobuf/ " + |
| "--out-dir=$$(dirname $(location pw_protobuf_protos/common.pb.h)) " + |
| "--plugin-path=$(location protoc-gen-nanopb) " + |
| "--compile-dir=$$(dirname $(in)) " + |
| "--sources $(in) " + |
| "--language nanopb " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc) ", |
| out: [ |
| "pw_protobuf_protos/common.pb.h", |
| ], |
| tools: [ |
| "aprotoc", |
| "protoc-gen-nanopb", |
| "pw_protobuf_compiler_py", |
| ], |
| } |
| |
| // Copies the proto files to a prefix directory to add the prefix to the |
| // compiled proto. The prefix is taken from the directory name of the first |
| // item listen in out. |
| genrule_defaults { |
| name: "pw_protobuf_add_prefix_to_proto", |
| cmd: "out_files=($(out)); prefix=$$(dirname $${out_files[0]}); " + |
| "mkdir -p $${prefix}; cp -t $${prefix} $(in);", |
| } |
| |
| filegroup { |
| name: "pw_protobuf_common_proto", |
| srcs: [ |
| "pw_protobuf_protos/common.proto", |
| ], |
| } |
| |
| genrule { |
| name: "pw_protobuf_common_proto_with_prefix", |
| defaults: ["pw_protobuf_add_prefix_to_proto"], |
| srcs: [ |
| "pw_protobuf_protos/common.proto", |
| ], |
| out: [ |
| "pw_protobuf/pw_protobuf_protos/common.proto", |
| ], |
| } |
| |
| genrule { |
| name: "pw_protobuf_protos_common_pwpb_h", |
| srcs: [":pw_protobuf_common_proto_with_prefix"], |
| cmd: "python3 $(location pw_protobuf_compiler_py) " + |
| "--proto-path=external/pigweed/pw_protobuf/ " + |
| "--proto-path=external/protobuf/src/ " + |
| "--out-dir=$$(dirname $(location pw_protobuf_protos/common.pwpb.h)) " + |
| "--plugin-path=$(location pw_protobuf_plugin_py) " + |
| "--compile-dir=$$(dirname $(in)) " + |
| "--sources $(in) " + |
| "--language pwpb " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc) ", |
| out: [ |
| "pw_protobuf_protos/common.pwpb.h", |
| ], |
| tools: [ |
| "aprotoc", |
| "pw_protobuf_plugin_py", |
| "pw_protobuf_compiler_py", |
| ], |
| } |
| |
| // Generate the google/protobuf/descriptor.pwpb.h which is commonly imported. |
| genrule { |
| name: "google_protobuf_descriptor_pwpb_h", |
| // The libprotobuf-internal-descriptor-proto filegroup is unavailable so |
| // instead filter for just the descriptor.proto. |
| srcs: [":libprotobuf-internal-protos"], |
| cmd: "in_files=($(in)); compile_dir=$$(dirname $${in_files[0]}); " + |
| "proto_files=(); " + |
| "for f in \"$${in_files[@]}\"; do " + |
| "if [[ \"$${f##*descriptor.}\" == \"proto\" ]]; then " + |
| "proto_files+=(\"$${f}\"); fi; done; " + |
| "python3 $(location pw_protobuf_compiler_py) " + |
| "--proto-path=external/protobuf/src/ " + |
| "--out-dir=$$(dirname $(location google/protobuf/descriptor.pwpb.h)) " + |
| "--plugin-path=$(location pw_protobuf_plugin_py) " + |
| "--compile-dir=$${compile_dir} " + |
| "--sources $${proto_files} " + |
| "--language pwpb " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc) ", |
| out: [ |
| "google/protobuf/descriptor.pwpb.h", |
| ], |
| tools: [ |
| "aprotoc", |
| "pw_protobuf_plugin_py", |
| "pw_protobuf_compiler_py", |
| ], |
| } |
| |
| genrule { |
| name: "pw_protobuf_codegen_protos_py", |
| srcs: ["pw_protobuf_codegen_protos/codegen_options.proto"], |
| cmd: "$(location aprotoc) " + |
| "-I$$(dirname $(in)) " + |
| "--python_out=$(genDir) " + |
| "$(in)", |
| out: [ |
| "codegen_options_pb2.py", |
| ], |
| tools: [ |
| "aprotoc", |
| ], |
| } |
| |
| python_library_host { |
| name: "pw_protobuf_codegen_protos_py_lib", |
| srcs: [ |
| ":pw_protobuf_codegen_protos_py", |
| ], |
| pkg_path: "pw_protobuf_codegen_protos", |
| } |
| |
| genrule { |
| name: "pw_protobuf_protos_py", |
| srcs: [ |
| "pw_protobuf_protos/common.proto", |
| "pw_protobuf_protos/field_options.proto", |
| "pw_protobuf_protos/status.proto", |
| ":libprotobuf-internal-protos", |
| ], |
| cmd: "$(location aprotoc) " + |
| "-I$$(dirname $(location pw_protobuf_protos/common.proto)) " + |
| "-Iexternal/protobuf/src/ " + |
| "--python_out=$(genDir) " + |
| "$(in)", |
| out: [ |
| "common_pb2.py", |
| "field_options_pb2.py", |
| "status_pb2.py", |
| ], |
| tools: [ |
| "aprotoc", |
| ], |
| } |
| |
| python_library_host { |
| name: "pw_protobuf_protos_py_lib", |
| srcs: [ |
| ":pw_protobuf_protos_py", |
| ], |
| pkg_path: "pw_protobuf_protos", |
| } |