Firstly, much thanks to the developers and maintainers for getting this plugin started! I'm very excited by the prospect of using Rust in ROS2, and more generally having a nice automated workspace overlay tool for Rust.
After trying out the tool, I noticed that Rust library packages seem to explicitly not be supported. Trying to include a library package, I get the following error message:
error: no packages found with binaries or examples
I assume this is an intentional limitation, since it currently seems quite difficult to have Cargo redirect to a local dependency without modifying the Cargo.toml
of the package that needs to use the local dependency.
While researching how we might be able to make libraries and dependency overlays work I learned about Cargo config files which (will) offer a patch-in-config feature. This allows a [patch]
section to be put into a .cargo/config.toml
file, and those dependency patches will be applied to every package that belongs to the workspace that the config file is provided for. This feature is currently in the beta
channel (version 1.56), which looks like it will move to stable
on Oct 21.
I just did a quick manually set-up test of this with the following structure (relative to the root of a hypothetical colcon workspace):
.cargo/config.toml
:
[patch.crates-io]
hello_lib = {path = "src/hello_lib"}
src/hello_lib/Cargo.toml
:
[package]
name = "hello_lib"
version = "0.1.0"
edition = "2018"
src/hello_lib/src/lib.rs
:
pub fn say_hello() {
println!("Hello, library!");
}
src/hello_app/Cargo.toml
:
[package]
name = "hello_app"
version = "0.1.0"
edition = "2018"
[dependencies]
hello_lib = "*"
src/hello_app/main.rs
:
use hello_lib;
fn main() {
hello_lib::say_hello();
}
Then run the following command from src/hello_app
:
You should find that the hello_app
successfully builds, runs, and prints out Hello, library!
. (Make sure you have run rustup install beta
and rustup update
before running the command.)
I think this would be a solid strategy for fully integrating Cargo into colcon. The documentation for this feature explicitly mentions that the feature is intended for external build tools (such as colcon):
Patching through cargo configuration files is generally only appropriate when the patch section is automatically generated by an external build tool.
Does anyone have thoughts on this? It's exciting to think that we might be able to have complete colcon+cargo integration in just a few weeks when this feature goes stable.