nix-ros-overlay/distros/build-ros-package/default.nix

71 lines
2.4 KiB
Nix
Raw Permalink Normal View History

{ stdenv, lib, python3Packages, rosDistro, rosVersion }:
{ buildType ? "catkin"
# Too difficult to fix all the problems with the tests in each package
, doCheck ? false
# nixpkgs requires that either dontWrapQtApps is set or wrapQtAppsHook is added
# to nativeBuildInputs if a package depends on Qt5. This is difficult to achieve
# with auto-generated packages, so we just always disable wrapping except for
# packages that are overridden in distro-overlay.nix. This means some Qt5
# applications are broken, but allows all libraries that depend on Qt5 to build
# correctly.
, dontWrapQtApps ? true
2023-07-01 19:00:11 +10:00
, nativeBuildInputs ? [ ]
, CXXFLAGS ? ""
2023-07-30 11:28:13 +10:00
, postFixup ? ""
, passthru ? { }
, separateDebugInfo ? true
2019-03-21 00:23:14 -04:00
, ...
}@args:
(if buildType == "ament_python" then python3Packages.buildPythonPackage
else stdenv.mkDerivation) (args // {
inherit doCheck dontWrapQtApps separateDebugInfo;
# Disable warnings that cause "Log limit exceeded" errors on Hydra in lots of
# packages that use Eigen
CXXFLAGS = CXXFLAGS + "-Wno-deprecated-declarations -Wno-deprecated-copy";
2019-04-16 15:02:56 -04:00
passthru = passthru // {
rosPackage = true;
inherit rosDistro rosVersion;
2019-04-16 15:02:56 -04:00
};
2020-03-04 17:18:10 -05:00
} // lib.optionalAttrs (buildType == "ament_python") {
dontUseCmakeConfigure = true;
2023-07-01 19:00:11 +10:00
# Modeled after colcon.
# As of 0.12.1, colcon uses the legacy distutils install.py script, so we do
# the same. Using modern techniques, such as "pip install" with setuptools,
# causes issues due to differences in setup.cfg interpretation. In particular,
# it ignores the "install-scripts" directive, which is commonly used in ROS
# to install binaries to "$out/lib/<package name>".
# https://github.com/colcon/colcon-core/blob/0.12.1/colcon_core/task/python/build.py#L84
2023-07-01 19:00:11 +10:00
format = "other";
nativeBuildInputs = nativeBuildInputs ++ [ python3Packages.setuptools ];
2023-07-01 19:00:11 +10:00
buildPhase = ''
runHook preBuild
python setup.py build
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p "$out/${python3Packages.python.sitePackages}"
export PYTHONPATH="$out/${python3Packages.python.sitePackages}:$PYTHONPATH"
2023-07-01 19:00:11 +10:00
python setup.py install --prefix="$out" --single-version-externally-managed --record /dev/null
runHook postInstall
'';
2023-07-30 11:28:13 +10:00
postFixup = ''
${postFixup}
find "$out/lib" -mindepth 1 -maxdepth 1 -type d ! -name '${python3Packages.python.libPrefix}' -print0 | while read -d "" libpkgdir; do
wrapPythonProgramsIn "$libpkgdir" "$out $pythonPath"
2023-07-30 11:28:13 +10:00
done
'';
2020-03-04 17:18:10 -05:00
})