Skip to content

Add xacro support to bazel_ros2_rules - #422

Merged
frneer merged 3 commits into
RobotLocomotion:mainfrom
julianadrianheine:julianadrianheine/add_xacro_support
Apr 22, 2026
Merged

Add xacro support to bazel_ros2_rules#422
frneer merged 3 commits into
RobotLocomotion:mainfrom
julianadrianheine:julianadrianheine/add_xacro_support

Conversation

@julianadrianheine

@julianadrianheine julianadrianheine commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR introduces a macro ros_xacro that allows generating URDF/SDF artifacts. The implementation was based on #420

Summary

  • Adds bazel_ros2_rules/lib/private/xacro.bzl with a ros_xacro macro that transforms a .urdf.xacro source file into a .urdf output file at build time
  • Registers xacro.bzl in COMMON_FILES_MANIFEST so it is distributed as @ros2//:xacro.bzl
  • Adds ros2_example_xacro as a worked example and test for the new rule

Implementation notes

ros_xacro follows the same pattern as ros_launch: it wraps a generated runner script in ros_py_binary, whose dload shim sets up AMENT_PREFIX_PATH (including prefixes for any user-defined packages) before executing the system @ros2//:xacro binary. Resolved runfiles paths are always absolute, which is required because xacro's $(find <pkg>) expansion joins non-absolute paths with the parent file's directory.

Local packages are declared inline via the ros_packages dict, mapping a ROS package name to its source files. The macro creates an ament_index_share_files target for each entry internally, deriving strip_prefix automatically from native.package_name() so the user never has to compute it.

The BUILD file usage is minimal:

# BUILD.bazel
load("@bazel_ros2_rules//lib:xacro.bzl", "ros_xacro")

ros_xacro(
    name = "example",
    src = "example.urdf.xacro",
    ros_packages = {
        "my_robot": glob(["urdf/**"]),
    },
    data = [macros.xacro],
    xacro_args = ["sim:=false"],
)

This change is Reviewable

@julianadrianheine
julianadrianheine force-pushed the julianadrianheine/add_xacro_support branch 2 times, most recently from 0041bf0 to ca521a8 Compare April 17, 2026 20:28
@julianadrianheine
julianadrianheine marked this pull request as ready for review April 20, 2026 12:03
@julianadrianheine
julianadrianheine force-pushed the julianadrianheine/add_xacro_support branch 4 times, most recently from 43610a9 to 9b927d9 Compare April 20, 2026 13:04
@frneer frneer linked an issue Apr 20, 2026 that may be closed by this pull request
@frneer
frneer force-pushed the julianadrianheine/add_xacro_support branch from 9b927d9 to f092114 Compare April 21, 2026 18:49
@frneer frneer self-assigned this Apr 22, 2026

@frneer frneer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+a:@frneer

@frneer partially reviewed 9 files and made 1 comment.
Reviewable status: 8 of 12 files reviewed, all discussions resolved.

@frneer frneer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@frneer made 1 comment.
Reviewable status: 8 of 12 files reviewed, all discussions resolved.

@frneer
frneer merged commit 6b3776f into RobotLocomotion:main Apr 22, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add xacro support

2 participants