Unverified Commit 8cd5fa43 authored by Gaétan Lepage's avatar Gaétan Lepage Committed by GitHub
Browse files

python3Packages.lightgbm: fix builds (#507972)

parents ec96c64d 23c17744
Loading
Loading
Loading
Loading
+20 −19
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@

  # buildInputs
  llvmPackages,
  boost,
  boost187,
  ocl-icd,
  opencl-headers,

@@ -42,7 +42,10 @@
assert gpuSupport -> !cudaSupport;
assert cudaSupport -> !gpuSupport;

buildPythonPackage rec {
let
  effectiveStdenv = if cudaSupport then cudaPackages.backendStdenv else stdenv;
in
buildPythonPackage.override { stdenv = effectiveStdenv; } (finalAttrs: {
  inherit (pkgs.lightgbm)
    pname
    version
@@ -51,22 +54,10 @@ buildPythonPackage rec {
  pyproject = true;

  src = fetchPypi {
    inherit pname version;
    inherit (finalAttrs) pname version;
    hash = "sha256-yxxZcg61aTicC6dNFPUjUbVzr0ifIwAyocnzFPi6t/4=";
  };

  # Patch dll search path to fix proper discovery of lib_lightgbm.so
  #   Exception: Cannot find lightgbm library file in following paths:
  # /nix/store/...-python3.13-lightgbm-4.6.0/lib/python3.13/site-packages/lib_lightgbm.so
  # /nix/store/...-python3.13-lightgbm-4.6.0/lib/python3.13/site-packages/lightgbm/bin/lib_lightgbm.so
  # /nix/store/...-python3.13-lightgbm-4.6.0/lib/python3.13/site-packages/lightgbm/lib/lib_lightgbm.so
  postPatch = ''
    substituteInPlace lightgbm/libpath.py \
      --replace-fail \
        'curr_path.parents[0] / "lib",' \
        'curr_path.parents[1] / "lib",'
  '';

  build-system = [
    scikit-build-core
  ];
@@ -85,7 +76,7 @@ buildPythonPackage rec {
  buildInputs =
    (lib.optionals stdenv.cc.isClang [ llvmPackages.openmp ])
    ++ (lib.optionals gpuSupport [
      boost
      boost187
      ocl-icd
      opencl-headers
    ])
@@ -102,6 +93,13 @@ buildPythonPackage rec {
  cmakeFlags = [
    (lib.cmakeBool "USE_GPU" gpuSupport)
    (lib.cmakeBool "USE_CUDA" cudaSupport)
    # Set in pyproject.toml for `cmake.args` in `[tool.scikit-build]`,
    # but not set by our hooks.
    (lib.cmakeBool "__BUILD_FOR_PYTHON" true)
  ]
  ++ lib.optionals cudaSupport [
    # build fails otherwise
    (lib.cmakeFeature "CMAKE_CUDA_STANDARD" "14")
  ];

  optional-dependencies = {
@@ -128,8 +126,11 @@ buildPythonPackage rec {
  meta = {
    description = "Fast, distributed, high performance gradient boosting (GBDT, GBRT, GBM or MART) framework";
    homepage = "https://github.com/lightgbm-org/LightGBM";
    changelog = "https://github.com/lightgbm-org/LightGBM/releases/tag/v${version}";
    changelog = "https://github.com/lightgbm-org/LightGBM/releases/tag/v${finalAttrs.version}";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ teh ];
    maintainers = with lib.maintainers; [
      flokli
      teh
    ];
  };
}
})