binarystore: Convert to nanopb
This converts the on BMC code to use nanopb, while keeping the test code
using the standard protobuf impl. This is an effort to reduce code size
for some of our legacy BMCs which requires us to get rid of the standard
protobuf implementation where possible.
Change-Id: I522087820ae437a595c24aebc2086bea8908cfcc
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/proto/meson.build b/proto/meson.build
index 5c2ec4a..452114c 100644
--- a/proto/meson.build
+++ b/proto/meson.build
@@ -1,28 +1,100 @@
-src_pb = custom_target(
- 'proto',
- command: [
- find_program('protoc', native: true),
- '--proto_path=@CURRENT_SOURCE_DIR@',
- '--cpp_out=@OUTDIR@',
- '@INPUT@'
+binaryblob_proto_kwargs = {
+ 'output': [
+ '@BASENAME@.pb.h',
+ '@BASENAME@.pb.cc',
],
- output: [
- 'binaryblob.pb.h',
- 'binaryblob.pb.cc',
+ 'command': [
+ find_program('protoc', native: true, disabler: true, required: get_option('tests')),
+ '-I@SOURCE_ROOT@/proto',
+ '--cpp_out=@BUILD_ROOT@/proto',
+ '@INPUT@',
],
- input: 'binaryblob.proto')
+}
-binaryblobproto_pre = declare_dependency(
+nanopb = find_program('nanopb_generator.py', native: true, required: false)
+if not nanopb.found()
+ nanopb_opts = import('cmake').subproject_options()
+ nanopb_opts.add_cmake_defines({'BUILD_SHARED_LIBS': 'ON'})
+ nanopb_proj = import('cmake').subproject('nanopb', options: nanopb_opts)
+ nanopb = find_program(meson.global_source_root() + '/subprojects/nanopb/generator/nanopb_generator.py', native: true)
+ nanopb_dep = nanopb_proj.dependency('protobuf_nanopb')
+else
+ nanopb_dep = meson.get_compiler('cpp').find_library('protobuf-nanopb')
+endif
+
+binaryblob_nanopb_kwargs = {
+ 'output': [
+ '@BASENAME@.pb.n.h',
+ '@BASENAME@.pb.n.c',
+ ],
+ 'command': [
+ nanopb,
+ '-q',
+ '-s', 'packed_struct:0',
+ '-H.n.h',
+ '-S.n.c',
+ '-I@SOURCE_ROOT@/proto',
+ '-D@BUILD_ROOT@/proto',
+ '@INPUT@',
+ ],
+}
+
+binaryblob_proto_src = []
+binaryblob_proto_hdr = []
+binaryblob_nanopb_src = []
+binaryblob_nanopb_hdr = []
+protos = [
+ 'binaryblob',
+]
+
+foreach proto : protos
+ tgt = custom_target(
+ proto + '.pb.hcc',
+ input: proto + '.proto',
+ kwargs: binaryblob_proto_kwargs,
+ build_by_default: false)
+ binaryblob_proto_hdr += tgt[0]
+ binaryblob_proto_src += tgt[1]
+
+ tgt = custom_target(
+ proto + '.pb.n.hc',
+ input: proto + '.proto',
+ kwargs: binaryblob_nanopb_kwargs)
+ binaryblob_nanopb_hdr += tgt[0]
+ binaryblob_nanopb_src += tgt[1]
+endforeach
+
+binaryblob_proto_pre = declare_dependency(
include_directories: include_directories('.'),
- dependencies: dependency('protobuf'))
+ sources: binaryblob_proto_hdr,
+ dependencies: [
+ dependency('protobuf', disabler: true, required: get_option('tests')),
+ ])
-binaryblobproto_lib = static_library(
+binaryblob_proto_lib = static_library(
'binaryblob_proto',
- src_pb[1],
+ binaryblob_proto_src,
implicit_include_directories: false,
- dependencies: binaryblobproto_pre)
+ dependencies: binaryblob_proto_pre,
+ build_by_default: false)
-binaryblobproto_dep = declare_dependency(
- dependencies: binaryblobproto_pre,
- link_with: binaryblobproto_lib,
- sources: src_pb[0])
+binaryblob_proto_dep = declare_dependency(
+ dependencies: binaryblob_proto_pre,
+ link_with: binaryblob_proto_lib)
+
+binaryblob_nanopb_pre = declare_dependency(
+ include_directories: include_directories('.'),
+ sources: binaryblob_nanopb_hdr,
+ dependencies: [
+ nanopb_dep,
+ ])
+
+binaryblob_nanopb_lib = static_library(
+ 'binaryblob_nanopb',
+ binaryblob_nanopb_src,
+ implicit_include_directories: false,
+ dependencies: binaryblob_nanopb_pre)
+
+binaryblob_nanopb_dep = declare_dependency(
+ dependencies: binaryblob_nanopb_pre,
+ link_with: binaryblob_nanopb_lib)