nixpkgs/pkgs/development/python-modules/paddlepaddle/default.nix
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00

122 lines
2.8 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
stdenv,
config,
lib,
buildPythonPackage,
fetchPypi,
python,
pythonOlder,
pythonAtLeast,
openssl_1_1,
zlib,
setuptools,
cudaSupport ? config.cudaSupport or false,
cudaPackages_11 ? { },
addDriverRunpath,
# runtime dependencies
httpx,
numpy,
protobuf,
pillow,
decorator,
astor,
paddle-bfloat,
opt-einsum,
}:
let
pname = "paddlepaddle" + lib.optionalString cudaSupport "-gpu";
version = "2.5.0";
format = "wheel";
pyShortVersion = "cp${builtins.replaceStrings [ "." ] [ "" ] python.pythonVersion}";
cpuOrGpu = if cudaSupport then "gpu" else "cpu";
allHashAndPlatform = import ./binary-hashes.nix;
hash =
allHashAndPlatform."${stdenv.system}"."${cpuOrGpu}"."${pyShortVersion}"
or (throw "${pname} has no binary-hashes.nix entry for '${stdenv.system}.${cpuOrGpu}.${pyShortVersion}' attribute");
platform = allHashAndPlatform."${stdenv.system}".platform;
src = fetchPypi ({
inherit
version
format
hash
platform
;
pname = builtins.replaceStrings [ "-" ] [ "_" ] pname;
dist = pyShortVersion;
python = pyShortVersion;
abi = pyShortVersion;
});
in
buildPythonPackage {
inherit
pname
version
format
src
;
disabled = pythonOlder "3.9" || pythonAtLeast "3.11";
libraryPath = lib.makeLibraryPath (
# TODO: remove openssl_1_1 and zlib, maybe by building paddlepaddle from
# source as suggested in the following comment:
# https://github.com/NixOS/nixpkgs/pull/243583#issuecomment-1641450848
[
openssl_1_1
zlib
]
++ lib.optionals cudaSupport (
with cudaPackages_11;
[
cudatoolkit.lib
cudatoolkit.out
cudnn
]
)
);
postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
function fixRunPath {
p=$(patchelf --print-rpath $1)
patchelf --set-rpath "$p:$libraryPath" $1
${lib.optionalString cudaSupport ''
addDriverRunpath $1
''}
}
fixRunPath $out/${python.sitePackages}/paddle/fluid/libpaddle.so
'';
nativeBuildInputs = [ addDriverRunpath ];
propagatedBuildInputs = [
setuptools
httpx
numpy
protobuf
pillow
decorator
astor
paddle-bfloat
opt-einsum
];
pythonImportsCheck = [ "paddle" ];
# no tests
doCheck = false;
meta = with lib; {
description = "PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice &";
homepage = "https://github.com/PaddlePaddle/Paddle";
license = licenses.asl20;
maintainers = with maintainers; [ happysalada ];
platforms =
[ "x86_64-linux" ]
++ optionals (!cudaSupport) [
"x86_64-darwin"
"aarch64-darwin"
];
};
}