fix: respect AMENT_PREFIX_PATH precedence when resolving Rust packages#41
Open
azerupi wants to merge 1 commit into
Open
fix: respect AMENT_PREFIX_PATH precedence when resolving Rust packages#41azerupi wants to merge 1 commit into
AMENT_PREFIX_PATH precedence when resolving Rust packages#41azerupi wants to merge 1 commit into
Conversation
find_installed_cargo_packages iterated AMENT_PREFIX_PATH and overwrote prefix_for_package[pkg] = prefix on every hit, so the LAST prefix containing a package won. AMENT_PREFIX_PATH is conventionally ordered from highest to lowest priority (like PATH), and an overlay sourced on top of an underlay puts the overlay prefix first. Last-wins meant the underlay (e.g. /opt/ros/<distro>) silently overrode a locally rebuilt overlay of the same package in the .cargo/config.toml that downstream Rust packages then link against. Use dict.setdefault so the first prefix that contains a given Rust package wins, matching ament_cmake / CMAKE_PREFIX_PATH semantics. Adds two unit tests: - test_find_installed_cargo_packages_overlay_first_wins: an overlay listed before an underlay must take precedence for shared package names; non-overlapping packages still resolve from whichever prefix contains them. - test_find_installed_cargo_packages_empty_ament_prefix_path: an unset AMENT_PREFIX_PATH returns an empty mapping without raising. This was found while debugging a perf change in ros2-rust/ros2_rust#628 where a locally-rebuilt std_msgs was silently bypassed in favor of the distro-installed one, leading to end-to-end benchmarks measuring the wrong code.
Collaborator
|
@cottsay changes look good to me, but it'd be great if you can have a look too. Thanks! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #41 +/- ##
=======================================
Coverage ? 88.29%
=======================================
Files ? 5
Lines ? 205
Branches ? 17
=======================================
Hits ? 181
Misses ? 20
Partials ? 4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
find_installed_cargo_packagesiteratedAMENT_PREFIX_PATHand overwroteprefix_for_package[pkg] = prefixon every hit, so the last prefix containing a package won. SinceAMENT_PREFIX_PATHis ordered from highest to lowest priority (likePATH) and an overlay sourced on top of an underlay puts the overlay prefix first, last-wins meant the underlay silently overrode a locally rebuilt overlay of the same package in the generated.cargo/config.toml.Switched to
dict.setdefaultso the first prefix that contains a given Rust package wins, matchingament_cmake/CMAKE_PREFIX_PATHsemantics.Why this matters
Without the fix, anyone who locally rebuilds a Rust message crate (e.g.
std_msgs) while overlaying a packaged ROS distro gets downstream Rust binaries linked against the distro.rlib, not the local one. The build succeeds, code runs, only behavior is silently wrong.This was found while debugging a perf change in ros2-rust/ros2_rust#628 where a locally-rebuilt
std_msgswas silently bypassed in favor of the distro-installed one, leading to benchmarks measuring the wrong code.