mvukov / rules_ros2

Build ROS 2 with Bazel
Apache License 2.0
81 stars 45 forks source link

Unable to build using Zig hermetic toolchain (linker cannot find library -latomic) #167

Closed tervay-bdai closed 11 months ago

tervay-bdai commented 1 year ago

Hi, thanks for your work on this, it is overall a great library.

We are using Uber's hermetic CC toolchain to compile and are unable to get simple python scripts depending on rclpy to build. A minimal reproduction can be found here: https://github.com/tervay-bdai/zig-linking-repro

$ bazelisk run //src:ex

INFO: Analyzed target //src:ex (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /home/jtervay/.cache/bazel/_bazel_jtervay/2ba880a27a7b10a0e8a3abfc5bd990ba/external/ros2_rclpy/BUILD.bazel:11:16: Linking external/ros2_rclpy/rclpy/rclpy/_rclpy_pybind11.so failed: (Exit 1): c++ failed: error executing command (from target @ros2_rclpy//:rclpy/rclpy/_rclpy_pybind11.so) external/zig_sdk/tools/x86_64-linux-gnu.2.34/c++ -shared -o bazel-out/k8-fastbuild-ST-35841e508e03/bin/external/ros2_rclpy/rclpy/rclpy/_rclpy_pybind11.so ... (remaining 59 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
ld.lld: error: unable to find library -latomic
Target //src:ex failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.504s, Critical Path: 0.30s
INFO: 3 processes: 3 internal.
FAILED: Build did NOT complete successfully
ERROR: Build failed. Not running target

I am truthfully not sure if this problem lies within the toolchain or within rules_ros2. It seems that when building with this toolchain, it's not able to find the atomic library, even though mentions of it seem to be found in the generated bazel directories.

The line from rules_ros2 causing the problem is here: https://github.com/mvukov/rules_ros2/blob/a3e124988e8215f505bee467c73074e6f7c72dee/repositories/rclpy.BUILD.bazel#L21

I've tried patching the flag out, but it results in an illegal operation runtime error, so I assume the flag is actually required and patching it out doesn't actually solve anything.

Guidance would be appreciated here, if any; I can also file an issue on the Zig toolchain repo but again, I'm not sure where the problem actually is.

mvukov commented 1 year ago

Hi, on Ubuntu the library is provided via apt in libatomic1 package. I guess you also need to have this library in the rootfs the compiler works on.

mvukov commented 1 year ago

Any progress here?

mvukov commented 1 year ago

Can it be that with zig/cc you don't need to link -latomic, like is the case with android/qnx?

tervay-bdai commented 1 year ago

Unfortunately no, no progress. Had to revert to clang toolchains in the meantime to unblock other things.

mvukov commented 11 months ago

OK, let's close this for now then.