Skip to content
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 #1414

Merged
merged 3 commits into from
Aug 16, 2024
Merged

Conversation

traversaro
Copy link
Contributor

Closes part of gazebosim/gz-sim#626

Summary

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.

Furthermore, this PR also deprecates the SDF_SHARE_PATH macro, using the strategy described in https://stackoverflow.com/a/29297970 . That strategy works fine on GCC and Clang, while on MSVC it raise a warning:

warning C4068: unknown pragma

However, I think that it does anyhow the job of raising some kind of warning, and then at soon as the developer checks the macro definition the kind of warning is clear.

The PR also deprecates the SDF_VERSION_PATH macro without providing any replacement. This is done as at the moment the SDF_VERSION_PATH points to a non-existent directory:

#ifndef SDF_VERSION_PATH
#define SDF_VERSION_PATH "/home/traversaro/miniforge3/envs/sdformat14/share/sdformat14/14.2"
#endif

so I guess it is mostly unused, and it can be safely deprecated.

Similarly to gazebosim/gz-physics#507, a local copy of joinPaths is imported to avoid to add a dependency on gz-common.

Test it

The test should work as usual. The used CMake machinery is tested in gazebosim/gz-cmake#334 .

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

@github-actions github-actions bot added the 🎵 harmonic Gazebo Harmonic label May 13, 2024
@traversaro
Copy link
Contributor Author

cc @xela-95

@mjcarroll I guess the bazel build system needs to be adapted to this change, do you have any pointer on how I could do that? Thanks!

Signed-off-by: Silvio Traversaro <silvio@traversaro.it>
@traversaro
Copy link
Contributor Author

@mjcarroll I guess the bazel build system needs to be adapted to this change, do you have any pointer on how I could do that? Thanks!

Friendly ping @mjcarroll, thanks!

@azeey azeey added the beta Targeting beta release of upcoming collection label Jul 29, 2024
@iche033
Copy link
Contributor

iche033 commented Aug 13, 2024

changes look good to me. Perhaps we can get this in first and adapt the changes to bzl as a follow-on task?

@traversaro
Copy link
Contributor Author

changes look good to me. Perhaps we can get this in first and adapt the changes to bzl as a follow-on task?

Ok for me!

@azeey azeey merged commit 7404b55 into gazebosim:sdf14 Aug 16, 2024
11 checks passed
@scpeters
Copy link
Member

I've started seeing windows builds of downstream packages fail since this was merged:

