Skip to content

Commit

Permalink
compile .proto files with protoc so gp2040ce-binary-tools doesn't hav…
Browse files Browse the repository at this point in the history
…e to

this hopefully gets around the weird bug with Windows stuff that seems
to be caused by gRPC and/or dynamically compiling the files as part of
gp2040ce-binary-tools invocations
  • Loading branch information
bsstephan committed Feb 10, 2025
1 parent ac6d090 commit 2397751
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions compile_proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function (compile_proto)
)

set(NANOPB_GENERATOR ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/nanopb_generator.py)
set(PYTHON_GENERATOR ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/protoc)
set(PROTO_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto)
set(PROTO_OUTPUT_DIR ${PROTO_OUTPUT_DIR} PARENT_SCOPE)

Expand All @@ -42,4 +43,27 @@ function (compile_proto)
OUTPUT ${PROTO_OUTPUT_DIR}/config.pb.c ${PROTO_OUTPUT_DIR}/config.pb.h ${PROTO_OUTPUT_DIR}/enums.pb.c ${PROTO_OUTPUT_DIR}/enums.pb.h
COMMENT "Compiling enums.proto and config.proto"
)

add_custom_command(
DEPENDS ${VENV_FILE} ${PYTHON_GENERATOR} ${CMAKE_SOURCE_DIR}/proto/enums.proto ${CMAKE_SOURCE_DIR}/proto/config.proto ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto/nanopb.proto
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROTO_OUTPUT_DIR}
COMMAND ${VENV_BIN_DIR}/python ${PYTHON_GENERATOR}
--python_out ${PROTO_OUTPUT_DIR}
-I ${CMAKE_SOURCE_DIR}/proto
-I ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto
${CMAKE_SOURCE_DIR}/proto/enums.proto
COMMAND ${VENV_BIN_DIR}/python ${PYTHON_GENERATOR}
--python_out ${PROTO_OUTPUT_DIR}
-I ${CMAKE_SOURCE_DIR}/proto
-I ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto
${CMAKE_SOURCE_DIR}/proto/config.proto
COMMAND ${VENV_BIN_DIR}/python ${PYTHON_GENERATOR}
--python_out ${PROTO_OUTPUT_DIR}
-I ${CMAKE_SOURCE_DIR}/proto
-I ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto
${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto/nanopb.proto
OUTPUT ${PROTO_OUTPUT_DIR}/config_pb2.py ${PROTO_OUTPUT_DIR}/enums_pb2.py ${PROTO_OUTPUT_DIR}/nanopb_pb2.py
COMMENT "Compiling config_pb2.py, enums_pb2.py, and nanopb_pb2.py Python modules"
)
endfunction()
2 changes: 1 addition & 1 deletion patch_board_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function (patch_board_config)

add_custom_target(
PatchBoardConfig ALL
DEPENDS ${PROJECT_NAME}
DEPENDS ${PROJECT_NAME} ${PROTO_OUTPUT_DIR}/config_pb2.py ${PROTO_OUTPUT_DIR}/enums_pb2.py ${PROTO_OUTPUT_DIR}/nanopb_pb2.py
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
# something in the protobuf compiler doesn't like the multiple paths,
# so we'll copy all the .proto files into one location
Expand Down

0 comments on commit 2397751

Please sign in to comment.