1{ lib
2, config
3, stdenv
4, fetchFromGitHub
5, cmake
6, libiconv
7, llvmPackages
8, ninja
9, openssl
10, python3Packages
11, ragel
12, yasm
13, zlib
14, cudaSupport ? config.cudaSupport
15, cudaPackages ? {}
16, pythonSupport ? false
17}:
18
19stdenv.mkDerivation (finalAttrs: {
20 pname = "catboost";
21 version = "1.2.2";
22
23 src = fetchFromGitHub {
24 owner = "catboost";
25 repo = "catboost";
26 rev = "refs/tags/v${finalAttrs.version}";
27 hash = "sha256-A1zCIqPOW21dHKBQHRtS+/sstZ2o6F8k71lmJFGn0+g=";
28 };
29
30 patches = [
31 ./remove-conan.patch
32 ];
33
34 postPatch = ''
35 substituteInPlace cmake/common.cmake \
36 --replace "\''${RAGEL_BIN}" "${ragel}/bin/ragel" \
37 --replace "\''${YASM_BIN}" "${yasm}/bin/yasm"
38
39 shopt -s globstar
40 for cmakelists in **/CMakeLists.*; do
41 sed -i "s/OpenSSL::OpenSSL/OpenSSL::SSL/g" $cmakelists
42 ${lib.optionalString (lib.versionOlder cudaPackages.cudaVersion "11.8") ''
43 sed -i 's/-gencode=arch=compute_89,code=sm_89//g' $cmakelists
44 sed -i 's/-gencode=arch=compute_90,code=sm_90//g' $cmakelists
45 ''}
46 done
47 '';
48
49 outputs = [ "out" "dev" ];
50
51 nativeBuildInputs = [
52 cmake
53 llvmPackages.bintools
54 ninja
55 (python3Packages.python.withPackages (ps: with ps; [ six ]))
56 ragel
57 yasm
58 ] ++ lib.optionals cudaSupport (with cudaPackages; [
59 cuda_nvcc
60 ]);
61
62 buildInputs = [
63 openssl
64 zlib
65 ] ++ lib.optionals stdenv.isDarwin [
66 libiconv
67 ] ++ lib.optionals cudaSupport (with cudaPackages; [
68 cuda_cudart
69 cuda_cccl
70 libcublas
71 ]);
72
73 env = {
74 CUDAHOSTCXX = lib.optionalString cudaSupport "${stdenv.cc}/bin/cc";
75 NIX_CFLAGS_LINK = lib.optionalString stdenv.isLinux "-fuse-ld=lld";
76 NIX_LDFLAGS = "-lc -lm";
77 };
78
79 cmakeFlags = [
80 "-DCMAKE_BINARY_DIR=$out"
81 "-DCMAKE_POSITION_INDEPENDENT_CODE=on"
82 "-DCATBOOST_COMPONENTS=app;libs${lib.optionalString pythonSupport ";python-package"}"
83 ] ++ lib.optionals cudaSupport [
84 "-DHAVE_CUDA=on"
85 ];
86
87 installPhase = ''
88 runHook preInstall
89
90 mkdir $dev
91 cp -r catboost $dev
92 install -Dm555 catboost/app/catboost -t $out/bin
93 install -Dm444 catboost/libs/model_interface/static/lib/libmodel_interface-static-lib.a -t $out/lib
94 install -Dm444 catboost/libs/model_interface/libcatboostmodel${stdenv.hostPlatform.extensions.sharedLibrary} -t $out/lib
95 install -Dm444 catboost/libs/train_interface/libcatboost${stdenv.hostPlatform.extensions.sharedLibrary} -t $out/lib
96
97 runHook postInstall
98 '';
99
100 meta = with lib; {
101 description = "High-performance library for gradient boosting on decision trees";
102 longDescription = ''
103 A fast, scalable, high performance Gradient Boosting on Decision Trees
104 library, used for ranking, classification, regression and other machine
105 learning tasks for Python, R, Java, C++. Supports computation on CPU and GPU.
106 '';
107 license = licenses.asl20;
108 platforms = platforms.unix;
109 homepage = "https://catboost.ai";
110 maintainers = with maintainers; [ PlushBeaver natsukium ];
111 mainProgram = "catboost";
112 };
113})