Skip to content

Commit 02022e3

Browse files
committed
rust/protobuf: use prost-build to generate Rust protobuf files
We make a small cli tool, used in CMakeLists, similar to nanopb. The generated file lands in the source folder and is committed. I prefer this over generating into the build folder. The advantages are: - Less reliance on the tool to work when you check out and old commit - The rust crates do not depend on CMake in this way, which should make it easier to use standard Rust tooling (though more work is - needed there).
1 parent 5ed4002 commit 02022e3

File tree

6 files changed

+1397
-0
lines changed

6 files changed

+1397
-0
lines changed

messages/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ add_custom_command(
5151
--proto_path=${CMAKE_CURRENT_SOURCE_DIR}
5252
'--nanopb_out=-I${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_CURRENT_BINARY_DIR}'
5353
${PROTO_FILES_ABSOLUTE}
54+
# We build the Rust protobuf files here and put them straight into the crate.
55+
# This way, the crate can be compiled and tested without relying on cmake environment vars.
56+
# Using prost-build the normal way as part of build.rs does not work due to a cargo bug:
57+
# https://github.com/danburkert/prost/issues/344#issuecomment-650721245
58+
COMMAND
59+
${CMAKE_COMMAND} -E env
60+
cargo run --manifest-path=${CMAKE_SOURCE_DIR}/tools/prost-build/Cargo.toml -- --messages-dir=${CMAKE_CURRENT_SOURCE_DIR} --out-dir=${CMAKE_SOURCE_DIR}/src/rust/bitbox02-rust/src/hww/api/
5461
)
5562

5663
add_custom_target(

0 commit comments

Comments
 (0)