rosrust icon indicating copy to clipboard operation
rosrust copied to clipboard

Integrate with the catkin build system

Open adnanademovic opened this issue 7 years ago • 13 comments

It would be greatly useful to build upon catkin_make invocations, and to be callable from rosrun <package> <node>. The latter would by extension allow running from launchfiles.

The current solution is creating shell scripts that run cargo run ... for the binary in question, and putting them in the /scripts subfolder. That's similar to how python scripts are already being run.

This isn't very urgent, since this hacky solution works for now.

adnanademovic avatar Dec 26 '17 01:12 adnanademovic

Related: #113

I don't think we'll be able to do anything better than hacky unless Catkin learns about Rust.

neachdainn avatar Jul 03 '19 23:07 neachdainn

I did have an idea that might be viable: we could create a cargo-catkin that implements all of the changes specified in #113. It could set up the .cargo/config file and then, for each crate in the workspace, set up a simple CMakeLists.txt and package.xml base on the metadata available in the crate's Cargo.toml. It wouldn't be a perfect solution but it might be the best possible way to integrate without having to make modifications to Catkin itself.

I'm fairly busy at the moment, but this is definitely on my list of things I would like to do.

neachdainn avatar Jul 07 '19 22:07 neachdainn

I think it is great idea!

OTL avatar Jul 08 '19 05:07 OTL

I'm fairly busy at the moment, but this is definitely on my list of things I would like to do.

Hi, I'm currently working on a ROS project involving some rust code... Would be happy to help you develop this feature.

pmirabel avatar Jul 21 '20 17:07 pmirabel

While this is still on my list of projects I would like to eventually address, I have since moved on to a project that currently does not involve ROS. If I do find time to work on this, I'll probably try to introduce a level of Rust support in CMake (maybe based on the Devolutions attempt) as that solves this issue without being limited to ROS.

If you want to work on this yourself, I'd be more than happy to help with any questions you have.

EDIT: In case anyone stumbles on this before I get around to it, this file is a good starting point for adding a new language to CMake.

neachdainn avatar Jul 21 '20 17:07 neachdainn

I will let you know when I get back to this subject, I have to successfully compile a rust node first... and stuck with some novice comile errors.

pmirabel avatar Aug 17 '20 09:08 pmirabel

This might also be a potential starting point: https://github.com/AndrewGaspar/corrosion

kjeremy avatar Sep 30 '20 20:09 kjeremy

This might also be a potential starting point: https://github.com/AndrewGaspar/corrosion

I have tried that out for a small project and it's absolutely delightful so far. If #112 is solved, I think that would put this crate in a very good place.

neachdainn avatar Oct 02 '20 23:10 neachdainn

It looks like corrosion has a minimum cmake version of 3.12 while melodic has a much lower minimum cmake.

kjeremy avatar Oct 07 '20 14:10 kjeremy

Upgrading CMake is easy and is moot without this crate declaring a MSRV.

neachdainn avatar Oct 07 '20 15:10 neachdainn

I accidentally posted this in #113 instead of here:

After adding the cmake ppa and updating my cmake I was able to build/install corrosion. Then I could do:

cmake_minimum_required(VERSION 3.0.2)
project(publisher_node)

find_package(catkin REQUIRED)
find_package(Corrosion REQUIRED)

catkin_package()

corrosion_import_crate(MANIFEST_PATH Cargo.toml)

corrosion_install(TARGETS ${PROJECT_NAME}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

This builds but did not install my publisher_node into devel. I can't figure out how to get rosrun to see my package until I build with catkin_make install.

kjeremy avatar Oct 07 '20 20:10 kjeremy

@kjeremy Thank you for that cheat sheet, it works very well for me using ROS Noetic and the catkin command (not catkin_make). Even works with a workspace containing multiple binaries, I just change the corrosion_install() line to:

corrosion_install(TARGETS binary1 binary2
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

icefoxen avatar Nov 23 '21 20:11 icefoxen

My CMakeLists looks like this and seems to work without a workspace:

cmake_minimum_required(VERSION 3.0)
project(<package>)

find_package(catkin REQUIRED)
catkin_package()

add_custom_target(<package>
   ALL
   COMMAND cargo build --release --manifest-path ${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml --target-dir ${CMAKE_BINARY_DIR}/cargo
   COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/cargo/release/<package> ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/<package>
   COMMENT "Building <package>!!!"
)

ModProg avatar Apr 30 '23 15:04 ModProg