-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add visibility control to all packages #405
Add visibility control to all packages #405
Conversation
bf61477
to
de88435
Compare
0b89a7c
to
ed9e4e7
Compare
a468ffc
to
4c7260c
Compare
Codecov Report
@@ Coverage Diff @@
## feature/CommandLanguage #405 +/- ##
===========================================================
- Coverage 75.46% 75.43% -0.04%
===========================================================
Files 204 204
Lines 12204 12204
===========================================================
- Hits 9210 9206 -4
- Misses 2994 2998 +4
|
@colin-lewis-19 and @marrts Do either of you have time to review this? This does not contain changes to code just setting symbol visibility. |
@Levi-Armstrong Is this how packages like PCL handle it? |
I am not sure how PCL does it but it should be similar. There is a global way to expose all symbols which may be what they are doing, but this approach is the preferred way. This was copied form rclcpp, which i copied from GCC website. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how PCL does it but it should be similar. There is a global way to expose all symbols which may be what they are doing, but this approach is the preferred way. This was copied form rclcpp, which i copied from GCC website.
Do IDEs get confused? This isn't going to make code development painful is it?
Edit: Still reviewing. I guess it took this comment as meaning I was done with the review.
@@ -23,6 +23,10 @@ | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
macro(tesseract_variables) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a new macro? I don't remember it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how PCL does it but it should be similar. There is a global way to expose all symbols which may be what they are doing, but this approach is the preferred way. This was copied form rclcpp, which i copied from GCC website.
Do IDEs get confused? This isn't going to make code development painful is it?
Edit: Still reviewing. I guess it took this comment as meaning I was done with the review.
I don't believe so. If you want a class or global function to visible you just need to add TESSERACT_PUBLIC and if it is not supposed to be visible you add TESSERACT_LOCAL and that is pretty much it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a new macro? I don't remember it.
No it was added as part of the switch to cmake_common_scripts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if visibility is turned off, then a target that links it will not be able to see it? Could we just default them to visible and set the ones we want private (since there are only a few). I assume not since that is basically what we had before just with none set not visible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me assuming this is the overall approach you want to go with. I did not check for missing objects. I just checked the ones you changed.
#ifdef TESSERACT_BUILDING_LIBRARY | ||
#define TESSERACT_PUBLIC TESSERACT_EXPORT | ||
#else | ||
#define TESSERACT_PUBLIC TESSERACT_IMPORT | ||
#endif | ||
#define TESSERACT_PUBLIC_TYPE TESSERACT_PUBLIC | ||
#define TESSERACT_LOCAL | ||
#else | ||
#define TESSERACT_EXPORT __attribute__ ((visibility("default"))) | ||
#define TESSERACT_IMPORT | ||
#if __GNUC__ >= 4 | ||
#define TESSERACT_PUBLIC __attribute__ ((visibility("default"))) | ||
#define TESSERACT_LOCAL __attribute__ ((visibility("hidden"))) | ||
#else | ||
#define TESSERACT_PUBLIC | ||
#define TESSERACT_LOCAL | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there documentation about when to use these? Perhaps we should start a contribution guide like github keeps bugging us about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just at the bottom of the GCC link provided. Basically it is the three cases below. Inline, typedefs, templates, enum, const, static variable,functions or classes do not require anything.
class TESSERACT_PUBLIC|TESSERACT_LOCAL ....
struct TESSERACT_PUBLIC|TESSERACT_LOCAL ....
TESSERACT_PUBLIC|TESSERACT_LOCAL void foo();
set(CMAKE_CXX_VISIBILITY_PRESET hidden) | ||
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these just go in tesseract_variables()? Or is that too general?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think tat should be fine. I will add it there and remove it from the cmake files.
...s/include/tesseract_motion_planners/descartes/problem_generators/default_problem_generator.h
Outdated
Show resolved
Hide resolved
#ifndef TESSERACT_MOTION_PLANNERS_LVS_INTERPOLATION_H | ||
#define TESSERACT_MOTION_PLANNERS_LVS_INTERPOLATION_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an interesting bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I am not sure how this was working but when I disabled visibility it just would not work and took a while to figure out what was going on.
Small note on this. Most of the ros2 code copies the code from https://gcc.gnu.org/wiki/Visibility that is described as "Some examples of the syntax:", but that code unfortunately does not work well when compiling static libraries under Windows/MSVC. The more complete version is indeed still in https://gcc.gnu.org/wiki/Visibility, but at the bottom, under the "Step-by-step guide", that contains the complete example that works correctly also for static libraries on Windows/MSVC. See ament/ament_cmake#201 (comment) . Note that this is not a big problem if you are not interesting in supporting compilation as static library under Windows/MSVC. |
Yea I am using the full one that you recommended supporting creating static libraries. |
@traversaro In your example it has RCLCPP_BUILD_STATIC_LIBRARY and RCLCPP_BUILD_SHARED_LIBRARY which I just added to mine, but curious why this does not just leverage BUILD_SHARED_LIBS to check if static or shared? |
If you refer to ament/ament_cmake#201 (comment), it is because the |
@traversaro Sorry one more question. Does RCLCPP_BUILD_STATIC_LIBRARY or RCLCPP_BUILD_SHARED_LIBRARY need to be provided with the target for those linking against your library or can they be private?
or should I just do this setting default behavior?
|
I guess from my example you refer to |
I am not sure I understand what you mean here. |
@traversaro I believe the the changes in the latest commit should now enable the support of static libraries? |
I am probably missing something, but you should have a different visibility header for each library, as the symbol that is exported in a library is the same symbol that is imported in another library, so you can't use the same visibility header (or the same visibility macros) for all libraries. |
Oh, I was not aware. |
@traversaro I went through and made the switch such that every library has its own export header but I did have one question. Because my headers now have "<target_name>_export.h", I had to change the target include directories |
I found a way around changing the install include paths setting the export file name.
|
4163389
to
c76c373
Compare
@traversaro I switch everything to using the generate_export_headers, thanks for the help. |
d80dfdb
to
a025edf
Compare
@traversaro I switched to using the generate_export_headers, but it only appears to work on Focal, the Bionic and Xenial seem to fail for odd reasons. Have you ever experienced this? |
f318228
to
16aece1
Compare
Well I could not figure out what was going on when using the generate_export_header so I went back an manually added the visibility control file for every target and everything is building and the tests are passing. |
This makes all symbols hidden as default and uses visibility control to expose symbols to have the same behavior building on Linux as it is on Windows.