fix(generator): do not register generated crates in the rust_packages - #37
Open
azerupi wants to merge 1 commit into
Open
fix(generator): do not register generated crates in the rust_packages#37azerupi wants to merge 1 commit into
azerupi wants to merge 1 commit into
Conversation
… index Generated interface crates opt into `ros-env` by default since ros2-rust#21 (`[package.metadata.ros-env] include = true` in the Cargo.toml template), which means they are `include!()`d from the source installed to `share/<pkg>/rust` rather than resolved as Cargo dependencies. The `rust_packages` ament index resource exists only so that `colcon-ros-cargo` can emit a `[patch.crates-io.<pkg>]` entry for packages that *are* real Cargo dependencies. Registering generated crates therefore produces a patch that nothing in the dependency graph uses, and Cargo records those as `[[patch.unused]]` in every consumer's `Cargo.lock`. That makes the lockfile depend on whichever interface packages happen to be present on the prefix: locks differ between machines and `--locked` builds fail on any extra patched crate. Stop registering the resource. The `install(DIRECTORY ...)` of the crate source is kept, since that is what `ros-env` reads from `AMENT_PREFIX_PATH`. This is the generator-side counterpart of cargo-ament-build PR ros2-rust#35, which already skips the same marker for `ament_cargo` packages that opt into `ros-env`. Verified with a two-package workspace (an `ament_cmake` interface package plus an `ament_cargo` node consuming it through `ros-env`) built with cargo-ament-build 0.1.11 and colcon-ros-cargo 0.2.0. Before the change the marker file, the `[patch.crates-io]` entry and a `[[patch.unused]]` block for the interface package are all present; after it all three are gone and the node still compiles and links. Note this is a behaviour change for consumers that still declare generated interface crates as direct Cargo dependencies: those relied on `colcon-ros-cargo` patching them in and should migrate to `ros-env`.
Contributor
|
Thank you for noticing this and putting up the fix @azerupi! Regarding the roll out impact, I believe this is inevitable unfortunately. End users can buy time by pinning to an older We will need to make sure a new version of rclrs is released as well around this time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The
rust_packagesament index resource exists so thatcolcon-ros-cargocan inject a[patch.crates-io.<pkg>]entry pointing at an installed crate's source. Since #21, generated interface crates useros-envby adding[package.metadata.ros-env] include = trueinresource/Cargo.toml. Such crates should be used throughros-envinstead of being added as a cargo dependency and patched.Creating the marker file anyway means
colcon-ros-cargoemits a patch that nothing uses, and Cargo records every unused patch as a[[patch.unused]]block in the consumer'sCargo.lock. The lockfile therefore depends on which interface packages happen to be present on the prefix, not on what the crate actually depends on. The consequence is that locks differ between machines, workspaces and branches and therefore result in constant merge conflicts. This is the issue that I reported in colcon/colcon-ros-cargo#37cargo-ament-buildPR #35 already fixed exactly this forament_cargopackages, it skips therust_packagesmarker when the manifest opts intoros-env. But interface packages areament_cmakeand their marker is written by this repo's CMake, unconditionallyReproduction
Here is a minimal reproduction to test. Create a a two-package workspace.
src/mre_msgswith
<build_type>ament_cmake</build_type>,<buildtool_depend>rosidl_default_generators</buildtool_depend>and<member_of_group>rosidl_interface_packages</member_of_group>inpackage.xml.src/mre_nodepackage.xmldeclares<build_type>ament_cargo</build_type>and<depend>mre_msgs</depend>.Then:
$ colcon build --packages-up-to mre_nodemre_msgsis not a Cargo dependency of anything, yet all three of these appear:install/mre_msgs/share/ament_index/resource_index/rust_packages/mre_msgs.cargo/config.toml[[patch.unused]]in theCargo.lockfileFix
We stop generating the marker file. We don't need to do this conditionally because
resource/Cargo.toml.ememits theros-envopt-in unconditionally.Rollout impact
When this generator change reaches the ROS buildfarm, any user of rclrs that still declares a generated interface crate as a direct Cargo dependency (
std_msgs = "*",sensor_msgs = "*", …) and relies oncolcon-ros-cargopatching instead of using rosenv will start to see their builds fail after updating their ROS apt packages.