-
Notifications
You must be signed in to change notification settings - Fork 11
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
Feature/examples repo #43
Changes from 10 commits
94932b4
7982433
6d2db95
a07dc97
b544693
da645f0
0f3fb49
ab75189
715addf
f5b4141
3faf693
63d7c24
5fa846f
8e88efe
fc7278f
9253ca9
c1b897e
d8ead2d
7c7df83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
examples |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../.bazelrc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
alias( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these aliases to ensure they are built as I don't see what in the examples depends on them. If so, could be worth adding a comment as to why they're here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's more for convenience, referenced some of them in the readme for the chatter examples. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added docs. |
||
name = "roscore", | ||
actual = "@rules_ros//third_party/ros/roslaunch:roscore", | ||
) | ||
|
||
alias( | ||
name = "rosgraph", | ||
actual = "@ros_comm//:rosgraph", | ||
) | ||
|
||
alias( | ||
name = "rosparam", | ||
actual = "@ros_comm//:rosparam", | ||
) | ||
|
||
alias( | ||
name = "rosbag_record", | ||
actual = "@ros_comm//:rosbag_record", | ||
) | ||
|
||
alias( | ||
name = "rosbag_play", | ||
actual = "@ros_comm//:rosbag_play", | ||
) | ||
|
||
alias( | ||
name = "rosservice", | ||
actual = "@rules_ros//third_party/ros/rosservice", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module(name = "rules_ros_examples") | ||
|
||
bazel_dep(name = "rules_python", version = "0.34.0") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you now specify your own python toolchain, wouldn't it be possible to use a different python version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It won't let me reply to the above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it help if we specify a toolchain here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I add the following to examples/MODULE.bazel: python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
is_default = True,
python_version = "3.10",
) and remove the config flag from .bazelrc: that works for the examples repo but I get:
IMO, the flag in .bazelrc is a cleaner solution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But isn't this what we want? Being able to override the Python toolchain used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't have time to investigate how this would work. If you have some time, give it a shot. But, yes, it would be nice if toolchain override could work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok fine with me. Let's try that and once it is merged I will try to update in our codebase and report back if there are any errors. |
||
|
||
# This import is relevant for these examples and this (rules_ros) repository. | ||
bazel_dep(name = "rules_ros") | ||
local_path_override( | ||
module_name = "rules_ros", | ||
path = "..", | ||
) | ||
|
||
# In a normal workflow, you would typically import rules_ros2 into your | ||
mvukov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# (mono)repo as follows: | ||
# bazel_dep(name = "rules_ros") | ||
# archive_override( | ||
# module_name = "rules_ros", | ||
# integrity = "sha256-<integrity sum of the .tar.gz archive below>", | ||
# strip_prefix = "rules_ros-<git commit SHA>", | ||
# urls = "https://github.com/mvukov/rules_ros/archive/<git commit SHA>.tar.gz" | ||
# ) | ||
|
||
non_module_ros_repositories = use_extension("@rules_ros//ros:extensions.bzl", "non_module_dependencies") | ||
use_repo( | ||
non_module_ros_repositories, | ||
"console_bridge", | ||
"orocos_kdl", | ||
"ros_actionlib", | ||
"ros_comm", | ||
"ros_comm_msgs", | ||
"ros_common_msgs", | ||
"ros_dynamic_reconfigure", | ||
"ros_gencpp", | ||
"ros_genmsg", | ||
"ros_genpy", | ||
"ros_geometry2", | ||
"ros_ros", | ||
"ros_std_msgs", | ||
"rosconsole", | ||
"roscpp_core", | ||
"tinyxml", | ||
"urdfdom", | ||
"urdfdom_headers", | ||
) | ||
|
||
bazel_dep(name = "rules_boost") | ||
archive_override( | ||
module_name = "rules_boost", | ||
integrity = "sha256-I1iTdF3qckTmDRab+0yjA37Iya9AOGvEGJVoPtfpADM=", | ||
strip_prefix = "rules_boost-42d8155d8f20a1aee8ee20b7903a495bdfb9befd", | ||
urls = "https://github.com/nelhage/rules_boost/archive/42d8155d8f20a1aee8ee20b7903a495bdfb9befd.zip", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Examples for rules_ros | ||
|
||
This folder provides some examples and guidelines on how you can use this repo | ||
in your very own (mono)repo. It's important to note here that this folder is | ||
a yet another Bazel module (it has a MODULE.bazel file). Please take a look at | ||
the module file to get an idea how to set up yourself. | ||
|
||
Besides setting up your module file, please make sure you copy the `.bazelrc` | ||
file as well to your monorepo -- or at least adjust your own using the provided | ||
one. | ||
|
||
Before you build/run/test any of the targets in this folder, please make sure | ||
your terminal is in this folder, or in a subfolder, and not in the root | ||
of the repo. | ||
|
||
You can start with a simple [chatter](chatter) example. | ||
|
||
In `dishwasher` folder you can find another example that demonstrates | ||
defining and usage of ROS actions (and actionlib). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# A chatter example | ||
|
||
Let's begin with starting `roscore`: | ||
|
||
```sh | ||
bazel run //:roscore | ||
``` | ||
|
||
In a separate terminal, let's start a (C++) talker node: | ||
|
||
```sh | ||
bazel run //chatter:talker | ||
``` | ||
|
||
This single command will compile and run the talker node. | ||
|
||
In a yet another terminal we can start a listener node: | ||
|
||
```sh | ||
bazel run //chatter:listener # C++ version or | ||
bazel run //chatter:py_listener # Python version | ||
``` | ||
|
||
Rosbag recording & playing works as well: | ||
|
||
```sh | ||
bazel run //:rosbag_record -- /chatter -o /tmp/foo.bag # to record a bag or | ||
bazel run //:rosbag_play -- /tmp/foo_<timestamp>.bag # to play a bag | ||
``` | ||
|
||
`rostopic`, tied to this example (see `BUILD.bazel` for more info) can be used as | ||
|
||
```sh | ||
bazel run //chatter:rostopic -- echo /chatter | ||
``` | ||
|
||
Not too shabby. | ||
|
||
Next, let's start a deployment with the talker and the listener nodes. You can | ||
stop the nodes you started with the above commands. Now execute | ||
|
||
```sh | ||
bazel run //chatter:chatter | ||
``` | ||
|
||
This command will build the necessary nodes and launch them. This is similar | ||
to executing good-ol' `roslaunch`, but, running the chatter `ros_launch` target | ||
using Bazel ensures all necessary dependencies are (re-)built. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<launch> | ||
<node type="examples/chatter/talker" name="talker" /> | ||
<node type="examples/chatter/listener" name="listener" output="screen" /> | ||
<node type="chatter/talker" name="talker" /> | ||
<node type="chatter/listener" name="listener" output="screen" /> | ||
</launch> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add the
default = True
attribute to the python toolchain in theMODULE
file, then you don't need this, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't change the toolchain in rules_ros. The flag isn't needed in rules_ros but it's needed in the examples repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this required in the examples repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise Bazel can't figure out that pip deps are indeed for Python 3.10 toolchain. E.g. I get:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is required for the examples repo only, would it make sense to have a
.bazelrc
for the examples repo only to avoid this for the main repo?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to maintain two .bazelrc files, that's why I synmlink-ed the rules_ros2 repo one to the examples repo. The flag doesn't harm the main repo.