From ecd33b6f92472081efb7c4d16f99c0b955517b2d Mon Sep 17 00:00:00 2001 From: nviets Date: Mon, 24 Apr 2023 06:15:55 -0500 Subject: [PATCH] lightgbm: init at 2023-02-18 (#216971) * Adding lightgbm with cli tool, r-package, and other features. * Update pkgs/development/libraries/lightgbm/default.nix Co-authored-by: Yt --------- Co-authored-by: nviets Co-authored-by: Yt --- .../libraries/lightgbm/default.nix | 142 ++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 2 files changed, 144 insertions(+) create mode 100644 pkgs/development/libraries/lightgbm/default.nix diff --git a/pkgs/development/libraries/lightgbm/default.nix b/pkgs/development/libraries/lightgbm/default.nix new file mode 100644 index 00000000000..7ac716b326d --- /dev/null +++ b/pkgs/development/libraries/lightgbm/default.nix @@ -0,0 +1,142 @@ +{ config, stdenv, lib, fetchFromGitHub, cmake, gtest, doCheck ? true +, cudaSupport ? config.cudaSupport or false, openclSupport ? false, mpiSupport ? false, javaWrapper ? false, hdfsSupport ? false +, rLibrary ? false, cudaPackages, opencl-headers, ocl-icd, boost, llvmPackages, openmpi, openjdk, swig, hadoop, R, rPackages }: + +assert doCheck -> mpiSupport != true; +assert openclSupport -> cudaSupport != true; +assert cudaSupport -> openclSupport != true; + +stdenv.mkDerivation rec { + pnameBase = "lightgbm"; + # prefix with r when building the R library + # The R package build results in a special binary 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 support and other features + # which aren't included in the CRAN release. Build with: + # nix-build -E "with (import $NIXPKGS{}); \ + # let \ + # lgbm = lightgbm.override{rLibrary = true; doCheck = false;}; \ + # in \ + # rWrapper.override{ packages = [ lgbm ]; }" + pname = lib.optionalString rLibrary "r-" + pnameBase; + version = "3.3.5"; + + src = fetchFromGitHub { + owner = "microsoft"; + repo = pnameBase; + rev = "v${version}"; + fetchSubmodules = true; + hash = "sha256-QRuBbMVtD5J5ECw+bAp57bWaRc/fATMcTq+AKikhj1I="; + }; + + nativeBuildInputs = [ cmake ] + ++ lib.optionals stdenv.isDarwin [ llvmPackages.openmp ] + ++ lib.optionals openclSupport [ opencl-headers ocl-icd boost ] + ++ lib.optionals mpiSupport [ openmpi ] + ++ lib.optionals hdfsSupport [ hadoop ] + ++ lib.optionals (hdfsSupport || javaWrapper) [ openjdk ] + ++ lib.optionals javaWrapper [ swig ] + ++ lib.optionals rLibrary [ R ]; + + buildInputs = [ gtest ] + ++ lib.optional cudaSupport cudaPackages.cudatoolkit; + + propagatedBuildInputs = lib.optionals rLibrary [ + rPackages.data_table + rPackages.jsonlite + rPackages.Matrix + rPackages.R6 + ]; + + # Skip APPLE in favor of linux build for .so files + postPatch = '' + export PROJECT_SOURCE_DIR=./ + substituteInPlace CMakeLists.txt \ + --replace "find_package(GTest CONFIG)" "find_package(GTest REQUIRED)" \ + --replace "OpenCL_INCLUDE_DIRS}" "OpenCL_INCLUDE_DIRS}" \ + --replace "elseif(APPLE)" "elseif(APPLESKIP)" + substituteInPlace \ + external_libs/compute/include/boost/compute/cl.hpp \ + external_libs/compute/include/boost/compute/cl_ext.hpp \ + --replace "include