Python: improve cross-compilation

This changeset allows for cross-compilation of Python packages. Packages
built with buildPythonPackage are not allowed to refer to the build
machine. Executables that have shebangs will refer to the host.
This commit is contained in:
Frederik Rietdijk
2019-01-02 20:09:44 +01:00
parent 613498af97
commit f665828fa3
14 changed files with 68 additions and 41 deletions

View File

@@ -1,5 +1,4 @@
{ stdenv
, bootstrapped-pip
, buildPythonPackage
, python
, fetchPypi
@@ -24,11 +23,11 @@ buildPythonPackage rec {
# That is because while the default install phase succeeds to build the package,
# it fails to generate the file "auto_paridecl.pxd".
installPhase = ''
mkdir -p "$out/lib/${python.libPrefix}/site-packages"
export PYTHONPATH="$out/lib/${python.libPrefix}/site-packages:$PYTHONPATH"
mkdir -p "$out/lib/${python.sitePackages}"
export PYTHONPATH="$out/lib/${python.sitePackages}:$PYTHONPATH"
# install "." instead of "*.whl"
${bootstrapped-pip}/bin/pip install --no-index --prefix=$out --no-cache --build=tmpdir .
${python.pythonForBuild.pkgs.bootstrapped-pip}/bin/pip install --no-index --prefix=$out --no-cache --build=tmpdir .
'';
buildInputs = [

View File

@@ -1,4 +1,4 @@
{ lib, buildPythonPackage, fetchPypi, libyaml }:
{ lib, buildPythonPackage, fetchPypi, libyaml, buildPackages }:
buildPythonPackage rec {
pname = "PyYAML";
@@ -9,6 +9,8 @@ buildPythonPackage rec {
sha256 = "3ef3092145e9b70e3ddd2c7ad59bdd0252a94dfe3949721633e41344de00a6bf";
};
nativeBuildInputs = [ buildPackages.stdenv.cc ];
propagatedBuildInputs = [ libyaml ];
meta = with lib; {

View File

@@ -17,19 +17,24 @@ stdenv.mkDerivation rec {
sha256 = "86bb4d8e1b0fabad1f4642b64c335b673e53e7a381de03c9a89fe678152c4c64";
};
nativeBuildInputs = [ unzip wrapPython ];
buildInputs = [ python ];
nativeBuildInputs = [ unzip wrapPython python.pythonForBuild ];
doCheck = false; # requires pytest
installPhase = ''
dst=$out/${python.sitePackages}
mkdir -p $dst
export PYTHONPATH="$dst:$PYTHONPATH"
${python.interpreter} setup.py install --prefix=$out
${python.pythonForBuild.interpreter} setup.py install --prefix=$out
wrapPythonPrograms
'';
pythonPath = [];
dontPatchShebangs = true;
# Python packages built through cross-compilation are always for the host platform.
disallowedReferences = stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ python.pythonForBuild ];
meta = with stdenv.lib; {
description = "Utilities to facilitate the installation of Python packages";
homepage = https://pypi.python.org/pypi/setuptools;