about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/xgboost
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2023-06-16 06:56:35 +0000
committerAlyssa Ross <hi@alyssa.is>2023-06-16 06:56:35 +0000
commit99fcaeccb89621dd492203ce1f2d551c06f228ed (patch)
tree41cb730ae07383004789779b0f6e11cb3f4642a3 /nixpkgs/pkgs/development/libraries/xgboost
parent59c5f5ac8682acc13bb22bc29c7cf02f7d75f01f (diff)
parent75a5ebf473cd60148ba9aec0d219f72e5cf52519 (diff)
downloadnixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.gz
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.bz2
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.lz
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.xz
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.zst
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.zip
Merge branch 'nixos-unstable' of https://github.com/NixOS/nixpkgs
Conflicts:
	nixpkgs/nixos/modules/config/console.nix
	nixpkgs/nixos/modules/services/mail/mailman.nix
	nixpkgs/nixos/modules/services/mail/public-inbox.nix
	nixpkgs/nixos/modules/services/mail/rss2email.nix
	nixpkgs/nixos/modules/services/networking/ssh/sshd.nix
	nixpkgs/pkgs/applications/networking/instant-messengers/dino/default.nix
	nixpkgs/pkgs/applications/networking/irc/weechat/default.nix
	nixpkgs/pkgs/applications/window-managers/sway/default.nix
	nixpkgs/pkgs/build-support/go/module.nix
	nixpkgs/pkgs/build-support/rust/build-rust-package/default.nix
	nixpkgs/pkgs/development/interpreters/python/default.nix
	nixpkgs/pkgs/development/node-packages/overrides.nix
	nixpkgs/pkgs/development/tools/b4/default.nix
	nixpkgs/pkgs/servers/dict/dictd-db.nix
	nixpkgs/pkgs/servers/mail/public-inbox/default.nix
	nixpkgs/pkgs/tools/security/pinentry/default.nix
	nixpkgs/pkgs/tools/text/unoconv/default.nix
	nixpkgs/pkgs/top-level/all-packages.nix
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/xgboost')
-rw-r--r--nixpkgs/pkgs/development/libraries/xgboost/default.nix135
1 files changed, 107 insertions, 28 deletions
diff --git a/nixpkgs/pkgs/development/libraries/xgboost/default.nix b/nixpkgs/pkgs/development/libraries/xgboost/default.nix
index b4d668d5fba1..2f0c7a1d7a4c 100644
--- a/nixpkgs/pkgs/development/libraries/xgboost/default.nix
+++ b/nixpkgs/pkgs/development/libraries/xgboost/default.nix
@@ -7,64 +7,143 @@
 , doCheck ? true
 , cudaSupport ? config.cudaSupport or false
 , ncclSupport ? false
+, rLibrary ? false
 , cudaPackages
 , llvmPackages
-}:
+, R
+, rPackages
+}@inputs:
 
 assert ncclSupport -> cudaSupport;
