rosrust
rosrust copied to clipboard
rosrust_msg takes a lot of time on each cargo build while messages definitions have not changed
I have using rosrust
in a catkin workspace and use catkin to build the nodes using these lines in the CMakeList.txt
file, inspired from # 113
set(CARGO_OUTPUT "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}")
add_custom_command(
OUTPUT ${CARGO_OUTPUT}
DEPENDS src/main.rs
COMMAND ${CMAKE_COMMAND} -E echo_append "Building Rust node..."
COMMAND cargo build --release -p ${PROJECT_NAME} --target-dir ${CMAKE_BINARY_DIR}/cargo
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/cargo/release/${PROJECT_NAME} ${CARGO_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E echo "Done."
)
add_custom_target(${PROJECT_NAME}_rust ALL DEPENDS ${CARGO_OUTPUT})
install(PROGRAMS
${CARGO_OUTPUT}
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
But after any change in the main.rs
file, the rust target rosrust_msg
takes a lot of time to build.
With the -vv
flag of cargo build
, I have noticed that the list of files printed with cargo:rerun-if-changed=
includes literally all the files of my ROS workspace, including .git
content for each package.
Commenting the following lines fixed the issue and only the .msg
and .srv
files are listed, which avoids the rosrust_msg
rebuild after any change.
https://github.com/adnanademovic/rosrust/blob/2b75da0aba50f29a0443f761d864265b1a8e5748/rosrust_msg/build.rs#L84-L86
I understand that using rosrust
with catkin is not yet supported but maybe we can only add folders with names srv
and msg
in the list?
From all of my testing of how this trigger works, the rerun trigger needs to include the hierarchy of folders that we're looking at, otherwise adding a new .msg
file won't be registered.
Overly eager rebuilds would be reduced by filtering out folders that we know won't contain message files, like .git
.