[python312Packages.]lightgbm: 4.5.0 -> 4.6.0

Diff: https://github.com/microsoft/lightgbm/compare/v4.5.0...v4.6.0

Changelog: https://github.com/microsoft/LightGBM/releases/tag/v4.6.0
This commit is contained in:
Gaetan Lepage 2025-02-28 23:21:52 +01:00
parent 759641ba4c
commit 274e70aa39
2 changed files with 106 additions and 71 deletions

View File

@ -1,8 +1,9 @@
{ {
config,
stdenv,
lib, lib,
stdenv,
config,
fetchFromGitHub, fetchFromGitHub,
fetchpatch,
cmake, cmake,
gtest, gtest,
doCheck ? true, doCheck ? true,
@ -25,14 +26,14 @@
R, R,
rPackages, rPackages,
pandoc, pandoc,
python3Packages,
}: }:
assert doCheck -> !mpiSupport; assert doCheck -> !mpiSupport;
assert openclSupport -> !cudaSupport; assert openclSupport -> !cudaSupport;
assert cudaSupport -> !openclSupport; assert cudaSupport -> !openclSupport;
stdenv.mkDerivation rec { stdenv.mkDerivation (finalAttrs: {
pnameBase = "lightgbm";
# prefix with r when building the R library # prefix with r when building the R library
# The R package build results in a special binary file # The R package build results in a special binary file
# that contains a subset of the .so file use for the CLI # that contains a subset of the .so file use for the CLI
@ -45,17 +46,52 @@ stdenv.mkDerivation rec {
# lgbm = lightgbm.override{rLibrary = true; doCheck = false;}; \ # lgbm = lightgbm.override{rLibrary = true; doCheck = false;}; \
# in \ # in \
# rWrapper.override{ packages = [ lgbm ]; }" # rWrapper.override{ packages = [ lgbm ]; }"
pname = lib.optionalString rLibrary "r-" + pnameBase; pname = lib.optionalString rLibrary "r-" + "lightgbm";
version = "4.5.0"; version = "4.6.0";
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "microsoft"; owner = "microsoft";
repo = pnameBase; repo = "lightgbm";
rev = "v${version}"; tag = "v${finalAttrs.version}";
fetchSubmodules = true; fetchSubmodules = true;
hash = "sha256-nST6+/c3Y4/hqwgEUhx03gWtjxhlmUu1XKDCy2pSsvU="; hash = "sha256-vq/TlM87i1GNq0Rpy0OTulT9LF+uvi4PhOUz7ZNeceA=";
}; };
patches = [
# Fix boost 1.83+ compatibility
# https://github.com/microsoft/LightGBM/issues/6786
# Patch taken from https://github.com/conda-forge/lightgbm-feedstock/pull/69
(fetchpatch {
name = "fix-boost-sha1";
url = "https://raw.githubusercontent.com/conda-forge/lightgbm-feedstock/68ca96d25d8a6f7281310a4ad3b8d5cdd01f067b/recipe/patches/0003-boost-sha1.patch";
hash = "sha256-Hw2YmoduOPri7O1XV2p/3Ny4hC8xq7Jq4zoSuKhVeVQ=";
})
];
# Skip APPLE in favor of linux build for .so files
postPatch = ''
export PROJECT_SOURCE_DIR=./
substituteInPlace CMakeLists.txt \
--replace-fail "find_package(GTest CONFIG)" "find_package(GTest REQUIRED)" \
--replace-fail "OpenCL_INCLUDE_DIRS}" "OpenCL_INCLUDE_DIRS}" \
--replace-fail "elseif(APPLE)" "elseif(APPLESKIP)"
substituteInPlace \
external_libs/compute/include/boost/compute/cl.hpp \
external_libs/compute/include/boost/compute/cl_ext.hpp \
--replace-fail "include <OpenCL/" "include <CL/"
substituteInPlace build_r.R \
--replace-fail "shQuote(normalizePath" "shQuote(type = 'cmd', string = normalizePath" \
--replace-fail "file.path(getwd(), \"lightgbm_r\")" "'$out/tmp'" \
--replace-fail \
"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)"
# Retry this test in next release. Something fails in the setup, so GTEST_FILTER is not enough
substituteInPlace CMakeLists.txt \
--replace-fail "tests/cpp_tests/test_arrow.cpp" ""
rm tests/cpp_tests/test_arrow.cpp
'';
nativeBuildInputs = nativeBuildInputs =
[ cmake ] [ cmake ]
++ lib.optionals stdenv.hostPlatform.isDarwin [ llvmPackages.openmp ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ llvmPackages.openmp ]
@ -84,48 +120,36 @@ stdenv.mkDerivation rec {
rPackages.R6 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 "shQuote(normalizePath" "shQuote(type = 'cmd', string = normalizePath" \
--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)"
# Retry this test in next release. Something fails in the setup, so GTEST_FILTER is not enough
rm tests/cpp_tests/test_arrow.cpp
'';
cmakeFlags = cmakeFlags =
lib.optionals doCheck [ "-DBUILD_CPP_TEST=ON" ] lib.optionals doCheck [
++ lib.optionals cudaSupport [ (lib.cmakeBool "BUILD_CPP_TEST" true)
"-DUSE_CUDA=1" ]
"-DCMAKE_CXX_COMPILER=${cudaPackages.backendStdenv.cc}/bin/cc" ++ lib.optionals cudaSupport [
(lib.cmakeBool "USE_CUDA" true)
(lib.cmakeFeature "CMAKE_CXX_COMPILER" (lib.getExe cudaPackages.backendStdenv.cc))
]
++ lib.optionals openclSupport [
(lib.cmakeBool "USE_GPU" true)
]
++ lib.optionals mpiSupport [
(lib.cmakeBool "USE_MPI" true)
] ]
++ lib.optionals openclSupport [ "-DUSE_GPU=ON" ]
++ lib.optionals mpiSupport [ "-DUSE_MPI=ON" ]
++ lib.optionals hdfsSupport [ ++ lib.optionals hdfsSupport [
"-DUSE_HDFS=ON" (lib.cmakeBool "USE_HDFS" true)
"-DHDFS_LIB=${hadoop}/lib/hadoop-${hadoop.version}/lib/native/libhdfs.so" (lib.cmakeFeature "HDFS_LIB" "${hadoop}/lib/hadoop-${hadoop.version}/lib/native/libhdfs.so")
"-DHDFS_INCLUDE_DIR=${hadoop}/lib/hadoop-${hadoop.version}/include" (lib.cmakeFeature "HDFS_INCLUDE_DIR" "${hadoop}/lib/hadoop-${hadoop.version}/include")
] ]
++ lib.optionals javaWrapper [ ++ lib.optionals javaWrapper [
"-DUSE_SWIG=ON" (lib.cmakeBool "USE_SWIG" true)
# RPATH of binary /nix/store/.../bin/... contains a forbidden reference to /build/ # RPATH of binary /nix/store/.../bin/... contains a forbidden reference to /build/
"-DCMAKE_SKIP_BUILD_RPATH=ON" (lib.cmakeBool "CMAKE_SKIP_BUILD_RPATH" true)
] ]
++ lib.optionals rLibrary [ "-D__BUILD_FOR_R=ON" ] ++ lib.optionals rLibrary [
++ lib.optionals pythonLibrary [ "-D__BUILD_FOR_PYTHON=ON" ]; (lib.cmakeBool "__BUILD_FOR_R" true)
]
++ lib.optionals pythonLibrary [
(lib.cmakeBool "__BUILD_FOR_PYTHON" true)
];
configurePhase = lib.optionals rLibrary '' configurePhase = lib.optionals rLibrary ''
export R_LIBS_SITE="$out/library:$R_LIBS_SITE''${R_LIBS_SITE:+:}" export R_LIBS_SITE="$out/library:$R_LIBS_SITE''${R_LIBS_SITE:+:}"
@ -182,16 +206,23 @@ stdenv.mkDerivation rec {
postFixup = lib.optionalString rLibrary '' postFixup = lib.optionalString rLibrary ''
if test -e $out/nix-support/propagated-build-inputs; then 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 ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages
fi fi
''; '';
meta = with lib; { passthru = {
tests = {
pythonPackage = python3Packages.lightgbm;
};
};
meta = {
description = "LightGBM is a gradient boosting framework that uses tree based learning algorithms."; description = "LightGBM is a gradient boosting framework that uses tree based learning algorithms.";
mainProgram = "lightgbm"; mainProgram = "lightgbm";
homepage = "https://github.com/microsoft/LightGBM"; homepage = "https://github.com/microsoft/LightGBM";
license = licenses.mit; changelog = "https://github.com/microsoft/LightGBM/releases/tag/v${finalAttrs.version}";
platforms = platforms.unix; license = lib.licenses.mit;
maintainers = with maintainers; [ nviets ]; platforms = lib.platforms.unix;
maintainers = with lib.maintainers; [ nviets ];
}; };
} })