InstallationDirectories.obj :
 error LNK2001: unresolved external symbol __imp_PathCombineA
 [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
# BEGIN SECTION: colcon compilation without test for dependencies of gz-physics7
"COLCON_EXTRA_ARGS: --packages-skip gz-physics7"
"COLCON_EXTRA_CMAKE_ARGS: "-DBUILD_TESTING=0""
"COLCON_EXTRA_CMAKE_ARGS2: "-DCMAKE_CXX_FLAGS=-w""
...
--- output: sdformat14
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.20348.
-- The C compiler identification is MSVC 19.29.30148.0
-- The CXX compiler identification is MSVC 19.29.30148.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- sdformat14 version 14.5.0
-- Operating system is Windows
-- Checking for module 'tinyxml2'
--   Found tinyxml2, version 9.0.0
-- Looking for TINYXML2 - found

-- Looking for urdfdom - not found

-- Looking for urdfdom - not found

-- Using internal URDF
-- Found Python3: C:/vcpkg/installed/x64-windows/tools/python3/python.exe (found version "3.10.1") found components: Interpreter Development Development.Module Development.Embed 
-- Performing Test HAS_MSVC_GL_LTCG
-- Performing Test HAS_MSVC_GL_LTCG - Success
-- Searching for pybind11 - found version 2.9.1.
-- Could NOT find PY_psutil (missing: PY_PSUTIL) 
-- Looking for gz-math7 -- found version 7.5.0
-- Searching for dependencies of gz-math7
-- Looking for gz-utils2 -- found version 2.2.0
-- Searching for dependencies of gz-utils2
-- Looking for gz-math7 - found

-- Looking for gz-utils2 -- found version 2.2.0
-- Searching for dependencies of gz-utils2
-- Searching for <gz-utils2> component [cli]
-- Looking for gz-utils2-cli -- found version 2.2.0
-- Searching for dependencies of gz-utils2-cli
-- Looking for gz-utils2 - found

CMake Warning at C:/J/workspace/gz_physics-7-win/ws/install/gz-cmake3/share/cmake/gz-cmake3/cmake3/GzConfigureBuild.cmake:68 (message):
   CONFIGURATION WARNINGS:
   -- Python psutil package not found. Memory leak tests will be skipped
Call Stack (most recent call first):
  CMakeLists.txt:155 (gz_configure_build)


-- Configuring library: sdformat14
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
-- Performing Test COMPILER_HAS_DEPRECATED
-- Performing Test COMPILER_HAS_DEPRECATED - Success
-- The program [cppcheck] was not found! Skipping codecheck setup
-- Build configuration successful
-- Build type: Release
-- Install prefix: C:/J/workspace/gz_physics-7-win/ws/install/sdformat14
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
-- Configuration successful. Type make to compile sdf
-- Configuring done
-- Generating done
-- Build files have been written to: C:/J/workspace/gz_physics-7-win/ws/build/sdformat14
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework

Copyright (C) Microsoft Corporation. All rights reserved.



  Checking Build System

  Building Custom Rule C:/J/workspace/gz_physics-7-win/ws/sdformat/src/CMakeLists.txt

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

  Actor.cc

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

  AirPressure.cc

  AirSpeed.cc

  Altimeter.cc

  Atmosphere.cc

  Box.cc

  Camera.cc

  Capsule.cc

  Collision.cc

  Cone.cc

  Console.cc

  Converter.cc

  CustomInertiaCalcProperties.cc

  Cylinder.cc

  Element.cc

  Ellipsoid.cc

  Error.cc

  Exception.cc

  Filesystem.cc

  ForceTorque.cc

  Frame.cc

  FrameSemantics.cc

  Geometry.cc

  Gui.cc

  Heightmap.cc

  Imu.cc

  InterfaceElements.cc

  InterfaceFrame.cc

  InterfaceJoint.cc

  InterfaceLink.cc

  InterfaceModel.cc

  InterfaceModelPoseGraph.cc

  JointAxis.cc

  Lidar.cc

  Light.cc

  Magnetometer.cc

  Material.cc

  Mesh.cc

  NavSat.cc

  Noise.cc

  OutputConfig.cc

  Param.cc

  ParamPassing.cc

  ParserConfig.cc

  ParticleEmitter.cc

  Pbr.cc

  Physics.cc

  Plane.cc

  Plugin.cc

  Polyline.cc

  PrintConfig.cc

  Projector.cc

  Root.cc

  SDF.cc

  SDFExtension.cc

  Scene.cc

  SemanticPose.cc

  Sensor.cc

  Sky.cc

  Sphere.cc

  Surface.cc

  Types.cc

  Utils.cc

  Visual.cc

  XmlUtils.cc

  gz.cc

  parser.cc

  parser_urdf.cc

  EmbeddedSdf.cc

  pose.cpp

  twist.cpp

  urdf_model_state.cpp

  urdf_sensor.cpp

  sdformat14_get_install_prefix_impl.cc

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

  InstallationDirectories.cc

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

  Joint.cc

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

  Link.cc

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

  Model.cc

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

  World.cc

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

  model.cpp

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

  link.cpp

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

  joint.cpp

cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

  world.cpp

  Actor.obj : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance

     Creating library C:/J/workspace/gz_physics-7-win/ws/build/sdformat14/lib/Release/sdformat14.lib and object C:/J/workspace/gz_physics-7-win/ws/build/sdformat14/lib/Release/sdformat14.exp

InstallationDirectories.obj : error LNK2001: unresolved external symbol __imp_PathCombineA [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\bin\Release\sdformat14.dll : fatal error LNK1120: 1 unresolved externals [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]

@@ -91,6 +109,11 @@ if (BUILD_TESTING)
-DGZ_SDFORMAT_STATIC_DEFINE
)

if(WIN32)
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PRIVATE shlwapi)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this needs to be public?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually this target_link_libraries call is inside if (BUILD_TESTING), but it should no depend on the value of BUILD_TESTING. I'll submit a PR shortly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix in #1468

@iche033
Copy link
Contributor

iche033 commented Aug 19, 2024

The note on the joinPaths function says it's copied from ign-common4. May we can update the code to use a copy of the joinPaths code from gz-common5 instead? It uses std::filesystem and does not have platform specific ifdefs

@traversaro
Copy link
Contributor Author

The note on the joinPaths function says it's copied from ign-common4. May we can update the code to use a copy of the joinPaths code from gz-common5 instead? It uses std::filesystem and does not have platform specific ifdefs

Originally this was done to avoid to link std::filesystem that created ABI problems in Ubuntu 20.04, if we dropped support for that I guess we can use std::filesystem.

@scpeters
Copy link
Member

The note on the joinPaths function says it's copied from ign-common4. May we can update the code to use a copy of the joinPaths code from gz-common5 instead? It uses std::filesystem and does not have platform specific ifdefs

Originally this was done to avoid to link std::filesystem that created ABI problems in Ubuntu 20.04, if we dropped support for that I guess we can use std::filesystem.

Gazebo Harmonic and up don't support 20.04, so yeah, we could copy the gz-common joinPaths implementation with std::filesystem as an alternative to shlwapi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta Targeting beta release of upcoming collection 🎵 harmonic Gazebo Harmonic
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants