ripasso-cursive: cosmetic changes (#361736)
[NixPkgs.git] / pkgs / by-name / ca / catboost / package.nix
blob1d0ef404a667b981c51d34ffb76541a78815bf63
2   lib,
3   config,
4   fetchFromGitHub,
5   cmake,
6   cctools,
7   libiconv,
8   llvmPackages,
9   ninja,
10   openssl,
11   python3Packages,
12   ragel,
13   yasm,
14   zlib,
15   cudaSupport ? config.cudaSupport,
16   cudaPackages ? { },
17   llvmPackages_12,
18   pythonSupport ? false,
20 let
21   inherit (llvmPackages) stdenv;
24 stdenv.mkDerivation (finalAttrs: {
25   pname = "catboost";
26   version = "1.2.7";
28   src = fetchFromGitHub {
29     owner = "catboost";
30     repo = "catboost";
31     rev = "refs/tags/v${finalAttrs.version}";
32     hash = "sha256-I3geFdVQ1Pm61eRXi+ueaxel3QRb8EJV9f4zV2Q7kk4=";
33   };
35   patches = [
36     ./remove-conan.patch
37   ];
39   postPatch = ''
40     substituteInPlace cmake/common.cmake \
41       --replace-fail  "\''${RAGEL_BIN}" "${ragel}/bin/ragel" \
42       --replace-fail "\''${YASM_BIN}" "${yasm}/bin/yasm"
44     shopt -s globstar
45     for cmakelists in **/CMakeLists.*; do
46       sed -i "s/OpenSSL::OpenSSL/OpenSSL::SSL/g" $cmakelists
47       ${lib.optionalString (lib.versionOlder cudaPackages.cudaVersion "11.8") ''
48         sed -i 's/-gencode=arch=compute_89,code=sm_89//g' $cmakelists
49         sed -i 's/-gencode=arch=compute_90,code=sm_90//g' $cmakelists
50       ''}
51     done
52   '';
54   outputs = [
55     "out"
56     "dev"
57   ];
59   nativeBuildInputs =
60     [
61       cmake
62       llvmPackages.bintools
63       ninja
64       (python3Packages.python.withPackages (ps: with ps; [ six ]))
65       ragel
66       yasm
67     ]
68     ++ lib.optionals stdenv.hostPlatform.isDarwin [
69       cctools
70     ]
71     ++ lib.optionals cudaSupport (
72       with cudaPackages;
73       [
74         cuda_nvcc
75       ]
76     );
78   buildInputs =
79     [
80       openssl
81       zlib
82     ]
83     ++ lib.optionals stdenv.hostPlatform.isDarwin [
84       libiconv
85     ]
86     ++ lib.optionals cudaSupport (
87       with cudaPackages;
88       [
89         cuda_cudart
90         cuda_cccl
91         libcublas
92       ]
93     );
95   env = {
96     PROGRAM_VERSION = finalAttrs.version;
98     # catboost requires clang 14+ for build, but does clang 12 for cuda build.
99     # after bumping the default version of llvm, check for compatibility with the cuda backend and pin it.
100     # see https://catboost.ai/en/docs/installation/build-environment-setup-for-cmake#compilers,-linkers-and-related-tools
101     CUDAHOSTCXX = lib.optionalString cudaSupport "${llvmPackages_12.stdenv.cc}/bin/cc";
102     NIX_CFLAGS_LINK = lib.optionalString stdenv.hostPlatform.isLinux "-fuse-ld=lld";
103     NIX_LDFLAGS = "-lc -lm";
104   };
106   cmakeFlags = [
107     (lib.cmakeFeature "CMAKE_BINARY_DIR" "$out")
108     (lib.cmakeBool "CMAKE_POSITION_INDEPENDENT_CODE" true)
109     (lib.cmakeFeature "CATBOOST_COMPONENTS" "app;libs${lib.optionalString pythonSupport ";python-package"}")
110     (lib.cmakeBool "HAVE_CUDA" cudaSupport)
111   ];
113   installPhase = ''
114     runHook preInstall
116     mkdir $dev
117     cp -r catboost $dev
118     install -Dm555 catboost/app/catboost -t $out/bin
119     install -Dm444 catboost/libs/model_interface/static/lib/libmodel_interface-static-lib.a -t $out/lib
120     install -Dm444 catboost/libs/model_interface/libcatboostmodel${stdenv.hostPlatform.extensions.sharedLibrary} -t $out/lib
121     install -Dm444 catboost/libs/train_interface/libcatboost${stdenv.hostPlatform.extensions.sharedLibrary} -t $out/lib
123     runHook postInstall
124   '';
126   meta = with lib; {
127     description = "High-performance library for gradient boosting on decision trees";
128     longDescription = ''
129       A fast, scalable, high performance Gradient Boosting on Decision Trees
130       library, used for ranking, classification, regression and other machine
131       learning tasks for Python, R, Java, C++. Supports computation on CPU and GPU.
132     '';
133     changelog = "https://github.com/catboost/catboost/releases/tag/v${finalAttrs.version}";
134     license = licenses.asl20;
135     platforms = platforms.unix;
136     homepage = "https://catboost.ai";
137     maintainers = with maintainers; [
138       PlushBeaver
139       natsukium
140     ];
141     mainProgram = "catboost";
142     # /nix/store/hzxiynjmmj35fpy3jla7vcqwmzj9i449-Libsystem-1238.60.2/include/sys/_types/_mbstate_t.h:31:9: error: unknown type name '__darwin_mbstate_t'
143     broken = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64;
144   };