View File

@ -2,23 +2,31 @@
lib, lib,
config, config,
stdenv, stdenv,
pkgs,
buildPythonPackage, buildPythonPackage,
fetchPypi, fetchPypi,
# build-system # build-system
scikit-build-core,
# nativeBuildInputs
cmake, cmake,
ninja, ninja,
pathspec, pathspec,
pyproject-metadata, pyproject-metadata,
scikit-build-core, writableTmpDirAsHomeHook,
# buildInputs
llvmPackages,
boost,
ocl-icd,
opencl-headers,
# dependencies # dependencies
llvmPackages,
numpy, numpy,
scipy, scipy,
pythonOlder,
# optionals # optional-dependencies
cffi, cffi,
dask, dask,
pandas, pandas,
@ -26,9 +34,6 @@
scikit-learn, scikit-learn,
# optionals: gpu # optionals: gpu
boost,
ocl-icd,
opencl-headers,
gpuSupport ? stdenv.hostPlatform.isLinux && !cudaSupport, gpuSupport ? stdenv.hostPlatform.isLinux && !cudaSupport,
cudaSupport ? config.cudaSupport, cudaSupport ? config.cudaSupport,
cudaPackages, cudaPackages,
@ -38,23 +43,28 @@ assert gpuSupport -> !cudaSupport;
assert cudaSupport -> !gpuSupport; assert cudaSupport -> !gpuSupport;
buildPythonPackage rec { buildPythonPackage rec {
pname = "lightgbm"; inherit (pkgs.lightgbm)
version = "4.5.0"; pname
version
patches
;
pyproject = true; pyproject = true;
disabled = pythonOlder "3.7";
src = fetchPypi { src = fetchPypi {
inherit pname version; inherit pname version;
hash = "sha256-4c17rwMY1OMIomV1pjpGNfCN+GatNiKp2OPXHZY3obo="; hash = "sha256-yxxZcg61aTicC6dNFPUjUbVzr0ifIwAyocnzFPi6t/4=";
}; };
build-system = [
scikit-build-core
];
nativeBuildInputs = [ nativeBuildInputs = [
cmake cmake
ninja ninja
pathspec pathspec
pyproject-metadata pyproject-metadata
scikit-build-core writableTmpDirAsHomeHook
] ++ lib.optionals cudaSupport [ cudaPackages.cuda_nvcc ]; ] ++ lib.optionals cudaSupport [ cudaPackages.cuda_nvcc ];
dontUseCmakeConfigure = true; dontUseCmakeConfigure = true;
@ -71,7 +81,7 @@ buildPythonPackage rec {
cudaPackages.cuda_cudart cudaPackages.cuda_cudart
]; ];
propagatedBuildInputs = [ dependencies = [
numpy numpy
scipy scipy
]; ];
@ -80,10 +90,6 @@ buildPythonPackage rec {
lib.optionals gpuSupport [ "--config-setting=cmake.define.USE_GPU=ON" ] lib.optionals gpuSupport [ "--config-setting=cmake.define.USE_GPU=ON" ]
++ lib.optionals cudaSupport [ "--config-setting=cmake.define.USE_CUDA=ON" ]; ++ lib.optionals cudaSupport [ "--config-setting=cmake.define.USE_CUDA=ON" ];
postConfigure = ''
export HOME=$(mktemp -d)
'';
optional-dependencies = { optional-dependencies = {
arrow = [ arrow = [
cffi cffi
@ -101,9 +107,7 @@ buildPythonPackage rec {
scikit-learn = [ scikit-learn ]; scikit-learn = [ scikit-learn ];
}; };
# The pypi package doesn't distribute the tests from the GitHub # No python tests
# repository. It contains c++ tests which don't seem to wired up to
# `make check`.
doCheck = false; doCheck = false;
pythonImportsCheck = [ "lightgbm" ]; pythonImportsCheck = [ "lightgbm" ];