Skip to content

Commit a033607

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 a033607

File tree

8 files changed

+1230
-1
lines changed

8 files changed

+1230
-1
lines changed

messages/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ 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 was 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+
OUT_DIR=${CMAKE_SOURCE_DIR}/src/rust/bitbox02-rust/src/hww/api/
61+
MESSAGES_DIR=${CMAKE_CURRENT_SOURCE_DIR}
62+
cargo run --manifest-path=${CMAKE_SOURCE_DIR}/tools/prost-build/Cargo.toml
5463
)
5564

5665
add_custom_target(

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ foreach(type ${RUST_LIBS})
484484
# see src/rust/bitbox02-rust-c/src/lib.rs.
485485
# https://github.com/rust-lang/rust/issues/66740
486486
RUSTC_BOOTSTRAP=1
487-
${CARGO} build -v --features target-${type} --target-dir ${RUST_BINARY_DIR} ${RUST_CARGO_FLAG} ${RUST_TARGET_ARCH_ARG}
487+
${CARGO} build --features target-${type} --target-dir ${RUST_BINARY_DIR} ${RUST_CARGO_FLAG} ${RUST_TARGET_ARCH_ARG}
488488
COMMAND
489489
# Rust packages stdlib functions which we must remove/weaken on the arm target
490490
# Currently the removed symbols only clash in device-tests for some reason. Without this command, compiling device tests would result in errors like:

0 commit comments

Comments
 (0)