1# 2# Makefile for Pigweed's RPC module 3# 4# NOTE: In order to use this, you *must* have the following: 5# - Installed mypy-protobuf and protoc 6# - nanopb-c git repo checked out 7# 8 9ifneq ($(PW_RPC_SRCS),) 10 11# Environment Checks ########################################################### 12 13# Location of various Pigweed modules 14PIGWEED_DIR = $(ANDROID_BUILD_TOP)/external/pigweed 15CHRE_PREFIX = $(ANDROID_BUILD_TOP)/system/chre 16CHRE_UTIL_DIR = $(CHRE_PREFIX)/util 17CHRE_API_DIR = $(CHRE_PREFIX)/chre_api 18PIGWEED_CHRE_DIR=$(CHRE_PREFIX)/external/pigweed 19PIGWEED_CHRE_UTIL_DIR = $(CHRE_UTIL_DIR)/pigweed 20 21ifeq ($(NANOPB_PREFIX),) 22$(error "PW_RPC_SRCS is non-empty. You must supply a NANOPB_PREFIX environment \ 23 variable containing a path to the nanopb project. Example: \ 24 export NANOPB_PREFIX=$$HOME/path/to/nanopb/nanopb-c") 25endif 26 27ifeq ($(PROTOC),) 28PROTOC=protoc 29endif 30 31PW_RPC_GEN_PATH = $(OUT)/pw_rpc_gen 32 33# Create proto used for header generation ###################################### 34 35PW_RPC_PROTO_GENERATOR = $(PIGWEED_DIR)/pw_protobuf_compiler/py/pw_protobuf_compiler/generate_protos.py 36PW_RPC_GENERATOR_PROTO = $(PIGWEED_DIR)/pw_rpc/internal/packet.proto 37PW_RPC_GENERATOR_COMPILED_PROTO = $(PW_RPC_GEN_PATH)/py/pw_rpc/internal/packet_pb2.py 38PW_PROTOBUF_PROTOS = $(PIGWEED_DIR)/pw_protobuf/pw_protobuf_protos/common.proto \ 39 $(PIGWEED_DIR)/pw_protobuf/pw_protobuf_protos/field_options.proto \ 40 $(PIGWEED_DIR)/pw_protobuf/pw_protobuf_protos/status.proto 41 42# Modifies PYTHONPATH so that python can see all of pigweed's modules used by 43# their protoc plugins 44PW_RPC_GENERATOR_CMD = PYTHONPATH=$$PYTHONPATH:$(PW_RPC_GEN_PATH)/py:$\ 45 $(PIGWEED_DIR)/pw_status/py:$(PIGWEED_DIR)/pw_protobuf/py:$\ 46 $(PIGWEED_DIR)/pw_protobuf_compiler/py $(PYTHON) 47 48$(PW_RPC_GENERATOR_COMPILED_PROTO): $(PW_RPC_GENERATOR_PROTO) 49 @echo " [PW_RPC] $<" 50 $(V)mkdir -p $(PW_RPC_GEN_PATH)/py/pw_rpc/internal 51 $(V)mkdir -p $(PW_RPC_GEN_PATH)/py/pw_protobuf_codegen_protos 52 $(V)mkdir -p $(PW_RPC_GEN_PATH)/py/pw_protobuf_protos 53 $(V)cp -R $(PIGWEED_DIR)/pw_rpc/py/pw_rpc $(PW_RPC_GEN_PATH)/py/ 54 55 $(PROTOC) -I$(PIGWEED_DIR)/pw_protobuf/pw_protobuf_protos \ 56 --experimental_allow_proto3_optional \ 57 --python_out=$(PW_RPC_GEN_PATH)/py/pw_protobuf_protos \ 58 $(PW_PROTOBUF_PROTOS) 59 60 $(PROTOC) -I$(PIGWEED_DIR)/pw_protobuf/pw_protobuf_codegen_protos \ 61 --experimental_allow_proto3_optional \ 62 --python_out=$(PW_RPC_GEN_PATH)/py/pw_protobuf_codegen_protos \ 63 $(PIGWEED_DIR)/pw_protobuf/pw_protobuf_codegen_protos/codegen_options.proto 64 65 $(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) --out-dir=$(PW_RPC_GEN_PATH)/py/pw_rpc/internal \ 66 --compile-dir=$(dir $<) --sources $(PW_RPC_GENERATOR_PROTO) \ 67 --language python 68 69 $(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) \ 70 --plugin-path=$(PIGWEED_DIR)/pw_protobuf/py/pw_protobuf/plugin.py \ 71 --compile-dir=$(dir $<) --sources $(PW_RPC_GENERATOR_PROTO) \ 72 --language pwpb 73 74# Generated PW RPC Files ####################################################### 75 76PW_RPC_GEN_SRCS = $(patsubst %.proto, \ 77 $(PW_RPC_GEN_PATH)/%.pb.c, \ 78 $(PW_RPC_SRCS)) 79 80# Include to-be-generated files 81COMMON_CFLAGS += -I$(PW_RPC_GEN_PATH) 82COMMON_CFLAGS += -I$(PW_RPC_GEN_PATH)/$(PIGWEED_DIR) 83COMMON_CFLAGS += $(addprefix -I$(PW_RPC_GEN_PATH)/, $(abspath $(dir $(PW_RPC_SRCS)))) 84 85COMMON_SRCS += $(PW_RPC_GEN_SRCS) 86 87# PW RPC library ############################################################### 88 89# Pigweed RPC include paths 90COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_assert/public 91COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_bytes/public 92COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_containers/public 93COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_function/public 94COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_log/public 95COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_polyfill/public 96COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_polyfill/public_overrides 97COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_polyfill/standard_library_public 98COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_preprocessor/public 99COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_protobuf/public 100COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_result/public 101COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_rpc/nanopb/public 102COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_rpc/public 103COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_rpc/pwpb/public 104COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_rpc/raw/public 105COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_span/public 106COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_span/public_overrides 107COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_status/public 108COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_stream/public 109COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_string/public 110COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_sync/public 111COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_toolchain/public 112COMMON_CFLAGS += -I$(PIGWEED_DIR)/pw_varint/public 113COMMON_CFLAGS += -I$(PIGWEED_DIR)/third_party/fuchsia/repo/sdk/lib/fit/include 114COMMON_CFLAGS += -I$(PIGWEED_DIR)/third_party/fuchsia/repo/sdk/lib/stdcompat/include 115 116# Pigweed RPC sources 117COMMON_SRCS += $(PIGWEED_DIR)/pw_assert_log/assert_log.cc 118COMMON_SRCS += $(PIGWEED_DIR)/pw_containers/intrusive_list.cc 119COMMON_SRCS += $(PIGWEED_DIR)/pw_protobuf/decoder.cc 120COMMON_SRCS += $(PIGWEED_DIR)/pw_protobuf/encoder.cc 121COMMON_SRCS += $(PIGWEED_DIR)/pw_protobuf/stream_decoder.cc 122COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/call.cc 123COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/channel.cc 124COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/channel_list.cc 125COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/client.cc 126COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/client_call.cc 127COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/endpoint.cc 128COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/packet.cc 129COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/server.cc 130COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/server_call.cc 131COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/service.cc 132COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/nanopb/common.cc 133COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/nanopb/method.cc 134COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/nanopb/server_reader_writer.cc 135COMMON_SRCS += $(PIGWEED_DIR)/pw_rpc/pwpb/server_reader_writer.cc 136COMMON_SRCS += $(PIGWEED_DIR)/pw_stream/memory_stream.cc 137COMMON_SRCS += $(PIGWEED_DIR)/pw_varint/stream.cc 138COMMON_SRCS += $(PIGWEED_DIR)/pw_varint/varint.cc 139 140# NanoPB header includes 141COMMON_CFLAGS += -I$(NANOPB_PREFIX) 142 143COMMON_CFLAGS += -DPW_RPC_USE_GLOBAL_MUTEX=0 144COMMON_CFLAGS += -DPW_RPC_YIELD_MODE=PW_RPC_YIELD_MODE_BUSY_LOOP 145 146# Enable closing a client stream. 147COMMON_CFLAGS += -DPW_RPC_CLIENT_STREAM_END_CALLBACK 148 149 150# Use dynamic channel allocation 151COMMON_CFLAGS += -DPW_RPC_DYNAMIC_ALLOCATION 152COMMON_CFLAGS += -DPW_RPC_DYNAMIC_CONTAINER\(type\)="chre::DynamicVector<type>" 153COMMON_CFLAGS += -DPW_RPC_DYNAMIC_CONTAINER_INCLUDE='"chre/util/dynamic_vector.h"' 154 155# NanoPB sources 156COMMON_SRCS += $(NANOPB_PREFIX)/pb_common.c 157COMMON_SRCS += $(NANOPB_PREFIX)/pb_decode.c 158COMMON_SRCS += $(NANOPB_PREFIX)/pb_encode.c 159 160COMMON_CFLAGS += -DPB_NO_PACKED_STRUCTS=1 161 162# Add CHRE Pigweed util sources since nanoapps should always use these 163COMMON_SRCS += $(PIGWEED_CHRE_UTIL_DIR)/chre_channel_output.cc 164COMMON_SRCS += $(PIGWEED_CHRE_UTIL_DIR)/rpc_client.cc 165COMMON_SRCS += $(PIGWEED_CHRE_UTIL_DIR)/rpc_helper.cc 166COMMON_SRCS += $(PIGWEED_CHRE_UTIL_DIR)/rpc_server.cc 167COMMON_SRCS += $(CHRE_UTIL_DIR)/nanoapp/callbacks.cc 168COMMON_SRCS += $(CHRE_UTIL_DIR)/dynamic_vector_base.cc 169 170# CHRE Pigweed overrides 171COMMON_CFLAGS += -I$(PIGWEED_CHRE_DIR)/pw_log_nanoapp/public_overrides 172COMMON_CFLAGS += -I$(PIGWEED_CHRE_DIR)/pw_assert_nanoapp/public_overrides 173 174# Generate PW RPC headers ###################################################### 175 176$(PW_RPC_GEN_PATH)/%.pb.c \ 177 $(PW_RPC_GEN_PATH)/%.pb.h \ 178 $(PW_RPC_GEN_PATH)/%.rpc.pb.h \ 179 $(PW_RPC_GEN_PATH)/%.raw_rpc.pb.h: %.proto \ 180 %.options \ 181 $(NANOPB_GENERATOR_SRCS) \ 182 $(PW_RPC_GENERATOR_COMPILED_PROTO) 183 @echo " [PW_RPC] $<" 184 $(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) \ 185 --plugin-path=$(NANOPB_PROTOC) \ 186 --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) --compile-dir=$(dir $<) --language nanopb \ 187 --sources $< 188 189 $(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) \ 190 --plugin-path=$(PIGWEED_DIR)/pw_protobuf/py/pw_protobuf/plugin.py \ 191 --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) --compile-dir=$(dir $<) --language pwpb \ 192 --sources $< 193 194 $(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) \ 195 --plugin-path=$(PIGWEED_DIR)/pw_rpc/py/pw_rpc/plugin_nanopb.py \ 196 --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) --compile-dir=$(dir $<) --language nanopb_rpc \ 197 --sources $< 198 199 $(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) \ 200 --plugin-path=$(PIGWEED_DIR)/pw_rpc/py/pw_rpc/plugin_raw.py \ 201 --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) --compile-dir=$(dir $<) --language raw_rpc \ 202 --sources $< 203 204 $(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) \ 205 --plugin-path=$(PIGWEED_DIR)/pw_rpc/py/pw_rpc/plugin_pwpb.py \ 206 --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) --compile-dir=$(dir $<) --language pwpb_rpc \ 207 --sources $< 208 209$(PW_RPC_GEN_PATH)/%.pb.c \ 210 $(PW_RPC_GEN_PATH)/%.pb.h \ 211 $(PW_RPC_GEN_PATH)/%.rpc.pb.h \ 212 $(PW_RPC_GEN_PATH)/%.raw_rpc.pb.h: %.proto \ 213 $(NANOPB_OPTIONS) \ 214 $(NANOPB_GENERATOR_SRCS) \ 215 $(PW_RPC_GENERATOR_COMPILED_PROTO) 216 @echo " [PW_RPC] $<" 217 $(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) \ 218 --plugin-path=$(NANOPB_PROTOC) \ 219 --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) --compile-dir=$(dir $<) --language nanopb \ 220 --sources $< 221 222 $(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) \ 223 --plugin-path=$(PIGWEED_DIR)/pw_protobuf/py/pw_protobuf/plugin.py \ 224 --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) --compile-dir=$(dir $<) --language pwpb \ 225 --sources $< 226 227 $(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) \ 228 --plugin-path=$(PIGWEED_DIR)/pw_rpc/py/pw_rpc/plugin_nanopb.py \ 229 --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) --compile-dir=$(dir $<) --language nanopb_rpc \ 230 --sources $< 231 232 $(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) \ 233 --plugin-path=$(PIGWEED_DIR)/pw_rpc/py/pw_rpc/plugin_raw.py \ 234 --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) --compile-dir=$(dir $<) --language raw_rpc \ 235 --sources $< 236 237 $(V)$(PW_RPC_GENERATOR_CMD) $(PW_RPC_PROTO_GENERATOR) \ 238 --plugin-path=$(PIGWEED_DIR)/pw_rpc/py/pw_rpc/plugin_pwpb.py \ 239 --out-dir=$(PW_RPC_GEN_PATH)/$(dir $<) --compile-dir=$(dir $<) --language pwpb_rpc \ 240 --sources $< 241endif