Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Rust libraries in colcon workspace #17

Open
mxgrey opened this issue Oct 4, 2021 · 4 comments
Open

Support for Rust libraries in colcon workspace #17

mxgrey opened this issue Oct 4, 2021 · 4 comments

Comments

@mxgrey
Copy link
Contributor

mxgrey commented Oct 4, 2021

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:

cargo +beta run

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.

@allsey87
Copy link

Hi @mxgrey, I need Cargo library support and will look into this/work towards creating a PR this week. @esteve @bergercookie do you have time at the moment to review/merge a PR? I only ask since this thread was left unanswered and there hasn't been much activity on this repository.

@esteve
Copy link
Contributor

esteve commented Dec 20, 2021

@allsey87 that'd be great, thank you so much! Yeah, I can review your PR and merge it.

@mxgrey
Copy link
Contributor Author

mxgrey commented Dec 20, 2021

We may want to coordinate effort with @nnmm . I believe he was thinking about incorporating these concepts into his PRs.

@nnmm
Copy link
Contributor

nnmm commented Feb 11, 2022

See the colcon/colcon-ros-cargo repository (currently still in a PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants