Files
Florian Klink 23c177448c python3Packages.lightgbm: override stdenv if built with cuda support
From https://github.com/NixOS/nixpkgs/pull/507972#discussion_r3053161889:

> [This prevents] the other stdenv and its cc from leaking into the
> build. The latter is somewhat optional, but the leakage can result in,
> on one hand, in mixing object files from different cc releases ("works
> in practice but nobody offers guarantees"), and on the other in the
> hypothetical possibility that cuda tools use up wrong cc.
>
> If lightgbm builds cuda kernel, it "should" conditionally override
> stdenv, so far we don't have a better system to configure this
> transparently to individual packages...
2026-04-09 23:47:47 +01:00

137 lines
2.7 KiB
Nix

{
lib,
config,
stdenv,
pkgs,
buildPythonPackage,
fetchPypi,
# build-system
scikit-build-core,
# nativeBuildInputs
cmake,
ninja,
pathspec,
pyproject-metadata,
writableTmpDirAsHomeHook,
# buildInputs
llvmPackages,
boost187,
ocl-icd,
opencl-headers,
# dependencies
numpy,
scipy,
# optional-dependencies
cffi,
dask,
pandas,
pyarrow,
scikit-learn,
# optionals: gpu
gpuSupport ? stdenv.hostPlatform.isLinux && !cudaSupport,
cudaSupport ? config.cudaSupport,
cudaPackages,
}:
assert gpuSupport -> !cudaSupport;
assert cudaSupport -> !gpuSupport;
let
effectiveStdenv = if cudaSupport then cudaPackages.backendStdenv else stdenv;
in
buildPythonPackage.override { stdenv = effectiveStdenv; } (finalAttrs: {
inherit (pkgs.lightgbm)
pname
version
patches
;
pyproject = true;
src = fetchPypi {
inherit (finalAttrs) pname version;
hash = "sha256-yxxZcg61aTicC6dNFPUjUbVzr0ifIwAyocnzFPi6t/4=";
};
build-system = [
scikit-build-core
];
nativeBuildInputs = [
cmake
ninja
pathspec
pyproject-metadata
writableTmpDirAsHomeHook
]
++ lib.optionals cudaSupport [ cudaPackages.cuda_nvcc ];
dontUseCmakeConfigure = true;
buildInputs =
(lib.optionals stdenv.cc.isClang [ llvmPackages.openmp ])
++ (lib.optionals gpuSupport [
boost187
ocl-icd
opencl-headers
])
++ lib.optionals cudaSupport [
cudaPackages.cuda_nvcc
cudaPackages.cuda_cudart
];
dependencies = [
numpy
scipy
];
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 = {
arrow = [
cffi
pyarrow
];
dask = [
dask
pandas
]
++ dask.optional-dependencies.array
++ dask.optional-dependencies.dataframe
++ dask.optional-dependencies.distributed;
pandas = [ pandas ];
scikit-learn = [ scikit-learn ];
};
# No python tests
doCheck = false;
pythonImportsCheck = [ "lightgbm" ];
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${finalAttrs.version}";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [
flokli
teh
];
};
})