ros-controls / ros2_controllers

Generic robotic controllers to accompany ros2_control
https://control.ros.org
Apache License 2.0
344 stars 310 forks source link

Cleanup visibility to enable compilation on Windows #1053

Open traversaro opened 6 months ago

traversaro commented 6 months ago

I would like to compile and run the software of this repo on Windows. I was able to do so with https://github.com/ros-controls/ros2_controllers/pull/1039 and https://github.com/ros-controls/ros2_control/compare/master...traversaro:ros2_control:patch-2 . However, given the comments in https://github.com/ros-controls/ros2_controllers/pull/1039#discussion_r1485948944, I thought it made sense to open an issue to discuss what is the preferred way to handle visibility of symbols on Windows.

Describe the solution you'd like

Differently from Linux and macOS, on Windows by default the symbols of shared libraries are not exported. To deal with this, there are several strategies:

Unless the shared library is particularly big, I typically prefer to adopt S1, as it is the strategy that put the least possible burden of library maintainers and authors, especially if most of them is not familiar with Windows. If S2 or S3 are used, I personally prefer at least to make sure that the visibility is hidden by default also on Linux and macOS, to permit developers to make sure that the visibility macros are working appropriately even without using Windows.

For some reasons (some discussed in https://github.com/ament/ament_cmake/issues/201#issuecomment-542808202 and https://github.com/ament/ament_cmake/issues/164) core ros2 packages use the S3 strategy, even if only a subset of packages actually set the visibility to hidden in non-Windows platforms (see https://github.com/search?q=org%3Aros2+hidden+language%3ACMake&type=code). Apparently the S3 strategy is used also on ros2_control repos.

Given this discussion, I would like to know what maintainers prefer:

christophfroehlich commented 6 months ago

Thanks for this detailed explanation: Finally I understand why this is necessary at all (ping https://github.com/ros-controls/ros2_control_demos/issues/73 :wink:) I vote for S2 + default hidden, but I'm not a qualified software engineer.

fyi: I added this to the agenda of the working group meeting next week, let's discuss it there if no one comments here until then.

traversaro commented 6 months ago

fyi: I added this to the agenda of the working group meeting next week, let's discuss it there if no one comments here until then.

Ok, I will try to attend so we can discuss/explain if anyone has specific questions, thanks!

destogl commented 6 months ago

I would go with S3 and fix all the issues we currently have.

traversaro commented 6 months ago

I would go with S3 and fix all the issues we currently have.

I kind of have already patches for this, see:

The tricky aspect is that the classes have a lot of protected methods, that technically are part of the public interface. I added patches for all the protected methods (as for example on_set_chained_mode needs to be exported) while I did not exported any protected attribute, that worked but I am not sure if that was just luck or it is kind of aligned with the actual usage.

bmagyar commented 6 months ago

The discussion on this topic at the WG meeting yesterday concluded with Option S1.

Does the S stand for Silvio? ;) @traversaro

traversaro commented 6 months ago

Does the S stand for Silvio? ;) @traversaro

I had to think a bit about it. :D I think it wanted to stand for "Solution".

traversaro commented 6 months ago

As S1 was decided, I realized that there are a few decision to make:

christophfroehlich commented 6 months ago

sidenote: I'd remove them from the demos soon, because we don't release the demos repos and can easily get rid of the boilerplate code there for every distro.

christophfroehlich commented 1 month ago

@traversaro did you have time to work on this? as we are preparing more breaking stuff on rolling, now it's the time to break even more ;)

traversaro commented 1 month ago

@traversaro did you have time to work on this? as we are preparing more breaking stuff on rolling, now it's the time to break even more ;)

Cool! With summer coming I hope to be able to prepare some PRs on this, thanks for the ping!