Fix cross-compiling ROS2 packages.

This commit is contained in:
Ben Wolsieffer 2022-09-23 18:29:03 -04:00
parent 93cf5a5ba4
commit 87396617b9
5 changed files with 47 additions and 5 deletions

View file

@ -2,8 +2,5 @@
makeSetupHook {
name = "ament-cmake-core-setup-hook";
substitutions = {
python_major = python.sourceVersion.major;
python_executable = python.pythonForBuild.interpreter;
};
substitutions.python_executable = python.pythonForBuild.interpreter;
} ./setup-hook.sh

View file

@ -28,6 +28,6 @@ _amentCmakeCorePreConfigureHook() {
# and just bloats the closure.
cmakeFlags+=" -DAMENT_CMAKE_ENVIRONMENT_PARENT_PREFIX_PATH_GENERATION:BOOL=OFF"
# Point CMake at build platform Python so it can run it at build time
cmakeFlags+=" -DPython@python_major@_EXECUTABLE:FILEPATH=@python_executable@"
cmakeFlags+=" -DPython3_EXECUTABLE:FILEPATH=@python_executable@"
}
preConfigureHooks+=(_amentCmakeCorePreConfigureHook)

View file

@ -267,6 +267,15 @@ let
pr2-tilt-laser-interface = patchBoostSignals rosSuper.pr2-tilt-laser-interface;
python-cmake-module = rosSuper.python-cmake-module.overrideAttrs ({ ... }: let
python = rosSelf.python;
in {
pythonExecutable = python.pythonForBuild.interpreter;
pythonLibrary = "${python}/lib/lib${python.libPrefix}.so";
pythonIncludeDir = "${python}/include/${python.libPrefix}";
setupHook = ./python-cmake-module-setup-hook.sh;
});
python-qt-binding = rosSuper.python-qt-binding.overrideAttrs ({
propagatedNativeBuildInputs ? [],
postPatch ? "", ...
@ -291,6 +300,30 @@ let
roscpp = patchBoostSignals rosSuper.roscpp;
rosidl-generator-py = rosSuper.rosidl-generator-py.overrideAttrs ({
postPatch ? "",
patches ? [], ...
}: let
python = rosSelf.python;
in {
patches = patches ++ [
# Remove stray numpy import in template
# https://github.com/ros2/rosidl_python/pull/185
(self.fetchpatch {
url = "https://github.com/ros2/rosidl_python/commit/bf866089baeb918834d9d16e05668d9f28887b87.patch";
hash = "sha256-tOb0t50TbV29+agDupm5XUZJJErfaujgIRtmb2vZxWo=";
stripLen = 1;
})
];
# Fix finding NumPy headers
postPatch = postPatch + ''
substituteInPlace cmake/rosidl_generator_py_generate_interfaces.cmake \
--replace '"import numpy"' "" \
--replace 'numpy.get_include()' "'${python.pkgs.numpy}/${python.sitePackages}/numpy/core/include'"
'';
setupHook = ./rosidl-generator-py-setup-hook.sh;
});
rmw-implementation = rosSuper.rmw-implementation.overrideAttrs ({
propagatedBuildInputs ? [], ...
}: {

View file

@ -0,0 +1,6 @@
_pythonCmakeModulePreConfigureHook() {
cmakeFlags+=" -DPYTHON_EXECUTABLE=@pythonExecutable@"
cmakeFlags+=" -DPYTHON_LIBRARY=@pythonLibrary@"
cmakeFlags+=" -DPYTHON_INCLUDE_DIR=@pythonIncludeDir@"
}
preConfigureHooks+=(_pythonCmakeModulePreConfigureHook)

View file

@ -0,0 +1,6 @@
_rosidlGeneratorPyPreConfigureHook() {
# Prevent "RPATH of binary ... contains a forbidden reference to /build/"
# when cross-compiling
cmakeFlags+=" -DCMAKE_SKIP_BUILD_RPATH:BOOL=ON"
}
preConfigureHooks+=(_rosidlGeneratorPyPreConfigureHook)