diff options
author | Alyssa Ross <hi@alyssa.is> | 2023-06-16 06:56:35 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2023-06-16 06:56:35 +0000 |
commit | 99fcaeccb89621dd492203ce1f2d551c06f228ed (patch) | |
tree | 41cb730ae07383004789779b0f6e11cb3f4642a3 /nixpkgs/pkgs/development/libraries/lightgbm/default.nix | |
parent | 59c5f5ac8682acc13bb22bc29c7cf02f7d75f01f (diff) | |
parent | 75a5ebf473cd60148ba9aec0d219f72e5cf52519 (diff) | |
download | nixlib-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/lightgbm/default.nix')
-rw-r--r-- | nixpkgs/pkgs/development/libraries/lightgbm/default.nix | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/lightgbm/default.nix b/nixpkgs/pkgs/development/libraries/lightgbm/default.nix new file mode 100644 index 000000000000..7ac716b326dd --- /dev/null +++ b/nixpkgs/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 <OpenCL/" "include <CL/" + substituteInPlace build_r.R \ + --replace "file.path(getwd(), \"lightgbm_r\")" "'$out/tmp'" \ + --replace \ + "install_args <- c(\"CMD\", \"INSTALL\", \"--no-multiarch\", \"--with-keep.source\", tarball)" \ + "install_args <- c(\"CMD\", \"INSTALL\", \"--no-multiarch\", \"--with-keep.source\", \"-l $out/library\", tarball)" + ''; + + cmakeFlags = lib.optionals doCheck [ "-DBUILD_CPP_TEST=ON" ] + ++ lib.optionals cudaSupport [ "-DUSE_CUDA=1" "-DCMAKE_CXX_COMPILER=${cudaPackages.cudatoolkit.cc}/bin/cc" ] + ++ lib.optionals openclSupport [ "-DUSE_GPU=ON" ] + ++ lib.optionals mpiSupport [ "-DUSE_MPI=ON" ] + ++ lib.optionals hdfsSupport [ + "-DUSE_HDFS=ON" + "-DHDFS_LIB=${hadoop}/lib/hadoop-3.3.1/lib/native/libhdfs.so" + "-DHDFS_INCLUDE_DIR=${hadoop}/lib/hadoop-3.3.1/include" ] + ++ lib.optionals javaWrapper [ "-DUSE_SWIG=ON" ] + ++ lib.optionals rLibrary [ "-D__BUILD_FOR_R=ON" ]; + + configurePhase = lib.optionals rLibrary '' + export R_LIBS_SITE="$out/library:$R_LIBS_SITE''${R_LIBS_SITE:+:}" + ''; + + # set the R package buildPhase to null because lightgbm has a + # custom builder script that builds and installs in one step + buildPhase = lib.optionals rLibrary '' + ''; + + inherit doCheck; + + installPhase = '' + runHook preInstall + '' + lib.optionalString (!rLibrary) '' + mkdir -p $out + mkdir -p $out/lib + mkdir -p $out/bin + cp -r ../include $out + install -Dm755 ../lib_lightgbm.so $out/lib/lib_lightgbm.so + install -Dm755 ../lightgbm $out/bin/lightgbm + '' + lib.optionalString javaWrapper '' + cp -r java $out + cp -r com $out + cp -r lightgbmlib.jar $out + '' + '' + '' + lib.optionalString javaWrapper '' + cp -r java $out + cp -r com $out + cp -r lightgbmlib.jar $out + '' + lib.optionalString rLibrary '' + mkdir $out + mkdir $out/tmp + mkdir $out/library + mkdir $out/library/lightgbm + '' + lib.optionalString (rLibrary && (!openclSupport)) '' + Rscript build_r.R + rm -rf $out/tmp + '' + lib.optionalString (rLibrary && openclSupport) '' + Rscript build_r.R --use-gpu \ + --opencl-library=${ocl-icd}/lib/libOpenCL.so \ + --boost-librarydir=${boost} + rm -rf $out/tmp + '' + '' + 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 = + "LightGBM is a gradient boosting framework that uses tree based learning algorithms."; + homepage = "https://github.com/microsoft/LightGBM"; + license = licenses.mit; + platforms = platforms.unix; + maintainers = with maintainers; [ nviets ]; + }; +} |