POC of using cargo package for installation #68
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR targets #67 and illustrates the idea I have been toying with about using
cargo packageto install libraries throughcolcon-cargo.It's just a POC to facilitate discussion, ideally we can at least be smarter with caching / remove duplicated work and rework install folder structures.
The proposed implementation in #67 uses
cargo package --listto get a list of files that would be installed then uses the output to copy files from the package's source directory into the install space.This however, is not sufficient for packages that are in a cargo workspace, since
cargo packageactually performs a series of operations to theCargo.tomlto, for example, remove relative path dependencies, resolve workspace dependencies etc. (point 1 and some of point 2 here).This shows in the fact that what we actually install in #67 doesn't compile if applied to a more complex package.
I came up with a "simple" test case for both #67 and this PR to show the difference.
Setup
Create a workspace and bring a custom tokio (where I just added a public
hello_worldfunction) and a POC crate that tests it (has a library and an executable that call the new tokio function).mkdir -p tokio_ws/src cd tokio_ws/src git clone https://github.com/luca-della-vedova/tokio git clone https://github.com/luca-della-vedova/cargo_custom_tokio_packageTest with #67
Remove
dev_dependsfrom here as done in this PR to avoid circular dependency errorsSince the tokio Cargo.toml has one of these "workspace inheritances", the build will actually fail, making the crate effectively non functional:
The snippet is preserved when copying the file and cannot be resolved since the file is copied to a different location and its workspace's
Cargo.tomlis not in its parent folder anymore.Test with this branch
You will see that the package builds correctly, meaning the workspace migration was done by Cargo.
Inspecting the installed Cargo.toml, we can see that the linter configuration was migrated to a standalone configuration that does not reference the workspace's
Cargo.toml:Additionally, if now you build the sample package:
It will build successfully and running it will work, meaning the hardcoded patch correctly resolved to a tokio with the custom function:
Conclusion
cargo packagedoes a lot more for non-toy projects. I demonstrated this with tokio but most major projects out there have workspace dependencies that would make them non functional (i.e. serde).colcon-ros-cargo/ message generation. Patching is hardcoded but left as future work (perhaps through pallet patcher?)cargo packagealways builds a package even if it was unchanged, since I see that install times are quite significant even when no changes are made.