mvukov / rules_ros

Build ROS (1) with Bazel
Apache License 2.0
24 stars 12 forks source link

Add support for LZ4 compressed rosbags to the `py_rosbag` target #63

Open jmauthe opened 1 month ago

jmauthe commented 1 month ago

To read LZ4 compressed rosbags via the py_rosbag target from Python, the roslz4 module needs to be passed as a dependency, as it is dynamically loaded during the imports of the bag.py module. See, in the bag.py implementation in the ros_comm repository.

Can we please add this support to the rule set here?

mvukov commented 3 weeks ago

Sounds good to me. Please feel free to impl this and open a PR.

jmauthe commented 1 week ago

I've started implementing on this. These are the changes I currently have for the ros_comm.BUILD.bazel:

diff --git a/ros/repositories/ros_comm.BUILD.bazel b/ros/repositories/ros_comm.BUILD.bazel
index 29a8062..5ad229e 100644
--- a/ros/repositories/ros_comm.BUILD.bazel
+++ b/ros/repositories/ros_comm.BUILD.bazel
@@ -239,6 +239,40 @@ cc_ros_library(
     ],
 )

+
+cc_ros_library(
+    name = "roslz4_py_lib",
+    srcs = ["utilities/roslz4/src/_roslz4module.c"],
+    visibility = ["//visibility:public"],
+    copts = ["-Wno-missing-field-initializers", "-Wno-unused-variable", "-Wno-strict-aliasing"],
+    deps = [
+        ":roslz4",
+        "@roscpp_core//:cpp_common",
+        "@rules_python//python/cc:current_py_cc_headers"
+    ],
+)
+
+cc_binary(
+    name = "_roslz4.so",
+    linkshared = 1,
+    deps = [":roslz4_py_lib"],
+)
+
+genrule(
+    name = "copy_roslz4_py_so",
+    srcs = ["_roslz4.so"],
+    outs = ["utilities/roslz4/src/roslz4/_roslz4.so"],
+    cmd = "cp $< $@",
+)
+
+py_library(
+    name = "roslz4_py",
+    srcs = glob(["utilities/roslz4/**/*.py"]),
+    imports = ["utilities/roslz4/src"],
+    data = [":copy_roslz4_py_so"],
+    visibility = ["//visibility:public"],
+)
+
 cc_ros_library(
     name = "rosbag_storage",
     srcs = [
@@ -349,6 +383,7 @@ py_library(
     deps = [
         ":py_topic_tools",
         ":rospy",
+        ":roslz4_py",
         "@rules_ros//third_party/ros:roslib",
         requirement("gnupg"),
         requirement("pycryptodomex"),

I'm currently struggling when importing the python bag module, which tries to load the _roslz4 module. There I get the following error: dynamic module does not define module export function (PyInit__roslz4) So it seems python does not find the init function in the shared object file, which should be there Any idea what is causing this?

I can also open a PR if it's easier to discuss there.