-
Notifications
You must be signed in to change notification settings - Fork 31
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 optional binary relocatability in downstream libraries #334
Conversation
I see several CI errors on Bionic and Focal, and I did not consider appropriately the effect of this targeting Fortress, while using std::filesystem, see gazebo-tooling/release-tools#639 . I need to think a bit about it, for the time being I will put this PR in draft. |
Can we avoid |
Thanks for tackling this! Thinking more about the filesystem issue. This package doesn't have a dependency on gz-common (rather the inverse), so that isn't really an option here. One option would be to push this to gz-cmake3 and drop the Alternatively, we can push all of this functionality into |
Sorry for the late reply @mjcarroll !
From what I understand from gazebo-tooling/release-tools#639, we have a similar mixture of some libraries compiled with gcc-8, some with gcc-9 and std::filesystem being ABI stable only since gcc-9 (so there is an ABI breakage between gcc-8 and gcc-9) also on Focal, or I am missing something? Migrating this functionality to gz-common and to use gz-common's filesystem is indeed an option, at a first glance it seems that all libraries that currently hardcode their CMAKE_INSTALL_PREFIX already depend on common. However, at the moment gz-common does not currently install CMake functions or any CMake module, so probably we would need to modify something at the CMAke level (see #331). Another possible option is to:
In this way, all the official builds (apt and homebrew) of the ignition/gazebo libraries will continue to hardcode Instead, packagers that mantain build of gazebo for which relocatability is important (such as conda-forge, conan-center-index, vcpkg, snap, flatpack, etc, etc) can enable the option After that, we can switch the default value of @mjcarroll feel free to let me know which option do you prefer, if moving everything to gz-common or the option I proposed, thanks! |
Gentle ping on this, I would be happy to implement what do you prefer. For a quick TL;DR, the options are:
I prefer option 2 to minimize the risk of breaking something for apt and homebrew users. |
I'm inclined towards option 2, but let me reread the proposal and bring it up with the team before we make a decision. I should have an answer for you by Tuesday of next week. |
Great, thanks! |
Did you have the occasion to check this? Sorry for being the "any update?" guy here : ), but unfortunatly given the nature of the change it is tricky to just integrate it in form of patch in conda-forge and then propose it upstream once we have it already working on conda-forge. If it make it simpler we can also have an alignment call on this on |
Discussion:
|
0b09325
to
8f89f08
Compare
Signed-off-by: Silvio Traversaro <silvio.traversaro@iit.it>
Done, sorry for the long way.
Done in gazebosim/gz-rendering#804, in general it can be handled in similar way for other downstream libraries.
For what regards the installation prefix, this PR adds a way to override it with env variables, while for other existing variables this is not strictly related to this PR. The PR is ready for review, and the original description was updated to reflect the latest changes. |
There are some warnings on Windows, I will fix them this (european) evening. |
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.
The whole approach and the PR looks great to me, thanks Silvio for pushing the relocatable effort. I added some minor comments to the PR, can not find any particular error.
I would say that would be great to have a Changelog.md
entry for this PR so people knows that the new functions are available. The CI scripts would need to define GZ_DISABLE_RELOCATABLE
to ON
in order to enable the test of this new feature.
There are some warnings on Windows, I will fix them this (european) evening.
I see the code usingstd::getenv
and not getenv
so my first impression is that the standard library implemented should be doing the right thing. Is there any particular reason to consider the warning as valid?
# value of CMAKE_INSTALL_PREFIX that was hardcoded in the library at compilation time | ||
# | ||
# As in some cases it is important to have the ability to control and change the value returned by | ||
# the GET_INSTALL_PREFIX_FUNCTION at runtime, in both cases the library returns the value of |
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.
Could we add please the documentation for the GET_INSTALL_PREFIX_FUNCTION
, GET_INSTALL_PREFIX_HEADER
and OVERRIDE_INSTALL_PREFIX_ENV_VARIABLE
using the same format that the rest of the GzUtils file?
snippet from gz_build_executables
#################################################
# gz_build_executables(SOURCES <sources>
# [PREFIX <prefix>]
# [LIB_DEPS <library_dependencies>]
# [INCLUDE_DIRS <include_dependencies>]
# [EXEC_LIST <output_var>]
# [EXCLUDE_PROJECT_LIB])
#
# Build executables for an Gazebo project. Arguments are as follows:
#
# SOURCES: Required. The names (without a path) of the source files for your
# executables.
#
# PREFIX: Optional. This will append <prefix> onto each executable name.
#
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.
Done in d7708fc . After writing the "Example" part, I wonder if it could make sense to make the arguments optional, and use as default values the one that I put as example. What do you think?
Done in d7708fc . |
I agree, for that reason I just added a suppression for the warning, just for that specific generated file. |
Co-authored-by: Jose Luis Rivero <jrivero@osrfoundation.org> Signed-off-by: Silvio Traversaro <silvio.traversaro@iit.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.
Nothing more to add. Thanks again Silvio, awesome work.
I did not realized that, but this added a dependency on |
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
This PR uses the changes introduced in gz-cmake3 in gazebosim/gz-cmake#334 to support the cmake installation directory to be moved after the make install prefix, and continue to work without the need to set any special environment variable, as long as the library is compiled as shared. To avoid regressions and problems in Ubuntu Focal due to the use of std::filesystem, this new behaviour is only activated if the GZ_ENABLE_RELOCATABLE_INSTALL option is enabled, and its default value is OFF . In particular, this PR defines a sdf::getSharePath() function that should be used in place of the SDF_SHARE_PATH macro to ensure that the library is relocatable. Signed-off-by: Silvio Traversaro <silvio@traversaro.it> Co-authored-by: Steve Peters <scpeters@openrobotics.org> Co-authored-by: Ian Chen <ichen@openrobotics.org>
🎉 New feature
Closes part of gazebosim/gz-sim#626
Summary
This PR add functionality in gz-cmake3 that permit to enable binary relocatability in downstream Gazebo libraries.
In particular it:
Adds the
gz_add_get_install_prefix_impl
CMake function, that can be used in downstream libraries to genate at CMake generation time the implementation of agz::<libraryname>::getInstallPrefix()
method. This method permits to compute the installation prefix (i.e. the value ofCMAKE_INSTALL_PREFIX
is a relocatable way, as follows:dlfcn
'sdladdr
function, and knowing the relative install location of the shared library.${CMAKE_INSTALL_PREFIX}
used at CMake configuration time in the library.GZ_ENABLE_RELOCATABLE_INSTALL
CMake option toON
in the project that callsgz_add_get_install_prefix_impl
(the default value isOFF
, as the relocatability logic requires std::filesystem that can create problems due to the mixture of gcc-8 and gcc-9 used in Ubuntu Focal packaging of gz libraries, see Add optional binary relocatability in downstream libraries #334 (comment))gz::<libraryname>::getInstallPrefix()
function can be overriden by defining theGZ_<uppercaselibraryname>_INSTALL_PREFIX
. This feature has two main use cases:gz::<libraryname>::getInstallPrefix()
have been moved to a directory different from theCMAKE_INSTALL_PREFIX
used at CMake configuration timegz::<libraryname>::getInstallPrefix()
to point to the correct installation prefix, not to so location in the build directory in which the expected files are not there. We can achieve this by settingENVIRONMENT GZ_<uppercaselibraryname>_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
for the test suite of a given ignition/gazebo library.Adds the
ENVIRONMENT
option in thegz_build_tests
function, to support the use case described in the previous bullet point.Test it
The PR contains test for the
gz_add_get_install_prefix_impl
CMake function that it adds, as long asGZ_ENABLE_RELOCATABLE_INSTALL
is enable in gz-cmake. Furthermore, the first downstream PR that uses it in an actual Gazebo library is gazebosim/gz-rendering#804 .Checklist
codecheck
passed (See contributing)