diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 657bdd26..75ee97d7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -62,15 +62,15 @@ jobs: - "gcc" - "clang" external_dependency_system: - # - bzlmod # TODO: https://github.com/mvukov/rules_ros2/pull/238 + - bzlmod - workspace include: - toolchain: "gcc" config_option: "" - toolchain: "clang" config_option: "--config=clang" - # - external_dependency_system: bzlmod - # bzlmod_flags: --enable_bzlmod + - external_dependency_system: bzlmod + bzlmod_flags: --enable_bzlmod - external_dependency_system: workspace bzlmod_flags: --noenable_bzlmod diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6e4e1920..974f793f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,4 @@ default_language_version: - python: python3.10 node: 18.16.0 default_stages: [commit] diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000..bfb704c2 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,111 @@ +module(name = "com_github_mvukov_rules_ros2") + +bazel_dep(name = "asio", version = "1.28.2") +bazel_dep(name = "bazel_skylib", version = "1.5.0") +bazel_dep(name = "boringssl", version = "0.0.0-20240126-22d349c") +bazel_dep(name = "eigen", version = "3.4.0") +bazel_dep(name = "fmt", version = "10.2.1") +bazel_dep(name = "googletest", version = "1.14.0.bcr.1") +bazel_dep(name = "libyaml", version = "0.2.5") +bazel_dep(name = "lz4", version = "1.9.4") +bazel_dep(name = "nlohmann_json", version = "3.11.3") +bazel_dep(name = "platforms", version = "0.0.8") +bazel_dep(name = "readerwriterqueue", version = "1.0.6") +bazel_dep(name = "rules_cc", version = "0.0.9") +bazel_dep(name = "rules_foreign_cc", version = "0.10.1") +bazel_dep(name = "rules_python", version = "0.29.0") +bazel_dep(name = "spdlog", version = "1.12.0") +bazel_dep(name = "sqlite3", version = "3.42.0.bcr.1") +bazel_dep(name = "tinyxml2", version = "10.0.0") +bazel_dep(name = "websocketpp", version = "0.8.2") +bazel_dep(name = "yaml-cpp", version = "0.8.0") +bazel_dep(name = "zlib", version = "1.3") +bazel_dep(name = "zstd", version = "1.5.5.bcr.1") + +python = use_extension("@rules_python//python:extensions.bzl", "python") +python.toolchain( + is_default = True, + python_version = "3.11", +) +use_repo(python, "python_versions") + +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") +pip.whl_mods( + # Keep this in sync with repositories/pip_annotations.bzl + additive_build_content = """\ +cc_library( + name = "headers", + hdrs = glob(["site-packages/numpy/core/include/numpy/**/*.h"]), + includes = ["site-packages/numpy/core/include"], + deps = ["@rules_python//python/cc:current_py_cc_headers"], +) +""", + hub_name = "whl_mods_hub", + whl_name = "numpy", +) +use_repo(pip, "whl_mods_hub") +pip.parse( + hub_name = "rules_ros2_pip_deps", + python_version = "3.11", + requirements_lock = "//:requirements_lock.txt", + whl_modifications = {"@whl_mods_hub//:numpy.json": "numpy"}, +) +use_repo(pip, "rules_ros2_pip_deps") +use_repo(pip, "rules_ros2_pip_deps_311_numpy") +pip.parse( + hub_name = "rules_ros2_resolver_deps", + python_version = "3.11", + requirements_lock = "//repositories/private:resolver_requirements_lock.txt", +) +use_repo(pip, "rules_ros2_resolver_deps") + +non_module_deps = use_extension("@com_github_mvukov_rules_ros2//:extensions.bzl", "non_module_deps") +use_repo( + non_module_deps, + "cyclonedds", + "foxglove_bridge", + "iceoryx", + "osrf_pycommon", + "pybind11", + "ros2_ament_cmake_ros", + "ros2_ament_index", + "ros2_class_loader", + "ros2_common_interfaces", + "ros2_diagnostics", + "ros2_geometry2", + "ros2_image_common", + "ros2_kdl_parser", + "ros2_keyboard_handler", + "ros2_launch", + "ros2_launch_ros", + "ros2_libstatistics_collector", + "ros2_message_filters", + "ros2_pluginlib", + "ros2_rcl", + "ros2_rcl_interfaces", + "ros2_rcl_logging", + "ros2_rclcpp", + "ros2_rclpy", + "ros2_rcpputils", + "ros2_rcutils", + "ros2_resource_retriever", + "ros2_rmw", + "ros2_rmw_cyclonedds", + "ros2_rmw_dds_common", + "ros2_rmw_implementation", + "ros2_robot_state_publisher", + "ros2_ros_testing", + "ros2_rosbag2", + "ros2_rosidl", + "ros2_rosidl_python", + "ros2_rosidl_runtime_py", + "ros2_rosidl_typesupport", + "ros2_rpyutils", + "ros2_tracing", + "ros2_unique_identifier_msgs", + "ros2_urdfdom", + "ros2_urdfdom_headers", + "ros2_xacro", + "ros2cli", + "ros2", +) diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 00000000..e69de29b diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel new file mode 100644 index 00000000..09412cd6 --- /dev/null +++ b/examples/MODULE.bazel @@ -0,0 +1,66 @@ +module(name = "rules_ros2_examples") + +bazel_dep(name = "com_github_mvukov_rules_ros2") +local_path_override( + module_name = "com_github_mvukov_rules_ros2", + path = "..", +) + +non_module_deps = use_extension("@com_github_mvukov_rules_ros2//:extensions.bzl", "non_module_deps") +use_repo( + non_module_deps, + "cyclonedds", + "foxglove_bridge", + "iceoryx", + "osrf_pycommon", + "ros2_ament_cmake_ros", + "ros2_ament_index", + "ros2_class_loader", + "ros2_common_interfaces", + "ros2_diagnostics", + "ros2_geometry2", + "ros2_image_common", + "ros2_kdl_parser", + "ros2_keyboard_handler", + "ros2_launch", + "ros2_launch_ros", + "ros2_libstatistics_collector", + "ros2_message_filters", + "ros2_pluginlib", + "ros2_rcl", + "ros2_rcl_interfaces", + "ros2_rcl_logging", + "ros2_rclcpp", + "ros2_rclpy", + "ros2_rcpputils", + "ros2_rcutils", + "ros2_resource_retriever", + "ros2_rmw", + "ros2_rmw_cyclonedds", + "ros2_rmw_dds_common", + "ros2_rmw_implementation", + "ros2_robot_state_publisher", + "ros2_ros_testing", + "ros2_rosbag2", + "ros2_rosidl", + "ros2_rosidl_python", + "ros2_rosidl_runtime_py", + "ros2_rosidl_typesupport", + "ros2_rpyutils", + "ros2_tracing", + "ros2_unique_identifier_msgs", + "ros2_urdfdom", + "ros2_urdfdom_headers", + "ros2_xacro", + "ros2cli", +) + +bazel_dep(name = "rules_cc", version = "0.0.9") +bazel_dep(name = "rules_python", version = "0.29.0") + +python = use_extension("@rules_python//python:extensions.bzl", "python") +python.toolchain( + is_default = True, + python_version = "3.11", +) +use_repo(python, "python_versions") diff --git a/extensions.bzl b/extensions.bzl new file mode 100644 index 00000000..48910434 --- /dev/null +++ b/extensions.bzl @@ -0,0 +1,9 @@ +load("@com_github_mvukov_rules_ros2//repositories:repositories.bzl", "ros2_repositories", "rules_ros2_workspace_and_bazelmod_common_deps") + +def _non_module_deps_impl(mctx): + rules_ros2_workspace_and_bazelmod_common_deps() + ros2_repositories() + +non_module_deps = module_extension( + implementation = _non_module_deps_impl, +) diff --git a/renovate.json5 b/renovate.json5 index 7a99cf7e..f5e9564d 100644 --- a/renovate.json5 +++ b/renovate.json5 @@ -25,7 +25,7 @@ "eigen", "foxglove_bridge", "nlohmann_json", - "openssl", + "boringssl", "pybind11", "rules_foreign_cc", "rules_python", diff --git a/repositories/asio.BUILD.bazel b/repositories/asio.BUILD.bazel index e7745b34..9e273d70 100644 --- a/repositories/asio.BUILD.bazel +++ b/repositories/asio.BUILD.bazel @@ -5,15 +5,10 @@ load("@rules_cc//cc:defs.bzl", "cc_library") cc_library( name = "asio", - srcs = glob(["src/*.cpp"]), - hdrs = glob([ - "include/**/*.hpp", - "include/**/*.ipp", + srcs = glob([ + "**/*.hpp", + "**/*.ipp", ]), - defines = [ - "ASIO_SEPARATE_COMPILATION", - ], - includes = ["include"], + includes = ["."], visibility = ["//visibility:public"], - deps = ["@openssl//:ssl"], ) diff --git a/repositories/curl.BUILD.bazel b/repositories/curl.BUILD.bazel index 58e81917..fa71afe8 100644 --- a/repositories/curl.BUILD.bazel +++ b/repositories/curl.BUILD.bazel @@ -104,7 +104,7 @@ cp ${BUILD_TMPDIR}/lib/libcurl.a ${INSTALLDIR}/lib """, visibility = ["//visibility:public"], deps = [ - "@openssl//:ssl", + "@boringssl//:ssl", "@zlib", ], ) diff --git a/repositories/foxglove_bridge.BUILD.bazel b/repositories/foxglove_bridge.BUILD.bazel index cf20f3e2..11482669 100644 --- a/repositories/foxglove_bridge.BUILD.bazel +++ b/repositories/foxglove_bridge.BUILD.bazel @@ -26,6 +26,7 @@ cc_library( includes = ["foxglove_bridge_base/include"], deps = [ "@nlohmann_json//:json", + "@boringssl//:ssl", "@websocketpp", ], ) diff --git a/repositories/libyaml.BUILD.bazel b/repositories/libyaml.BUILD.bazel index 8cde4200..54740039 100644 --- a/repositories/libyaml.BUILD.bazel +++ b/repositories/libyaml.BUILD.bazel @@ -20,7 +20,7 @@ expand_template( ) cc_library( - name = "yaml", + name = "libyaml", srcs = [ "src/api.c", "src/dumper.c", diff --git a/repositories/pip_annotations.bzl b/repositories/pip_annotations.bzl index 980a3b1b..2691d95a 100644 --- a/repositories/pip_annotations.bzl +++ b/repositories/pip_annotations.bzl @@ -1,5 +1,6 @@ load("@rules_python//python:pip.bzl", "package_annotation") +# Keep this in sync with MODULE.bazel PIP_ANNOTATIONS = { "numpy": package_annotation( additive_build_content = """\ diff --git a/repositories/rcl.BUILD.bazel b/repositories/rcl.BUILD.bazel index 44aa9c1a..2a2258eb 100644 --- a/repositories/rcl.BUILD.bazel +++ b/repositories/rcl.BUILD.bazel @@ -13,7 +13,7 @@ ros2_c_library( includes = ["rcl_yaml_param_parser/include"], visibility = ["//visibility:public"], deps = [ - "@libyaml//:yaml", + "@libyaml", "@ros2_rcutils//:rcutils", "@ros2_rmw//:rmw", ], diff --git a/repositories/repositories.bzl b/repositories/repositories.bzl index 73ed64a0..a55a6cba 100644 --- a/repositories/repositories.bzl +++ b/repositories/repositories.bzl @@ -8,8 +8,30 @@ load( "ros2_repositories_impl", ) +def rules_ros2_workspace_and_bazelmod_common_deps(): + """Import http_archive dependencies needed for both the WORKSPACE and MODULE.bazel version of rules_ros2.""" + maybe( + http_archive, + name = "pybind11", + build_file = "@com_github_mvukov_rules_ros2//repositories:pybind11.BUILD.bazel", + sha256 = "d475978da0cdc2d43b73f30910786759d593a9d8ee05b1b6846d1eb16c6d2e0c", + strip_prefix = "pybind11-2.11.1", + urls = ["https://github.com/pybind/pybind11/archive/refs/tags/v2.11.1.tar.gz"], + ) + + maybe( + http_archive, + name = "curl", + build_file = "@com_github_mvukov_rules_ros2//repositories:curl.BUILD.bazel", + sha256 = "230d61a4b1eb3346930f2d601cc8fe5237957163e16befbe15e0ef40c56767a2", + strip_prefix = "curl-curl-8_2_1", + urls = ["https://github.com/curl/curl/archive/refs/tags/curl-8_2_1.tar.gz"], + ) + def rules_ros2_workspace_deps(): """Import http_archive dependencies for the WORKSPACE version of rules_ros2.""" + rules_ros2_workspace_and_bazelmod_common_deps() + maybe( http_archive, name = "rules_python", @@ -29,18 +51,18 @@ def rules_ros2_workspace_deps(): http_archive, name = "fmt", build_file = "@com_github_mvukov_rules_ros2//repositories:fmt.BUILD.bazel", - sha256 = "5dea48d1fcddc3ec571ce2058e13910a0d4a6bab4cc09a809d8b1dd1c88ae6f2", - strip_prefix = "fmt-9.1.0", - url = "https://github.com/fmtlib/fmt/archive/9.1.0.tar.gz", + sha256 = "1250e4cc58bf06ee631567523f48848dc4596133e163f02615c97f78bab6c811", + strip_prefix = "fmt-10.2.1", + url = "https://github.com/fmtlib/fmt/archive/10.2.1.tar.gz", ) maybe( http_archive, name = "spdlog", build_file = "@com_github_mvukov_rules_ros2//repositories:spdlog.BUILD.bazel", - sha256 = "534f2ee1a4dcbeb22249856edfb2be76a1cf4f708a20b0ac2ed090ee24cfdbc9", - strip_prefix = "spdlog-1.13.0", - url = "https://github.com/gabime/spdlog/archive/v1.13.0.tar.gz", + sha256 = "4dccf2d10f410c1e2feaff89966bfc49a1abb29ef6f08246335b110e001e09a9", + strip_prefix = "spdlog-1.12.0", + url = "https://github.com/gabime/spdlog/archive/v1.12.0.tar.gz", ) maybe( @@ -52,15 +74,6 @@ def rules_ros2_workspace_deps(): urls = ["https://github.com/yaml/libyaml/archive/acd6f6f014c25e46363e718381e0b35205df2d83.tar.gz"], ) - maybe( - http_archive, - name = "pybind11", - build_file = "@com_github_mvukov_rules_ros2//repositories:pybind11.BUILD.bazel", - sha256 = "d475978da0cdc2d43b73f30910786759d593a9d8ee05b1b6846d1eb16c6d2e0c", - strip_prefix = "pybind11-2.11.1", - urls = ["https://github.com/pybind/pybind11/archive/refs/tags/v2.11.1.tar.gz"], - ) - maybe( http_archive, name = "rules_foreign_cc", @@ -126,9 +139,9 @@ def rules_ros2_workspace_deps(): http_archive, name = "asio", build_file = "@com_github_mvukov_rules_ros2//repositories:asio.BUILD.bazel", - sha256 = "b31c63867daaba0e460ee2c85dc508a52c81db0a7318e0d2147f444b26f80ed7", - strip_prefix = "asio-asio-1-27-0/asio", - urls = ["https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-27-0.tar.gz"], + sha256 = "5705a0e403017eba276625107160498518838064a6dd7fd8b00b2e30c0ffbdee", + strip_prefix = "asio-asio-1-28-2/asio/include", + urls = ["https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-28-2.tar.gz"], ) # We're pointing at hedronvision's mirror of google/boringssl:main-with-bazel to get @@ -136,7 +149,7 @@ def rules_ros2_workspace_deps(): # support Bazel. maybe( http_archive, - name = "openssl", + name = "boringssl", sha256 = "cf1cfe0adb443ef96197b109292847c0a97304058af21f3488a323b51984608a", strip_prefix = "boringssl-e762bd792ab7fecb170bdb1cd96a0bfb0c9d3238", urls = ["https://github.com/hedronvision/boringssl/archive/e762bd792ab7fecb170bdb1cd96a0bfb0c9d3238.tar.gz"], @@ -146,12 +159,9 @@ def rules_ros2_workspace_deps(): http_archive, name = "zlib", build_file = "@com_github_mvukov_rules_ros2//repositories:zlib.BUILD.bazel", - sha256 = "d14c38e313afc35a9a8760dadf26042f51ea0f5d154b0630a31da0540107fb98", - strip_prefix = "zlib-1.2.13", - urls = [ - "https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.xz", - "https://zlib.net/zlib-1.2.13.tar.xz", - ], + sha256 = "8a9ba2898e1d0d774eca6ba5b4627a11e5588ba85c8851336eb38de4683050a7", + strip_prefix = "zlib-1.3", + urls = ["https://github.com/madler/zlib/releases/download/v1.3/zlib-1.3.tar.xz"], ) maybe( @@ -164,15 +174,6 @@ def rules_ros2_workspace_deps(): ], ) - maybe( - http_archive, - name = "curl", - build_file = "@com_github_mvukov_rules_ros2//repositories:curl.BUILD.bazel", - sha256 = "230d61a4b1eb3346930f2d601cc8fe5237957163e16befbe15e0ef40c56767a2", - strip_prefix = "curl-curl-8_2_1", - urls = ["https://github.com/curl/curl/archive/refs/tags/curl-8_2_1.tar.gz"], - ) - maybe( http_archive, name = "zstd", @@ -186,18 +187,18 @@ def rules_ros2_workspace_deps(): http_archive, name = "lz4", build_file = "@com_github_mvukov_rules_ros2//repositories:lz4.BUILD.bazel", - sha256 = "4ec935d99aa4950eadfefbd49c9fad863185ac24c32001162c44a683ef61b580", - strip_prefix = "lz4-1.9.3", - urls = ["https://github.com/lz4/lz4/archive/refs/tags/v1.9.3.zip"], + sha256 = "0b0e3aa07c8c063ddf40b082bdf7e37a1562bda40a0ff5272957f3e987e0e54b", + strip_prefix = "lz4-1.9.4", + urls = ["https://github.com/lz4/lz4/archive/refs/tags/v1.9.4.tar.gz"], ) maybe( http_archive, name = "yaml-cpp", build_file = "@com_github_mvukov_rules_ros2//repositories:yaml-cpp.BUILD.bazel", - sha256 = "43e6a9fcb146ad871515f0d0873947e5d497a1c9c60c58cb102a97b47208b7c3", - strip_prefix = "yaml-cpp-yaml-cpp-0.7.0", - urls = ["https://github.com/jbeder/yaml-cpp/archive/yaml-cpp-0.7.0.tar.gz"], + sha256 = "fbe74bbdcee21d656715688706da3c8becfd946d92cd44705cc6098bb23b3a16", + strip_prefix = "yaml-cpp-0.8.0", + urls = ["https://github.com/jbeder/yaml-cpp/archive/refs/tags/0.8.0.tar.gz"], ) maybe( diff --git a/ros2/interfaces.bzl b/ros2/interfaces.bzl index 9b242906..0702bda9 100644 --- a/ros2/interfaces.bzl +++ b/ros2/interfaces.bzl @@ -18,6 +18,7 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load("@com_github_mvukov_rules_ros2//ros2:cc_opts.bzl", "CPP_COPTS", "C_COPTS") load("@rules_cc//cc:toolchain_utils.bzl", "find_cpp_toolchain") load("@rules_python//python:defs.bzl", "py_library") +load("@rules_python//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") load("@rules_ros2_pip_deps//:requirements.bzl", "requirement") Ros2InterfaceInfo = provider( @@ -822,7 +823,7 @@ py_generator_aspect = aspect( "_py_ext_c_deps": attr.label_list( default = [ Label("@rules_python//python/cc:current_py_cc_headers"), - Label("@rules_ros2_pip_deps_numpy//:headers"), + Label("@rules_ros2_pip_deps" + ("_311" if BZLMOD_ENABLED else "") + "_numpy//:headers"), ], providers = [CcInfo], ),