+# Disable regular tests when building the R package
+# because 1) the R package runs its own tests and
+# 2) the R package creates a different binary shared
+# object that isn't compatible with the regular CLI
+# tests.
+assert rLibrary -> doCheck != true;
+
+let
+  # This ensures xgboost gets the correct libstdc++ when
+  # built with cuda support. This may be removed once
+  # #226165 rewrites cudaStdenv
+  inherit (cudaPackages) backendStdenv;
+  stdenv = if cudaSupport then backendStdenv else inputs.stdenv;
+in
 
 stdenv.mkDerivation rec {
-  pname = "xgboost";
-  version = "1.5.2";
+  pnameBase = "xgboost";
+  # prefix with r when building the R library
+  # The R package build results in a special xgboost.so file
+  # that contains a subset of the .so file use for the CLI
+  # and python version. In general, the CRAN version from
+  # nixpkgs's r-modules should be used, but this non-standard
+  # build allows for enabling CUDA and NCCL support which aren't
+  # included in the CRAN release. Build with:
+  # nix-build -E "with (import $NIXPKGS{}); \
+  #   let \
+  #     xgb = xgboost.override{rLibrary = true; doCheck = false;}; \
+  #   in \
+  #   rWrapper.override{ packages = [ xgb ]; }"
+  pname = lib.optionalString rLibrary "r-" + pnameBase;
+  version = "1.7.5";
 
   src = fetchFromGitHub {
     owner = "dmlc";
-    repo = pname;
+    repo = pnameBase;
     rev = "v${version}";
     fetchSubmodules = true;
-    sha256 = "sha256-h7zcHCOxe1h7HRB6idtjf4HUBEoHC4V2pqbN9hpe00g=";
+    hash = "sha256-IBqtyz40VVHdncibnZQAe5oDsjb5isWBYQ6pGx/zt38=";
   };
 
-  nativeBuildInputs = [
-    cmake
-  ] ++ lib.optionals stdenv.isDarwin [
-    llvmPackages.openmp
-  ] ++ lib.optionals cudaSupport [
-    cudaPackages.autoAddOpenGLRunpathHook
-  ];
+  nativeBuildInputs = [ cmake ]
+    ++ lib.optionals stdenv.isDarwin [ llvmPackages.openmp ]
+    ++ lib.optionals cudaSupport [ cudaPackages.autoAddOpenGLRunpathHook ]
+    ++ lib.optionals rLibrary [ R ];
 
   buildInputs = [ gtest ] ++ lib.optional cudaSupport cudaPackages.cudatoolkit
-                ++ lib.optional ncclSupport cudaPackages.nccl;
+    ++ lib.optional ncclSupport cudaPackages.nccl;
+
+  propagatedBuildInputs = lib.optionals rLibrary [
+    rPackages.data_table
+    rPackages.jsonlite
+    rPackages.Matrix
+  ];
 
   cmakeFlags = lib.optionals doCheck [ "-DGOOGLE_TEST=ON" ]
-    ++ lib.optionals cudaSupport [ "-DUSE_CUDA=ON" "-DCUDA_HOST_COMPILER=${cudaPackages.cudatoolkit.cc}/bin/cc" ]
-    ++ lib.optionals (cudaSupport && lib.versionAtLeast cudaPackages.cudatoolkit.version "11.4.0") [ "-DBUILD_WITH_CUDA_CUB=ON" ]
-    ++ lib.optionals ncclSupport [ "-DUSE_NCCL=ON" ];
+    ++ lib.optionals cudaSupport [
+    "-DUSE_CUDA=ON"
+    # Their CMakeLists.txt does not respect CUDA_HOST_COMPILER, instead using the CXX compiler.
+    # https://github.com/dmlc/xgboost/blob/ccf43d4ba0a94e2f0a3cc5a526197539ae46f410/CMakeLists.txt#L145
+    "-DCMAKE_C_COMPILER=${cudaPackages.cudatoolkit.cc}/bin/gcc"
+    "-DCMAKE_CXX_COMPILER=${cudaPackages.cudatoolkit.cc}/bin/g++"
+  ] ++ lib.optionals
+    (cudaSupport
+      && lib.versionAtLeast cudaPackages.cudatoolkit.version "11.4.0")
+    [ "-DBUILD_WITH_CUDA_CUB=ON" ]
+    ++ lib.optionals ncclSupport [ "-DUSE_NCCL=ON" ]
+    ++ lib.optionals rLibrary [ "-DR_LIB=ON" ];
+
+  preConfigure = lib.optionals rLibrary ''
+    substituteInPlace cmake/RPackageInstall.cmake.in --replace "CMD INSTALL" "CMD INSTALL -l $out/library"
+    export R_LIBS_SITE="$R_LIBS_SITE''${R_LIBS_SITE:+:}$out/library"
+  '';
 
   inherit doCheck;
 
   # By default, cmake build will run ctests with all checks enabled
   # If we're building with cuda, we run ctest manually so that we can skip the GPU tests
   checkPhase = lib.optionalString cudaSupport ''
-    ctest --force-new-ctest-process ${lib.optionalString cudaSupport "-E TestXGBoostLib"}
+    ctest --force-new-ctest-process ${
+      lib.optionalString cudaSupport "-E TestXGBoostLib"
+    }
   '';
 
-  installPhase = let
-    libname = "libxgboost${stdenv.hostPlatform.extensions.sharedLibrary}";
-  in ''
-    runHook preInstall
-    mkdir -p $out
-    cp -r ../include $out
-    install -Dm755 ../lib/${libname} $out/lib/${libname}
-    install -Dm755 ../xgboost $out/bin/xgboost
-    runHook postInstall
+  # Disable finicky tests from dmlc core that fail in Hydra. XGboost team
+  # confirmed xgboost itself does not use this part of the dmlc code.
+  GTEST_FILTER =
+    let
+      # Upstream Issue: https://github.com/xtensor-stack/xsimd/issues/456
+      filteredTests = lib.optionals stdenv.hostPlatform.isDarwin [
+        "ThreadGroup.TimerThread"
+        "ThreadGroup.TimerThreadSimple"
+      ];
+    in
+    "-${builtins.concatStringsSep ":" filteredTests}";
+
+  installPhase =
+    let libname = "libxgboost${stdenv.hostPlatform.extensions.sharedLibrary}";
+    in ''
+      runHook preInstall
+      mkdir -p $out
+      cp -r ../include $out
+      cp -r ../dmlc-core/include/dmlc $out/include
+      cp -r ../rabit/include/rabit $out/include
+    '' + lib.optionalString (!rLibrary) ''
+      install -Dm755 ../lib/${libname} $out/lib/${libname}
+      install -Dm755 ../xgboost $out/bin/xgboost
+    ''
+    # the R library option builds a completely different binary xgboost.so instead of
+    # libxgboost.so, which isn't full featured for python and CLI
+    + lib.optionalString rLibrary ''
+      mkdir $out/library
+      export R_LIBS_SITE="$out/library:$R_LIBS_SITE''${R_LIBS_SITE:+:}"
+      make install -l $out/library
+    '' + ''
+      runHook postInstall
+    '';
+
+  postFixup = lib.optionalString rLibrary ''
+    if test -e $out/nix-support/propagated-build-inputs; then
+        ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages
+    fi
   '';
 
   meta = with lib; {
-    description = "Scalable, Portable and Distributed Gradient Boosting (GBDT, GBRT or GBM) Library";
+    description =
+      "Scalable, Portable and Distributed Gradient Boosting (GBDT, GBRT or GBM) Library";
     homepage = "https://github.com/dmlc/xgboost";
     license = licenses.asl20;
     platforms = platforms.unix;
-    maintainers = with maintainers; [ abbradar ];
+    maintainers = with maintainers; [ abbradar nviets ];
   };
 }