From 94932b40e62318fd7117ec5fe04e4748d907bccd Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Thu, 8 Aug 2024 00:08:11 +0200 Subject: [PATCH 01/17] WIP Work out examples as a separate repo --- .bazelignore | 1 + MODULE.bazel | 10 ++--- examples/.bazelrc | 1 + examples/MODULE.bazel | 45 +++++++++++++++++++ examples/README.md | 3 ++ examples/chatter/BUILD.bazel | 14 +++--- examples/chatter/chatter.launch | 4 +- examples/chatter/talker_tests.launch | 6 +-- examples/dishwasher/BUILD.bazel | 6 +-- examples/dishwasher/dishwasher.launch | 4 +- examples/dynamic_reconfiguration/BUILD.bazel | 6 +-- .../dynamic_reconfiguration.launch | 4 +- ros/BUILD.bazel | 2 +- ros/dynamic_reconfigure.bzl | 2 +- ros/launch.bzl | 4 +- ros/repositories/actionlib.BUILD.bazel | 2 +- ros/repositories/common_msgs.BUILD.bazel | 6 +-- .../dynamic_reconfigure.BUILD.bazel | 4 +- ros/repositories/geometry2.BUILD.bazel | 4 +- ros/repositories/orocos_kdl.BUILD.bazel | 4 +- ros/repositories/repositories.bzl | 36 +++++++-------- ros/repositories/ros_comm.BUILD.bazel | 16 +++---- ros/repositories/ros_comm_msgs.BUILD.bazel | 2 +- ros/repositories/rosconsole.BUILD.bazel | 2 +- ros/repositories/roscpp_core.BUILD.bazel | 2 +- ros/repositories/std_msgs.BUILD.bazel | 4 +- ros/repositories/urdfdom.BUILD.bazel | 2 +- ros/test.bzl | 4 +- third_party/ros/rostest/BUILD.bazel | 4 +- 29 files changed, 125 insertions(+), 79 deletions(-) create mode 100644 .bazelignore create mode 120000 examples/.bazelrc create mode 100644 examples/MODULE.bazel create mode 100644 examples/README.md diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 0000000..1e107f5 --- /dev/null +++ b/.bazelignore @@ -0,0 +1 @@ +examples diff --git a/MODULE.bazel b/MODULE.bazel index 50a2510..5fc7587 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,7 +1,4 @@ -module( - name = "rules_ros", - repo_name = "com_github_mvukov_rules_ros", -) +module(name = "rules_ros") bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "bzip2", version = "1.0.8.bcr.1") @@ -13,8 +10,7 @@ bazel_dep(name = "lz4", version = "1.9.4") bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "rules_cc", version = "0.0.9") bazel_dep(name = "rules_foreign_cc", version = "0.11.1") - -bazel_dep(name = "rules_python", version = "0.34.0", dev_dependency = True) +bazel_dep(name = "rules_python", version = "0.34.0") non_module_ros_repositories = use_extension("//ros:extensions.bzl", "non_module_dependencies") use_repo( @@ -64,6 +60,6 @@ pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") pip.parse( hub_name = "rules_ros_pip_deps", python_version = "3.10", - requirements_lock = "@com_github_mvukov_rules_ros//:requirements_lock.txt", + requirements_lock = "@rules_ros//:requirements_lock.txt", ) use_repo(pip, "rules_ros_pip_deps") diff --git a/examples/.bazelrc b/examples/.bazelrc new file mode 120000 index 0000000..adb6198 --- /dev/null +++ b/examples/.bazelrc @@ -0,0 +1 @@ +../.bazelrc \ No newline at end of file diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel new file mode 100644 index 0000000..6dfb45d --- /dev/null +++ b/examples/MODULE.bazel @@ -0,0 +1,45 @@ +module(name = "rules_ros_examples") + +bazel_dep(name = "rules_python", version = "0.34.0") +bazel_dep(name = "rules_ros") +local_path_override( + module_name = "rules_ros", + path = "..", +) + +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", +) + +non_module_boost_repositories = use_extension("@rules_boost//:boost/repositories.bzl", "non_module_dependencies") +use_repo( + non_module_boost_repositories, + "boost", +) diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..333d03a --- /dev/null +++ b/examples/README.md @@ -0,0 +1,3 @@ +``` +bazel test //... --@rules_python//python/config_settings:python_version=3.10 +``` diff --git a/examples/chatter/BUILD.bazel b/examples/chatter/BUILD.bazel index ff0ff39..d60919f 100644 --- a/examples/chatter/BUILD.bazel +++ b/examples/chatter/BUILD.bazel @@ -8,16 +8,16 @@ """ load("@rules_python//python:defs.bzl", "py_binary") -load("//ros:cc_defs.bzl", "cc_ros_binary") +load("@rules_ros//ros:cc_defs.bzl", "cc_ros_binary") load( - "//ros:interfaces.bzl", + "@rules_ros//ros:interfaces.bzl", "cc_ros_interface_library", "py_ros_interface_library", "ros_interface_library", ) -load("//ros:launch.bzl", "ros_launch") -load("//ros:test.bzl", "ros_test") -load("//ros:topic.bzl", "ros_topic") +load("@rules_ros//ros:launch.bzl", "ros_launch") +load("@rules_ros//ros:test.bzl", "ros_test") +load("@rules_ros//ros:topic.bzl", "ros_topic") # Handling of ROS messages & services resembles to some extent Bazel's rules for # handling protobuf messages (e.g. proto_library and cc_proto_library). @@ -61,8 +61,8 @@ ros_test( launch_file = "talker_tests.launch", nodes = [ ":talker", - "//third_party/ros/rostest:advertisetest", - "//third_party/ros/rostest:publishtest", + "@rules_ros//third_party/ros/rostest:advertisetest", + "@rules_ros//third_party/ros/rostest:publishtest", ], ) diff --git a/examples/chatter/chatter.launch b/examples/chatter/chatter.launch index 22e090e..a61c088 100644 --- a/examples/chatter/chatter.launch +++ b/examples/chatter/chatter.launch @@ -1,4 +1,4 @@ - - + + diff --git a/examples/chatter/talker_tests.launch b/examples/chatter/talker_tests.launch index e3199b3..aaccd50 100644 --- a/examples/chatter/talker_tests.launch +++ b/examples/chatter/talker_tests.launch @@ -1,9 +1,9 @@ - + + type="../rules_ros~/third_party/ros/rostest/advertisetest"> topics: - name: /chatter @@ -14,7 +14,7 @@ + type="../rules_ros~/third_party/ros/rostest/publishtest"> topics: - name: /chatter diff --git a/examples/dishwasher/BUILD.bazel b/examples/dishwasher/BUILD.bazel index 6088a1f..65ecc0e 100644 --- a/examples/dishwasher/BUILD.bazel +++ b/examples/dishwasher/BUILD.bazel @@ -2,13 +2,13 @@ interaction. """ -load("//ros:cc_defs.bzl", "cc_ros_binary") +load("@rules_ros//ros:cc_defs.bzl", "cc_ros_binary") load( - "//ros:interfaces.bzl", + "@rules_ros//ros:interfaces.bzl", "cc_ros_interface_library", "ros_interface_library", ) -load("//ros:launch.bzl", "ros_launch") +load("@rules_ros//ros:launch.bzl", "ros_launch") ros_interface_library( name = "dishwasher_actions", diff --git a/examples/dishwasher/dishwasher.launch b/examples/dishwasher/dishwasher.launch index ae03172..a42fb8d 100644 --- a/examples/dishwasher/dishwasher.launch +++ b/examples/dishwasher/dishwasher.launch @@ -1,4 +1,4 @@ - - + + diff --git a/examples/dynamic_reconfiguration/BUILD.bazel b/examples/dynamic_reconfiguration/BUILD.bazel index 7851677..e0e4b5c 100644 --- a/examples/dynamic_reconfiguration/BUILD.bazel +++ b/examples/dynamic_reconfiguration/BUILD.bazel @@ -2,13 +2,13 @@ for dynamic reconfiguration. """ -load("//ros:cc_defs.bzl", "cc_ros_binary") +load("@rules_ros//ros:cc_defs.bzl", "cc_ros_binary") load( - "//ros:dynamic_reconfigure.bzl", + "@rules_ros//ros:dynamic_reconfigure.bzl", "cc_ros_dynamic_reconfigure_library", "ros_dynamic_reconfigure_library", ) -load("//ros:launch.bzl", "ros_launch") +load("@rules_ros//ros:launch.bzl", "ros_launch") ros_dynamic_reconfigure_library( name = "tutorial_cfg", diff --git a/examples/dynamic_reconfiguration/dynamic_reconfiguration.launch b/examples/dynamic_reconfiguration/dynamic_reconfiguration.launch index 274acce..90669c1 100644 --- a/examples/dynamic_reconfiguration/dynamic_reconfiguration.launch +++ b/examples/dynamic_reconfiguration/dynamic_reconfiguration.launch @@ -1,4 +1,4 @@ - - + + diff --git a/ros/BUILD.bazel b/ros/BUILD.bazel index 1b31b65..2dce8fa 100644 --- a/ros/BUILD.bazel +++ b/ros/BUILD.bazel @@ -17,5 +17,5 @@ py_binary( srcs = ["parameter_generator_app.py"], main = "parameter_generator_app.py", visibility = ["//visibility:public"], - deps = ["@com_github_mvukov_rules_ros//third_party/ros:dynamic_reconfigure"], + deps = ["@rules_ros//third_party/ros:dynamic_reconfigure"], ) diff --git a/ros/dynamic_reconfigure.bzl b/ros/dynamic_reconfigure.bzl index b0b2b49..329312e 100644 --- a/ros/dynamic_reconfigure.bzl +++ b/ros/dynamic_reconfigure.bzl @@ -95,7 +95,7 @@ cc_ros_dynamic_reconfigure_generator = rule( providers = [RosDynamicReconfigureInfo], ), "_generator": attr.label( - default = Label("@com_github_mvukov_rules_ros//ros:parameter_generator_app"), + default = Label("@rules_ros//ros:parameter_generator_app"), executable = True, cfg = "exec", ), diff --git a/ros/launch.bzl b/ros/launch.bzl index c1c91aa..9c5dd4b 100644 --- a/ros/launch.bzl +++ b/ros/launch.bzl @@ -21,7 +21,7 @@ def ros_launch(name, nodes, launch_files, **kwargs): launch_script = "{}_launch.py".format(name) expand_template( name = "{}_launch_gen".format(name), - template = "@com_github_mvukov_rules_ros//ros:launch.py.tpl", + template = "@rules_ros//ros:launch.py.tpl", substitutions = substitutions, out = launch_script, data = launch_files, @@ -32,6 +32,6 @@ def ros_launch(name, nodes, launch_files, **kwargs): srcs = [launch_script], data = nodes + launch_files, main = launch_script, - deps = ["@com_github_mvukov_rules_ros//third_party/ros:roslaunch"], + deps = ["@rules_ros//third_party/ros:roslaunch"], **kwargs ) diff --git a/ros/repositories/actionlib.BUILD.bazel b/ros/repositories/actionlib.BUILD.bazel index 3a4d2ab..b552e41 100644 --- a/ros/repositories/actionlib.BUILD.bazel +++ b/ros/repositories/actionlib.BUILD.bazel @@ -1,8 +1,8 @@ """ Builds actionlib. """ -load("@com_github_mvukov_rules_ros//ros:cc_defs.bzl", "cc_ros_library") load("@rules_python//python:defs.bzl", "py_library") +load("@rules_ros//ros:cc_defs.bzl", "cc_ros_library") cc_ros_library( name = "actionlib", diff --git a/ros/repositories/common_msgs.BUILD.bazel b/ros/repositories/common_msgs.BUILD.bazel index 2893dad..f06d32d 100644 --- a/ros/repositories/common_msgs.BUILD.bazel +++ b/ros/repositories/common_msgs.BUILD.bazel @@ -1,14 +1,14 @@ """ Builds common_msgs. """ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_python//python:defs.bzl", "py_binary", "py_library") load( - "@com_github_mvukov_rules_ros//ros:interfaces.bzl", + "@rules_ros//ros:interfaces.bzl", "cc_ros_interface_library", "py_ros_interface_library", "ros_interface_library", ) -load("@rules_cc//cc:defs.bzl", "cc_library") -load("@rules_python//python:defs.bzl", "py_binary", "py_library") ros_interface_library( name = "actionlib_msgs", diff --git a/ros/repositories/dynamic_reconfigure.BUILD.bazel b/ros/repositories/dynamic_reconfigure.BUILD.bazel index 5274b7a..5a4f7a3 100644 --- a/ros/repositories/dynamic_reconfigure.BUILD.bazel +++ b/ros/repositories/dynamic_reconfigure.BUILD.bazel @@ -1,9 +1,9 @@ """ Builds dynamic_reconfigure. """ -load("@com_github_mvukov_rules_ros//ros:cc_defs.bzl", "cc_ros_library") +load("@rules_ros//ros:cc_defs.bzl", "cc_ros_library") load( - "@com_github_mvukov_rules_ros//ros:interfaces.bzl", + "@rules_ros//ros:interfaces.bzl", "cc_ros_interface_library", "ros_interface_library", ) diff --git a/ros/repositories/geometry2.BUILD.bazel b/ros/repositories/geometry2.BUILD.bazel index eac68e2..de62fbf 100644 --- a/ros/repositories/geometry2.BUILD.bazel +++ b/ros/repositories/geometry2.BUILD.bazel @@ -2,12 +2,12 @@ """ load( - "@com_github_mvukov_rules_ros//ros:cc_defs.bzl", + "@rules_ros//ros:cc_defs.bzl", "cc_ros_binary", "cc_ros_library", ) load( - "@com_github_mvukov_rules_ros//ros:interfaces.bzl", + "@rules_ros//ros:interfaces.bzl", "cc_ros_interface_library", "ros_interface_library", ) diff --git a/ros/repositories/orocos_kdl.BUILD.bazel b/ros/repositories/orocos_kdl.BUILD.bazel index 3fd557c..a2dfcee 100644 --- a/ros/repositories/orocos_kdl.BUILD.bazel +++ b/ros/repositories/orocos_kdl.BUILD.bazel @@ -1,11 +1,11 @@ """ Builds orocos_kdl. """ +load("@rules_cc//cc:defs.bzl", "cc_library") load( - "@com_github_mvukov_rules_ros//third_party:expand_template.bzl", + "@rules_ros//third_party:expand_template.bzl", "expand_template", ) -load("@rules_cc//cc:defs.bzl", "cc_library") cc_library( name = "orocos_kdl", diff --git a/ros/repositories/repositories.bzl b/ros/repositories/repositories.bzl index 282467e..7c62c1a 100644 --- a/ros/repositories/repositories.bzl +++ b/ros/repositories/repositories.bzl @@ -11,7 +11,7 @@ def ros_repositories(): maybe( http_archive, name = "console_bridge", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:console_bridge.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:console_bridge.BUILD.bazel", sha256 = "2ff175a9bb2b1849f12a6bf972ce7e4313d543a2bbc83b60fdae7db6e0ba353f", strip_prefix = "console_bridge-1.0.1", urls = ["https://github.com/ros/console_bridge/archive/1.0.1.tar.gz"], @@ -20,7 +20,7 @@ def ros_repositories(): maybe( http_archive, name = "roscpp_core", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:roscpp_core.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:roscpp_core.BUILD.bazel", sha256 = "a2aa77814ed97b48995c872a405c51f6b0f1ab9d40e38ece483852bbd273ad7b", strip_prefix = "roscpp_core-0.7.2", urls = ["https://github.com/ros/roscpp_core/archive/0.7.2.tar.gz"], @@ -29,7 +29,7 @@ def ros_repositories(): maybe( http_archive, name = "rosconsole", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:rosconsole.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:rosconsole.BUILD.bazel", sha256 = "0b2cbc4f9a92466c0fbae7863482b286ef87692de4941527cb429e6c74639246", strip_prefix = "rosconsole-1.14.3", urls = ["https://github.com/ros/rosconsole/archive/1.14.3.tar.gz"], @@ -38,7 +38,7 @@ def ros_repositories(): maybe( http_archive, name = "ros_genmsg", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:genmsg.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:genmsg.BUILD.bazel", sha256 = "0e414846823a2aaa7781f81268251c7c9a45ff96cef8e6a78bbbbcf7e4c28d56", strip_prefix = "genmsg-0.5.16", urls = ["https://github.com/ros/genmsg/archive/0.5.16.tar.gz"], @@ -47,7 +47,7 @@ def ros_repositories(): maybe( http_archive, name = "ros_gencpp", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:gencpp.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:gencpp.BUILD.bazel", sha256 = "05acfeeb1bbc374356bf7674fee2a7aab3bf6a48ebad4a06fd0f0d4455a60720", strip_prefix = "gencpp-0.6.5", urls = ["https://github.com/ros/gencpp/archive/0.6.5.tar.gz"], @@ -56,7 +56,7 @@ def ros_repositories(): maybe( http_archive, name = "ros_genpy", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:genpy.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:genpy.BUILD.bazel", sha256 = "523d20068171ce7e5b4c453eba7976aafa819e6b5af806ffdf6bc1d7a1dfc2a8", strip_prefix = "genpy-0.6.14", urls = ["https://github.com/ros/genpy/archive/0.6.14.tar.gz"], @@ -65,7 +65,7 @@ def ros_repositories(): maybe( http_archive, name = "ros_std_msgs", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:std_msgs.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:std_msgs.BUILD.bazel", sha256 = "ee6592d37b00a94cab8216aac2cfb5120f6da09ffa94bfe197fe8dc76dd21326", strip_prefix = "std_msgs-0.5.13", urls = ["https://github.com/ros/std_msgs/archive/0.5.13.tar.gz"], @@ -74,7 +74,7 @@ def ros_repositories(): maybe( http_archive, name = "ros_comm_msgs", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:ros_comm_msgs.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:ros_comm_msgs.BUILD.bazel", sha256 = "5b8b91e8671d03ea84ba32a3ea7360bc4594655e7ba3ec6677a984f393aaafbd", strip_prefix = "ros_comm_msgs-1.11.3", urls = ["https://github.com/ros/ros_comm_msgs/archive/1.11.3.tar.gz"], @@ -84,7 +84,7 @@ def ros_repositories(): maybe( http_archive, name = "ros_comm", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:ros_comm.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:ros_comm.BUILD.bazel", sha256 = "65906eab18bdf5832af7b6de8c21e3d87d3fac9732a1219637f5b6f5c948508d", strip_prefix = "ros_comm-30922861f247937001f82094c0934a6b802b6325", urls = ["https://github.com/mvukov/ros_comm/archive/30922861f247937001f82094c0934a6b802b6325.tar.gz"], @@ -93,7 +93,7 @@ def ros_repositories(): maybe( http_archive, name = "ros_ros", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:ros.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:ros.BUILD.bazel", sha256 = "7a1e729de9be807862b6ed721475fec74583f6dc0c06b233b06b1b9fda31291e", strip_prefix = "ros-1.15.7", urls = ["https://github.com/ros/ros/archive/1.15.7.tar.gz"], @@ -102,7 +102,7 @@ def ros_repositories(): maybe( http_archive, name = "ros_common_msgs", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:common_msgs.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:common_msgs.BUILD.bazel", sha256 = "74af8cc88bdc9c23cbc270d322e50562857e2c877359423f389d51c0735ee230", strip_prefix = "common_msgs-1.13.1", urls = ["https://github.com/ros/common_msgs/archive/1.13.1.tar.gz"], @@ -111,7 +111,7 @@ def ros_repositories(): maybe( http_archive, name = "ros_actionlib", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:actionlib.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:actionlib.BUILD.bazel", sha256 = "b741755881e30b9aea6bcdd9831e3f0932a8bbba02fa59e5c0e5970280024055", strip_prefix = "actionlib-1.13.2", urls = ["https://github.com/ros/actionlib/archive/1.13.2.tar.gz"], @@ -120,7 +120,7 @@ def ros_repositories(): maybe( http_archive, name = "ros_dynamic_reconfigure", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:dynamic_reconfigure.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:dynamic_reconfigure.BUILD.bazel", sha256 = "7cdb46269ae222a0ed5632d7c9b9d6f1e351c35dc9cc14b48930ad89273a5da5", strip_prefix = "dynamic_reconfigure-1.7.1", urls = ["https://github.com/ros/dynamic_reconfigure/archive/refs/tags/1.7.1.tar.gz"], @@ -131,7 +131,7 @@ def ros_repositories(): maybe( http_archive, name = "ros_geometry2", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:geometry2.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:geometry2.BUILD.bazel", sha256 = "0b5d461c71d6dc1dbdb99a2ba39e1515194cd451c2e53d53caadb3ecea13367a", strip_prefix = "geometry2-0.7.5", urls = ["https://github.com/ros/geometry2/archive/0.7.5.tar.gz"], @@ -140,7 +140,7 @@ def ros_repositories(): maybe( http_archive, name = "orocos_kdl", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:orocos_kdl.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:orocos_kdl.BUILD.bazel", sha256 = "5acb90acd82b10971717aca6c17874390762ecdaa3a8e4db04984ea1d4a2af9b", strip_prefix = "orocos_kinematics_dynamics-1.5.1", urls = ["https://github.com/orocos/orocos_kinematics_dynamics/archive/refs/tags/v1.5.1.tar.gz"], @@ -149,7 +149,7 @@ def ros_repositories(): maybe( http_archive, name = "urdfdom_headers", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:urdfdom_headers.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:urdfdom_headers.BUILD.bazel", sha256 = "76a68657c38e54bb45bddc4bd7d823a3b04edcd08064a56d8e7d46b9912035ac", strip_prefix = "urdfdom_headers-1.0.5", urls = ["https://github.com/ros/urdfdom_headers/archive/refs/tags/1.0.5.tar.gz"], @@ -158,7 +158,7 @@ def ros_repositories(): maybe( http_archive, name = "tinyxml", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:tinyxml.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:tinyxml.BUILD.bazel", sha256 = "15bdfdcec58a7da30adc87ac2b078e4417dbe5392f3afb719f9ba6d062645593", urls = [ "https://sourceforge.net/projects/tinyxml/files/tinyxml/2.6.2/tinyxml_2_6_2.tar.gz", @@ -169,7 +169,7 @@ def ros_repositories(): maybe( http_archive, name = "urdfdom", - build_file = "@com_github_mvukov_rules_ros//ros/repositories:urdfdom.BUILD.bazel", + build_file = "@rules_ros//ros/repositories:urdfdom.BUILD.bazel", sha256 = "8f3d56b0cbc4b84436d8baf4c8346cd2ee7ffb257bba5ddd9892c41bf516edc4", strip_prefix = "urdfdom-1.0.4", urls = ["https://github.com/ros/urdfdom/archive/refs/tags/1.0.4.tar.gz"], diff --git a/ros/repositories/ros_comm.BUILD.bazel b/ros/repositories/ros_comm.BUILD.bazel index bb72105..4df885b 100644 --- a/ros/repositories/ros_comm.BUILD.bazel +++ b/ros/repositories/ros_comm.BUILD.bazel @@ -3,23 +3,23 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts") load("@bazel_skylib//rules:copy_file.bzl", "copy_file") +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_python//python:defs.bzl", "py_binary", "py_library") load( - "@com_github_mvukov_rules_ros//ros:cc_defs.bzl", + "@rules_ros//ros:cc_defs.bzl", "cc_ros_binary", "cc_ros_library", ) load( - "@com_github_mvukov_rules_ros//ros:interfaces.bzl", + "@rules_ros//ros:interfaces.bzl", "cc_ros_interface_library", "py_ros_interface_library", "ros_interface_library", ) load( - "@com_github_mvukov_rules_ros//third_party:expand_template.bzl", + "@rules_ros//third_party:expand_template.bzl", "expand_template", ) -load("@rules_cc//cc:defs.bzl", "cc_library") -load("@rules_python//python:defs.bzl", "py_binary", "py_library") load("@rules_ros_pip_deps//:requirements.bzl", "requirement") cc_library( @@ -148,7 +148,7 @@ expand_template( substitutions = { "{default_python_logging_conf}": "$(rootpath {})".format(_DEFAULT_PYTHON_LOGGING_CONFIG), }, - template = "@com_github_mvukov_rules_ros//ros/repositories:ros_logging_config.py.tpl", + template = "@rules_ros//ros/repositories:ros_logging_config.py.tpl", ) py_library( @@ -342,7 +342,7 @@ py_library( deps = [ ":py_topic_tools", ":rospy", - "@com_github_mvukov_rules_ros//third_party/ros:roslib", + "@rules_ros//third_party/ros:roslib", requirement("gnupg"), requirement("pycryptodomex"), requirement("rospkg"), @@ -357,10 +357,10 @@ py_library( deps = [ ":py_roscpp", ":rosgraph_lib", - "@com_github_mvukov_rules_ros//third_party/ros:roslib", "@ros_comm_msgs//:py_rosgraph_msgs", "@ros_genpy//:genpy", "@ros_std_msgs//:py_std_msgs", + "@rules_ros//third_party/ros:roslib", requirement("numpy"), requirement("pyyaml"), requirement("rospkg"), diff --git a/ros/repositories/ros_comm_msgs.BUILD.bazel b/ros/repositories/ros_comm_msgs.BUILD.bazel index c380635..4a41b28 100644 --- a/ros/repositories/ros_comm_msgs.BUILD.bazel +++ b/ros/repositories/ros_comm_msgs.BUILD.bazel @@ -2,7 +2,7 @@ """ load( - "@com_github_mvukov_rules_ros//ros:interfaces.bzl", + "@rules_ros//ros:interfaces.bzl", "cc_ros_interface_library", "py_ros_interface_library", "ros_interface_library", diff --git a/ros/repositories/rosconsole.BUILD.bazel b/ros/repositories/rosconsole.BUILD.bazel index 3c706e8..558680d 100644 --- a/ros/repositories/rosconsole.BUILD.bazel +++ b/ros/repositories/rosconsole.BUILD.bazel @@ -1,7 +1,7 @@ """ Builds rosconsole. """ -load("@com_github_mvukov_rules_ros//ros:cc_defs.bzl", "cc_ros_library") +load("@rules_ros//ros:cc_defs.bzl", "cc_ros_library") cc_ros_library( name = "rosconsole", diff --git a/ros/repositories/roscpp_core.BUILD.bazel b/ros/repositories/roscpp_core.BUILD.bazel index 43748e6..5ed5e97 100644 --- a/ros/repositories/roscpp_core.BUILD.bazel +++ b/ros/repositories/roscpp_core.BUILD.bazel @@ -1,8 +1,8 @@ """ Builds roscpp_core. """ -load("@com_github_mvukov_rules_ros//ros:cc_defs.bzl", "cc_ros_library") load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_ros//ros:cc_defs.bzl", "cc_ros_library") cc_ros_library( name = "cpp_common", diff --git a/ros/repositories/std_msgs.BUILD.bazel b/ros/repositories/std_msgs.BUILD.bazel index 47e72e6..bc1ddb6 100644 --- a/ros/repositories/std_msgs.BUILD.bazel +++ b/ros/repositories/std_msgs.BUILD.bazel @@ -1,13 +1,13 @@ """ Builds std_msgs. """ +load("@rules_cc//cc:defs.bzl", "cc_library") load( - "@com_github_mvukov_rules_ros//ros:interfaces.bzl", + "@rules_ros//ros:interfaces.bzl", "cc_ros_interface_library", "py_ros_interface_library", "ros_interface_library", ) -load("@rules_cc//cc:defs.bzl", "cc_library") ros_interface_library( name = "std_msgs", diff --git a/ros/repositories/urdfdom.BUILD.bazel b/ros/repositories/urdfdom.BUILD.bazel index 8aee374..782fc98 100644 --- a/ros/repositories/urdfdom.BUILD.bazel +++ b/ros/repositories/urdfdom.BUILD.bazel @@ -2,7 +2,7 @@ """ load( - "@com_github_mvukov_rules_ros//ros:cc_defs.bzl", + "@rules_ros//ros:cc_defs.bzl", "cc_ros_binary", "cc_ros_library", ) diff --git a/ros/test.bzl b/ros/test.bzl index 8e45b38..8a8faa5 100644 --- a/ros/test.bzl +++ b/ros/test.bzl @@ -21,7 +21,7 @@ def ros_test(name, nodes, launch_file, deps = [], **kwargs): launch_script = "{}_launch.py".format(name) expand_template( name = "{}_launch_gen".format(name), - template = "@com_github_mvukov_rules_ros//ros:test.py.tpl", + template = "@rules_ros//ros:test.py.tpl", substitutions = substitutions, out = launch_script, data = [launch_file], @@ -32,6 +32,6 @@ def ros_test(name, nodes, launch_file, deps = [], **kwargs): srcs = [launch_script], data = nodes + [launch_file], main = launch_script, - deps = ["@com_github_mvukov_rules_ros//third_party/ros/rostest"] + deps, + deps = ["@rules_ros//third_party/ros/rostest"] + deps, **kwargs ) diff --git a/third_party/ros/rostest/BUILD.bazel b/third_party/ros/rostest/BUILD.bazel index 672fbca..ba6d292 100644 --- a/third_party/ros/rostest/BUILD.bazel +++ b/third_party/ros/rostest/BUILD.bazel @@ -12,9 +12,9 @@ py_library( ], visibility = ["//visibility:public"], deps = [ - "@com_github_mvukov_rules_ros//third_party/ros:roslaunch", "@ros_comm//:rospy", "@ros_ros//:rosunit", + "@rules_ros//third_party/ros:roslaunch", ], ) @@ -24,7 +24,7 @@ py_binary( visibility = ["//visibility:public"], deps = [ ":rostest", - "@com_github_mvukov_rules_ros//third_party/ros/rosservice", + "@rules_ros//third_party/ros/rosservice", ], ) From 798243323a1a069ac8d4dbf1de05dfc74e914eba Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Thu, 8 Aug 2024 08:03:52 +0200 Subject: [PATCH 02/17] Specify Python version in .bazelrc --- .bazelrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bazelrc b/.bazelrc index ba54ac1..800dbe5 100644 --- a/.bazelrc +++ b/.bazelrc @@ -26,6 +26,8 @@ build --heap_dump_on_oom # Speed up all builds by not checking if output files have been modified. build --noexperimental_check_output_files +build --@rules_python//python/config_settings:python_version=3.10 + # Don't bother building targets which aren't dependencies of the tests. test --build_tests_only From 6d2db95c7ecbe1c90e8fc27291f47bdcb966c478 Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Thu, 8 Aug 2024 23:29:18 +0200 Subject: [PATCH 03/17] Symlink test utils --- examples/README.md | 3 -- examples/chatter/BUILD.bazel | 17 +++++++- ...r_tests.launch => talker_tests.launch.tpl} | 4 +- third_party/BUILD.bazel | 1 + third_party/ros/rostest/BUILD.bazel | 41 +++++++++++++++---- third_party/symlink.bzl | 31 ++++++++++++++ 6 files changed, 83 insertions(+), 14 deletions(-) rename examples/chatter/{talker_tests.launch => talker_tests.launch.tpl} (77%) create mode 100644 third_party/symlink.bzl diff --git a/examples/README.md b/examples/README.md index 333d03a..e69de29 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,3 +0,0 @@ -``` -bazel test //... --@rules_python//python/config_settings:python_version=3.10 -``` diff --git a/examples/chatter/BUILD.bazel b/examples/chatter/BUILD.bazel index d60919f..1567cdb 100644 --- a/examples/chatter/BUILD.bazel +++ b/examples/chatter/BUILD.bazel @@ -18,6 +18,7 @@ load( load("@rules_ros//ros:launch.bzl", "ros_launch") load("@rules_ros//ros:test.bzl", "ros_test") load("@rules_ros//ros:topic.bzl", "ros_topic") +load("@rules_ros//third_party:expand_template.bzl", "expand_template") # Handling of ROS messages & services resembles to some extent Bazel's rules for # handling protobuf messages (e.g. proto_library and cc_proto_library). @@ -58,7 +59,7 @@ cc_ros_binary( # Defines tests for the talker node. ros_test( name = "talker_tests", - launch_file = "talker_tests.launch", + launch_file = ":talker_tests.launch", nodes = [ ":talker", "@rules_ros//third_party/ros/rostest:advertisetest", @@ -66,6 +67,20 @@ ros_test( ], ) +expand_template( + name = "talker_tests_launch", + out = "talker_tests.launch", + data = [ + "@rules_ros//third_party/ros/rostest:advertisetest", + "@rules_ros//third_party/ros/rostest:publishtest", + ], + substitutions = { + "{advertisetest}": "$(rootpath @rules_ros//third_party/ros/rostest:advertisetest)", + "{publishtest}": "$(rootpath @rules_ros//third_party/ros/rostest:publishtest)", + }, + template = "talker_tests.launch.tpl", +) + # Defines a C++ listener ROS node. cc_ros_binary( name = "listener", diff --git a/examples/chatter/talker_tests.launch b/examples/chatter/talker_tests.launch.tpl similarity index 77% rename from examples/chatter/talker_tests.launch rename to examples/chatter/talker_tests.launch.tpl index aaccd50..b68622e 100644 --- a/examples/chatter/talker_tests.launch +++ b/examples/chatter/talker_tests.launch.tpl @@ -3,7 +3,7 @@ + type="{advertisetest}"> topics: - name: /chatter @@ -14,7 +14,7 @@ + type="{publishtest}"> topics: - name: /chatter diff --git a/third_party/BUILD.bazel b/third_party/BUILD.bazel index 107fccc..7a0c019 100644 --- a/third_party/BUILD.bazel +++ b/third_party/BUILD.bazel @@ -1,3 +1,4 @@ exports_files([ "expand_template.bzl", + "symlink.bzl", ]) diff --git a/third_party/ros/rostest/BUILD.bazel b/third_party/ros/rostest/BUILD.bazel index ba6d292..364715c 100644 --- a/third_party/ros/rostest/BUILD.bazel +++ b/third_party/ros/rostest/BUILD.bazel @@ -1,5 +1,6 @@ load("@rules_python//python:defs.bzl", "py_binary", "py_library") load("//build_tools:pylint.bzl", "pylint") +load("//third_party:symlink.bzl", "symlink") py_library( name = "rostest", @@ -19,38 +20,62 @@ py_library( ) py_binary( - name = "advertisetest", + name = "advertisetest_impl", srcs = ["advertisetest.py"], - visibility = ["//visibility:public"], + main = "advertisetest.py", deps = [ ":rostest", "@rules_ros//third_party/ros/rosservice", ], ) +symlink( + name = "advertisetest", + executable = ":advertisetest_impl", + visibility = ["//visibility:public"], +) + py_binary( - name = "hztest", + name = "hztest_impl", srcs = ["hztest.py"], - visibility = ["//visibility:public"], + main = "hztest.py", deps = [ ":rostest", ], ) +symlink( + name = "hztest", + executable = ":hztest_impl", + visibility = ["//visibility:public"], +) + py_binary( - name = "paramtest", + name = "paramtest_impl", srcs = ["paramtest.py"], - visibility = ["//visibility:public"], + main = "paramtest.py", deps = [ ":rostest", ], ) +symlink( + name = "paramtest", + executable = ":paramtest_impl", + visibility = ["//visibility:public"], +) + py_binary( - name = "publishtest", + name = "publishtest_impl", srcs = ["publishtest.py"], - visibility = ["//visibility:public"], + main = "publishtest.py", deps = [":rostest"], ) +symlink( + name = "publishtest", + executable = ":publishtest_impl", + visibility = ["//visibility:public"], +) + pylint() diff --git a/third_party/symlink.bzl b/third_party/symlink.bzl new file mode 100644 index 0000000..207f226 --- /dev/null +++ b/third_party/symlink.bzl @@ -0,0 +1,31 @@ +# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# Adapted from https://github.com/digital-asset/daml/pull/8428 + +def _symlink_impl(ctx): + executable = ctx.actions.declare_file(ctx.label.name) + ctx.actions.symlink( + output = executable, + target_file = ctx.executable.executable, + is_executable = True, + ) + + runfiles = ctx.runfiles(files = [ctx.executable.executable]) + runfiles = runfiles.merge(ctx.attr.executable[DefaultInfo].default_runfiles) + return [DefaultInfo( + executable = executable, + files = depset(direct = [executable]), + runfiles = runfiles, + )] + +symlink = rule( + _symlink_impl, + attrs = { + "executable": attr.label( + executable = True, + cfg = "target", + ), + }, + executable = True, + doc = "Creates a new target for the given executable.", +) From a07dc97424c91ee51b96b275bd578448ae6b0a08 Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Thu, 8 Aug 2024 23:31:41 +0200 Subject: [PATCH 04/17] Fix nit --- examples/chatter/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/chatter/BUILD.bazel b/examples/chatter/BUILD.bazel index 1567cdb..ed91d87 100644 --- a/examples/chatter/BUILD.bazel +++ b/examples/chatter/BUILD.bazel @@ -59,7 +59,7 @@ cc_ros_binary( # Defines tests for the talker node. ros_test( name = "talker_tests", - launch_file = ":talker_tests.launch", + launch_file = "talker_tests.launch", nodes = [ ":talker", "@rules_ros//third_party/ros/rostest:advertisetest", From b54469301daf22a8660ee56a2ce75048d8eb5c55 Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Sat, 10 Aug 2024 21:19:12 +0200 Subject: [PATCH 05/17] Update CI config --- .github/workflows/main.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0cc4f3c..5c7e0c3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,6 +51,21 @@ jobs: image: mvukov/bazel-builder:commit-49178bdf9c151b1fdb1fb0bac580da5d53a990fd options: --user ${{ needs.configure.outputs.uid_gid }} + # Run bazel test with gcc and clang in each workspace + strategy: + matrix: + folder: + - "." + - "examples" + toolchain: + - "gcc" + - "clang" + include: + - toolchain: "gcc" + config_option: "" + - toolchain: "clang" + config_option: "--config=clang" + steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v4 @@ -74,12 +89,13 @@ jobs: path: | ~/.cache/bazel ~/.cache/bazel-repo - key: v1-bazel-repo-cache-${{ hashFiles('.bazelversion', 'MODULE.bazel', 'repositories/**', 'requirements_lock.txt') }} - restore-keys: v4-bazel-repo-cache - - name: bazel test //... + key: v4-bazel-repo-cache-${{ matrix.toolchain }}-${{ hashFiles('.bazelversion', 'examples/WORKSPACE', 'repositories/**', 'requirements_lock.txt', 'WORKSPACE') }} + restore-keys: v4-bazel-repo-cache-${{ matrix.toolchain }}- + - name: bazel test ${{ matrix.config_option }} //... env: # Bazelisk will download bazel to here, ensure it is cached between runs. XDG_CACHE_HOME: /github/home/.cache/bazel-repo BUILDBUDDY_ORG_API_KEY: ${{ secrets.BUILDBUDDY_ORG_API_KEY }} USER: ${{ needs.configure.outputs.user_name }} - run: ${GITHUB_WORKSPACE}/.github/workflows/test.sh + working-directory: ${{ matrix.folder }} + run: ${GITHUB_WORKSPACE}/.github/workflows/test.sh ${{ matrix.config_option }} From da645f0345767616698436a2ef7e1ddd89bf451f Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Sat, 10 Aug 2024 21:19:27 +0200 Subject: [PATCH 06/17] Update docs --- .bazelrc | 1 + BUILD.bazel | 30 -------------- README.md | 53 +----------------------- examples/BUILD.bazel | 29 +++++++++++++ examples/README.md | 19 +++++++++ examples/chatter/BUILD.bazel | 2 + examples/chatter/README.md | 48 +++++++++++++++++++++ examples/chatter/talker_tests.launch.tpl | 2 +- 8 files changed, 101 insertions(+), 83 deletions(-) create mode 100644 examples/BUILD.bazel create mode 100644 examples/chatter/README.md diff --git a/.bazelrc b/.bazelrc index 800dbe5..1c2de90 100644 --- a/.bazelrc +++ b/.bazelrc @@ -26,6 +26,7 @@ build --heap_dump_on_oom # Speed up all builds by not checking if output files have been modified. build --noexperimental_check_output_files +# This is a mandatory flag. build --@rules_python//python/config_settings:python_version=3.10 # Don't bother building targets which aren't dependencies of the tests. diff --git a/BUILD.bazel b/BUILD.bazel index 011a5c4..66d2adc 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -13,33 +13,3 @@ exports_files([ "requirements.txt", "requirements_lock.txt", ]) - -alias( - name = "roscore", - actual = "//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 = "//third_party/ros/rosservice", -) diff --git a/README.md b/README.md index ea64008..b3a55e1 100644 --- a/README.md +++ b/README.md @@ -20,58 +20,7 @@ So far a subset of ros-base packages can be built, including support for - actions, and - dynamic reconfiguration. -Here is an 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 //examples/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 //examples/chatter:listener # C++ version or -bazel run //examples/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_.bag # to play a bag -``` - -`rostopic`, tied to this example (see `examples/chatter/BUILD.bazel` for more -info) can be used as - -```sh -bazel run //examples/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 //examples/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. - -In `//examples/dishwasher` you can find another example that demonstrates -defining and usage of ROS actions (and actionlib). +Please take a look at the [examples](examples) folder to get started. ## Background and design decisions diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel new file mode 100644 index 0000000..7ef9ce1 --- /dev/null +++ b/examples/BUILD.bazel @@ -0,0 +1,29 @@ +alias( + 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", +) diff --git a/examples/README.md b/examples/README.md index e69de29..c59dbac 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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). diff --git a/examples/chatter/BUILD.bazel b/examples/chatter/BUILD.bazel index ed91d87..7591675 100644 --- a/examples/chatter/BUILD.bazel +++ b/examples/chatter/BUILD.bazel @@ -71,10 +71,12 @@ expand_template( name = "talker_tests_launch", out = "talker_tests.launch", data = [ + ":talker", "@rules_ros//third_party/ros/rostest:advertisetest", "@rules_ros//third_party/ros/rostest:publishtest", ], substitutions = { + "{talker}": "$(rootpath :talker)", "{advertisetest}": "$(rootpath @rules_ros//third_party/ros/rostest:advertisetest)", "{publishtest}": "$(rootpath @rules_ros//third_party/ros/rostest:publishtest)", }, diff --git a/examples/chatter/README.md b/examples/chatter/README.md new file mode 100644 index 0000000..02f5b40 --- /dev/null +++ b/examples/chatter/README.md @@ -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_.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. diff --git a/examples/chatter/talker_tests.launch.tpl b/examples/chatter/talker_tests.launch.tpl index b68622e..cbe86df 100644 --- a/examples/chatter/talker_tests.launch.tpl +++ b/examples/chatter/talker_tests.launch.tpl @@ -1,5 +1,5 @@ - + Date: Sat, 10 Aug 2024 21:25:09 +0200 Subject: [PATCH 07/17] Update docs --- examples/MODULE.bazel | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel index 6dfb45d..18bf8e2 100644 --- a/examples/MODULE.bazel +++ b/examples/MODULE.bazel @@ -1,12 +1,24 @@ module(name = "rules_ros_examples") bazel_dep(name = "rules_python", version = "0.34.0") + +# 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 +# (mono)repo as follows: +# bazel_dep(name = "rules_ros") +# archive_override( +# module_name = "rules_ros", +# integrity = "sha256-", +# strip_prefix = "rules_ros-", +# urls = "https://github.com/mvukov/rules_ros/archive/.tar.gz" +# ) + non_module_ros_repositories = use_extension("@rules_ros//ros:extensions.bzl", "non_module_dependencies") use_repo( non_module_ros_repositories, From ab75189893944b423e5c0939e78fb7e432427604 Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Sat, 10 Aug 2024 21:26:48 +0200 Subject: [PATCH 08/17] Update CI config --- .github/workflows/main.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5c7e0c3..8f5f887 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -57,14 +57,6 @@ jobs: folder: - "." - "examples" - toolchain: - - "gcc" - - "clang" - include: - - toolchain: "gcc" - config_option: "" - - toolchain: "clang" - config_option: "--config=clang" steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it @@ -89,13 +81,13 @@ jobs: path: | ~/.cache/bazel ~/.cache/bazel-repo - key: v4-bazel-repo-cache-${{ matrix.toolchain }}-${{ hashFiles('.bazelversion', 'examples/WORKSPACE', 'repositories/**', 'requirements_lock.txt', 'WORKSPACE') }} + key: v4-bazel-repo-cache-${{ matrix.toolchain }}-${{ hashFiles('.bazelversion', 'examples/MODULE.bazel', 'repositories/**', 'requirements_lock.txt', 'MODULE.bazel') }} restore-keys: v4-bazel-repo-cache-${{ matrix.toolchain }}- - - name: bazel test ${{ matrix.config_option }} //... + - name: bazel test //... env: # Bazelisk will download bazel to here, ensure it is cached between runs. XDG_CACHE_HOME: /github/home/.cache/bazel-repo BUILDBUDDY_ORG_API_KEY: ${{ secrets.BUILDBUDDY_ORG_API_KEY }} USER: ${{ needs.configure.outputs.user_name }} working-directory: ${{ matrix.folder }} - run: ${GITHUB_WORKSPACE}/.github/workflows/test.sh ${{ matrix.config_option }} + run: ${GITHUB_WORKSPACE}/.github/workflows/test.sh From 715addfbebd6703295764efc52fa37ac9baea718 Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Sat, 10 Aug 2024 21:27:37 +0200 Subject: [PATCH 09/17] Update CI config --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8f5f887..904f805 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -81,8 +81,8 @@ jobs: path: | ~/.cache/bazel ~/.cache/bazel-repo - key: v4-bazel-repo-cache-${{ matrix.toolchain }}-${{ hashFiles('.bazelversion', 'examples/MODULE.bazel', 'repositories/**', 'requirements_lock.txt', 'MODULE.bazel') }} - restore-keys: v4-bazel-repo-cache-${{ matrix.toolchain }}- + key: v4-bazel-repo-cache-${{ hashFiles('.bazelversion', 'examples/MODULE.bazel', 'repositories/**', 'requirements_lock.txt', 'MODULE.bazel') }} + restore-keys: v4-bazel-repo-cache- - name: bazel test //... env: # Bazelisk will download bazel to here, ensure it is cached between runs. From f5b4141333c72a20d2279f0f818084de157bb050 Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Sat, 10 Aug 2024 21:32:58 +0200 Subject: [PATCH 10/17] Simplify examples module --- examples/MODULE.bazel | 6 ------ 1 file changed, 6 deletions(-) diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel index 18bf8e2..ebe2a5f 100644 --- a/examples/MODULE.bazel +++ b/examples/MODULE.bazel @@ -49,9 +49,3 @@ archive_override( strip_prefix = "rules_boost-42d8155d8f20a1aee8ee20b7903a495bdfb9befd", urls = "https://github.com/nelhage/rules_boost/archive/42d8155d8f20a1aee8ee20b7903a495bdfb9befd.zip", ) - -non_module_boost_repositories = use_extension("@rules_boost//:boost/repositories.bzl", "non_module_dependencies") -use_repo( - non_module_boost_repositories, - "boost", -) From 3faf6937ef5b7ffdc51044fd93fcbe0953d82b70 Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Thu, 15 Aug 2024 11:00:13 +0200 Subject: [PATCH 11/17] Update examples/MODULE.bazel Co-authored-by: Finn --- examples/MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel index ebe2a5f..f6dd4e9 100644 --- a/examples/MODULE.bazel +++ b/examples/MODULE.bazel @@ -9,7 +9,7 @@ local_path_override( path = "..", ) -# In a normal workflow, you would typically import rules_ros2 into your +# In a normal workflow, you would typically import rules_ros into your # (mono)repo as follows: # bazel_dep(name = "rules_ros") # archive_override( From 63d7c24c243437cea5e1b807e3b98f246d381c77 Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Thu, 15 Aug 2024 11:03:59 +0200 Subject: [PATCH 12/17] Update docs --- examples/MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel index ebe2a5f..f6dd4e9 100644 --- a/examples/MODULE.bazel +++ b/examples/MODULE.bazel @@ -9,7 +9,7 @@ local_path_override( path = "..", ) -# In a normal workflow, you would typically import rules_ros2 into your +# In a normal workflow, you would typically import rules_ros into your # (mono)repo as follows: # bazel_dep(name = "rules_ros") # archive_override( From 8e88efe44828fb7d0238562fcc33c25e379ffd99 Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Thu, 15 Aug 2024 11:07:07 +0200 Subject: [PATCH 13/17] Update docs --- examples/BUILD.bazel | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index 7ef9ce1..9018280 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -1,3 +1,5 @@ +# The following aliases are defined for convenience. + alias( name = "roscore", actual = "@rules_ros//third_party/ros/roslaunch:roscore", From fc7278f38ec267a6a465ac5294db656ed0b9b9ab Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Wed, 21 Aug 2024 21:33:57 +0200 Subject: [PATCH 14/17] Fix nit --- .bazelrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.bazelrc b/.bazelrc index 1c2de90..1c41226 100644 --- a/.bazelrc +++ b/.bazelrc @@ -14,6 +14,9 @@ build --incompatible_default_to_explicit_init_py # This is a mandatory flag. build --cxxopt=-std=c++17 +# This is a mandatory flag for the user repos. +build --@rules_python//python/config_settings:python_version=3.10 + # Ensure that you don't accidentally make non-hermetic actions/tests # which depend on remote services. Tag an individual target with # tags=["requires-network"] to opt-out of the enforcement. @@ -26,9 +29,6 @@ build --heap_dump_on_oom # Speed up all builds by not checking if output files have been modified. build --noexperimental_check_output_files -# This is a mandatory flag. -build --@rules_python//python/config_settings:python_version=3.10 - # Don't bother building targets which aren't dependencies of the tests. test --build_tests_only From c1b897e0b1b0a1b6fae6aec55b117938d324faf2 Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Wed, 21 Aug 2024 21:35:40 +0200 Subject: [PATCH 15/17] Fix nit --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 904f805..3f7592f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -82,7 +82,7 @@ jobs: ~/.cache/bazel ~/.cache/bazel-repo key: v4-bazel-repo-cache-${{ hashFiles('.bazelversion', 'examples/MODULE.bazel', 'repositories/**', 'requirements_lock.txt', 'MODULE.bazel') }} - restore-keys: v4-bazel-repo-cache- + restore-keys: v4-bazel-repo-cache - name: bazel test //... env: # Bazelisk will download bazel to here, ensure it is cached between runs. From d8ead2dc1fcb4f68cbe2d5b6bb5206481fbf20d6 Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Wed, 21 Aug 2024 21:39:13 +0200 Subject: [PATCH 16/17] Expose @boost in the examples repo --- examples/MODULE.bazel | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel index f6dd4e9..393a9da 100644 --- a/examples/MODULE.bazel +++ b/examples/MODULE.bazel @@ -49,3 +49,9 @@ archive_override( strip_prefix = "rules_boost-42d8155d8f20a1aee8ee20b7903a495bdfb9befd", urls = "https://github.com/nelhage/rules_boost/archive/42d8155d8f20a1aee8ee20b7903a495bdfb9befd.zip", ) + +non_module_boost_repositories = use_extension("@rules_boost//:boost/repositories.bzl", "non_module_dependencies") +use_repo( + non_module_boost_repositories, + "boost", +) From 7c7df831a86ca2c18458822917d140bf26c17800 Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Wed, 21 Aug 2024 21:40:24 +0200 Subject: [PATCH 17/17] Fix nit --- .bazelrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelrc b/.bazelrc index 1c41226..f6f3986 100644 --- a/.bazelrc +++ b/.bazelrc @@ -14,7 +14,7 @@ build --incompatible_default_to_explicit_init_py # This is a mandatory flag. build --cxxopt=-std=c++17 -# This is a mandatory flag for the user repos. +# This is a mandatory flag for user repos. build --@rules_python//python/config_settings:python_version=3.10 # Ensure that you don't accidentally make non-hermetic actions/tests