2023-05-05 01:06:11 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# [description]
|
|
|
|
#
|
|
|
|
# Prepare a source distribution (sdist) or built distribution (wheel)
|
|
|
|
# of the Python package, and optionally install it.
|
|
|
|
#
|
|
|
|
# [usage]
|
|
|
|
#
|
|
|
|
# # build sdist and put it in dist/
|
|
|
|
# sh ./build-python.sh sdist
|
|
|
|
#
|
|
|
|
# # build wheel and put it in dist/
|
|
|
|
# sh ./build-python.sh bdist_wheel [OPTIONS]
|
|
|
|
#
|
|
|
|
# # compile lib_lightgbm and install the Python package wrapping it
|
|
|
|
# sh ./build-python.sh install [OPTIONS]
|
|
|
|
#
|
|
|
|
# # install the Python package using a pre-compiled lib_lightgbm
|
|
|
|
# # (assumes lib_lightgbm.{dll,so} is located at the root of the repo)
|
|
|
|
# sh ./build-python.sh install --precompile
|
|
|
|
#
|
|
|
|
# [options]
|
|
|
|
#
|
2023-05-06 20:34:20 +03:00
|
|
|
# --boost-dir=FILEPATH
|
|
|
|
# Directory with Boost package configuration file.
|
2023-05-05 01:06:11 +03:00
|
|
|
# --boost-include-dir=FILEPATH
|
|
|
|
# Directory containing Boost headers.
|
|
|
|
# --boost-librarydir=FILEPATH
|
|
|
|
# Preferred Boost library directory.
|
|
|
|
# --boost-root=FILEPATH
|
|
|
|
# Boost preferred installation prefix.
|
|
|
|
# --opencl-include-dir=FILEPATH
|
|
|
|
# OpenCL include directory.
|
|
|
|
# --opencl-library=FILEPATH
|
|
|
|
# Path to OpenCL library.
|
|
|
|
# --bit32
|
|
|
|
# Compile 32-bit version.
|
|
|
|
# --cuda
|
|
|
|
# Compile CUDA version.
|
|
|
|
# --gpu
|
|
|
|
# Compile GPU version.
|
|
|
|
# --integrated-opencl
|
|
|
|
# Compile integrated OpenCL version.
|
|
|
|
# --mingw
|
|
|
|
# Compile with MinGW.
|
|
|
|
# --mpi
|
|
|
|
# Compile MPI version.
|
2023-08-21 04:24:55 +03:00
|
|
|
# --no-isolation
|
|
|
|
# Assume all build and install dependencies are already installed,
|
|
|
|
# don't go to the internet to get them.
|
2023-05-05 01:06:11 +03:00
|
|
|
# --nomp
|
|
|
|
# Compile version without OpenMP support.
|
|
|
|
# --precompile
|
|
|
|
# Use precompiled library.
|
|
|
|
# Only used with 'install' command.
|
|
|
|
# --time-costs
|
|
|
|
# Output time costs for different internal routines.
|
|
|
|
# --user
|
|
|
|
# Install into user-specific instead of global site-packages directory.
|
|
|
|
# Only used with 'install' command.
|
|
|
|
|
2024-04-23 03:28:51 +03:00
|
|
|
set -e -E -u
|
2023-05-05 01:06:11 +03:00
|
|
|
|
|
|
|
echo "building lightgbm"
|
|
|
|
|
|
|
|
# Default values of arguments
|
|
|
|
INSTALL="false"
|
|
|
|
BUILD_SDIST="false"
|
|
|
|
BUILD_WHEEL="false"
|
|
|
|
|
|
|
|
PIP_INSTALL_ARGS=""
|
|
|
|
BUILD_ARGS=""
|
|
|
|
PRECOMPILE="false"
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
############################
|
|
|
|
# sub-commands of setup.py #
|
|
|
|
############################
|
|
|
|
install)
|
|
|
|
INSTALL="true"
|
|
|
|
;;
|
|
|
|
sdist)
|
|
|
|
BUILD_SDIST="true"
|
|
|
|
;;
|
|
|
|
bdist_wheel)
|
|
|
|
BUILD_WHEEL="true"
|
|
|
|
;;
|
|
|
|
############################
|
|
|
|
# customized library paths #
|
|
|
|
############################
|
2023-05-06 20:34:20 +03:00
|
|
|
--boost-dir|--boost-dir=*)
|
|
|
|
if [[ "$1" != *=* ]];
|
|
|
|
then shift;
|
|
|
|
fi
|
|
|
|
BOOST_DIR="${1#*=}"
|
2023-06-15 19:30:34 +03:00
|
|
|
BUILD_ARGS="${BUILD_ARGS} --config-setting=cmake.define.Boost_DIR='${BOOST_DIR}'"
|
2023-05-06 20:34:20 +03:00
|
|
|
;;
|
2023-05-05 01:06:11 +03:00
|
|
|
--boost-include-dir|--boost-include-dir=*)
|
|
|
|
if [[ "$1" != *=* ]];
|
|
|
|
then shift;
|
|
|
|
fi
|
|
|
|
BOOST_INCLUDE_DIR="${1#*=}"
|
2023-06-15 19:30:34 +03:00
|
|
|
BUILD_ARGS="${BUILD_ARGS} --config-setting=cmake.define.Boost_INCLUDE_DIR='${BOOST_INCLUDE_DIR}'"
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
|
|
|
--boost-librarydir|--boost-librarydir=*)
|
|
|
|
if [[ "$1" != *=* ]];
|
|
|
|
then shift;
|
|
|
|
fi
|
|
|
|
BOOST_LIBRARY_DIR="${1#*=}"
|
2023-06-15 19:30:34 +03:00
|
|
|
BUILD_ARGS="${BUILD_ARGS} --config-setting=cmake.define.BOOST_LIBRARYDIR='${BOOST_LIBRARY_DIR}'"
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
|
|
|
--boost-root|--boost-root=*)
|
|
|
|
if [[ "$1" != *=* ]];
|
|
|
|
then shift;
|
|
|
|
fi
|
|
|
|
BOOST_ROOT="${1#*=}"
|
2023-06-15 19:30:34 +03:00
|
|
|
BUILD_ARGS="${BUILD_ARGS} --config-setting=cmake.define.Boost_ROOT='${BOOST_ROOT}'"
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
|
|
|
--opencl-include-dir|--opencl-include-dir=*)
|
|
|
|
if [[ "$1" != *=* ]];
|
|
|
|
then shift;
|
|
|
|
fi
|
|
|
|
OPENCL_INCLUDE_DIR="${1#*=}"
|
2023-06-15 19:30:34 +03:00
|
|
|
BUILD_ARGS="${BUILD_ARGS} --config-setting=cmake.define.OpenCL_INCLUDE_DIR='${OPENCL_INCLUDE_DIR}'"
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
|
|
|
--opencl-library|--opencl-library=*)
|
|
|
|
if [[ "$1" != *=* ]];
|
|
|
|
then shift;
|
|
|
|
fi
|
|
|
|
OPENCL_LIBRARY="${1#*=}"
|
2023-06-15 19:30:34 +03:00
|
|
|
BUILD_ARGS="${BUILD_ARGS} --config-setting=cmake.define.OpenCL_LIBRARY='${OPENCL_LIBRARY}'"
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
|
|
|
#########
|
|
|
|
# flags #
|
|
|
|
#########
|
|
|
|
--bit32)
|
2023-06-15 19:30:34 +03:00
|
|
|
export CMAKE_GENERATOR="Visual Studio 17 2022"
|
|
|
|
export CMAKE_GENERATOR_PLATFORM="Win32"
|
|
|
|
echo "[INFO] Attempting to build 32-bit version of LightGBM, which is only supported on Windows with generator '${CMAKE_GENERATOR}'."
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
|
|
|
--cuda)
|
2023-06-15 19:30:34 +03:00
|
|
|
BUILD_ARGS="${BUILD_ARGS} --config-setting=cmake.define.USE_CUDA=ON"
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
|
|
|
--gpu)
|
2023-06-15 19:30:34 +03:00
|
|
|
BUILD_ARGS="${BUILD_ARGS} --config-setting=cmake.define.USE_GPU=ON"
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
|
|
|
--integrated-opencl)
|
2023-06-15 19:30:34 +03:00
|
|
|
BUILD_ARGS="${BUILD_ARGS} --config-setting=cmake.define.__INTEGRATE_OPENCL=ON"
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
|
|
|
--mingw)
|
2023-06-15 19:30:34 +03:00
|
|
|
export CMAKE_GENERATOR='MinGW Makefiles'
|
|
|
|
# ref: https://stackoverflow.com/a/45104058/3986677
|
|
|
|
BUILD_ARGS="${BUILD_ARGS} --config-setting=cmake.define.CMAKE_SH=CMAKE_SH-NOTFOUND"
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
|
|
|
--mpi)
|
2023-06-15 19:30:34 +03:00
|
|
|
BUILD_ARGS="${BUILD_ARGS} --config-setting=cmake.define.USE_MPI=ON"
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
2023-08-21 04:24:55 +03:00
|
|
|
--no-isolation)
|
|
|
|
BUILD_ARGS="${BUILD_ARGS} --no-isolation"
|
|
|
|
PIP_INSTALL_ARGS="${PIP_INSTALL_ARGS} --no-build-isolation"
|
|
|
|
;;
|
2023-05-05 01:06:11 +03:00
|
|
|
--nomp)
|
2023-06-15 19:30:34 +03:00
|
|
|
BUILD_ARGS="${BUILD_ARGS} --config-setting=cmake.define.USE_OPENMP=OFF"
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
|
|
|
--precompile)
|
|
|
|
PRECOMPILE="true"
|
|
|
|
;;
|
|
|
|
--time-costs)
|
2023-06-15 19:30:34 +03:00
|
|
|
BUILD_ARGS="${BUILD_ARGS} --config-setting=cmake.define.USE_TIMETAG=ON"
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
|
|
|
--user)
|
|
|
|
PIP_INSTALL_ARGS="${PIP_INSTALL_ARGS} --user"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "invalid argument '${1}'"
|
2024-02-10 07:42:00 +03:00
|
|
|
exit 1
|
2023-05-05 01:06:11 +03:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2023-06-15 19:30:34 +03:00
|
|
|
pip install --prefer-binary 'build>=0.10.0'
|
|
|
|
|
2023-05-05 01:06:11 +03:00
|
|
|
# create a new directory that just contains the files needed
|
|
|
|
# to build the Python package
|
|
|
|
create_isolated_source_dir() {
|
|
|
|
rm -rf \
|
|
|
|
./lightgbm-python \
|
|
|
|
./lightgbm \
|
|
|
|
./python-package/build \
|
|
|
|
./python-package/build_cpp \
|
|
|
|
./python-package/compile \
|
|
|
|
./python-package/dist \
|
|
|
|
./python-package/lightgbm.egg-info
|
|
|
|
|
|
|
|
cp -R ./python-package ./lightgbm-python
|
|
|
|
|
|
|
|
cp LICENSE ./lightgbm-python/
|
|
|
|
cp VERSION.txt ./lightgbm-python/lightgbm/VERSION.txt
|
|
|
|
|
2023-06-15 19:30:34 +03:00
|
|
|
cp -R ./cmake ./lightgbm-python
|
|
|
|
cp CMakeLists.txt ./lightgbm-python
|
|
|
|
cp -R ./include ./lightgbm-python
|
|
|
|
cp -R ./src ./lightgbm-python
|
|
|
|
cp -R ./swig ./lightgbm-python
|
|
|
|
cp -R ./windows ./lightgbm-python
|
2023-05-05 01:06:11 +03:00
|
|
|
|
|
|
|
# include only specific files from external_libs, to keep the package
|
|
|
|
# small and avoid redistributing code with licenses incompatible with
|
|
|
|
# LightGBM's license
|
|
|
|
|
|
|
|
######################
|
|
|
|
# fast_double_parser #
|
|
|
|
######################
|
2023-06-15 19:30:34 +03:00
|
|
|
mkdir -p ./lightgbm-python/external_libs/fast_double_parser
|
2023-05-05 01:06:11 +03:00
|
|
|
cp \
|
|
|
|
external_libs/fast_double_parser/CMakeLists.txt \
|
2023-06-15 19:30:34 +03:00
|
|
|
./lightgbm-python/external_libs/fast_double_parser/CMakeLists.txt
|
2023-05-05 01:06:11 +03:00
|
|
|
cp \
|
|
|
|
external_libs/fast_double_parser/LICENSE* \
|
2023-06-15 19:30:34 +03:00
|
|
|
./lightgbm-python/external_libs/fast_double_parser/
|
2023-05-05 01:06:11 +03:00
|
|
|
|
2023-06-15 19:30:34 +03:00
|
|
|
mkdir -p ./lightgbm-python/external_libs/fast_double_parser/include/
|
2023-05-05 01:06:11 +03:00
|
|
|
cp \
|
|
|
|
external_libs/fast_double_parser/include/fast_double_parser.h \
|
2023-06-15 19:30:34 +03:00
|
|
|
./lightgbm-python/external_libs/fast_double_parser/include/
|
2023-05-05 01:06:11 +03:00
|
|
|
|
|
|
|
#######
|
|
|
|
# fmt #
|
|
|
|
#######
|
2023-06-15 19:30:34 +03:00
|
|
|
mkdir -p ./lightgbm-python/external_libs/fmt
|
2023-05-05 01:06:11 +03:00
|
|
|
cp \
|
|
|
|
external_libs/fast_double_parser/CMakeLists.txt \
|
2023-06-15 19:30:34 +03:00
|
|
|
./lightgbm-python/external_libs/fmt/CMakeLists.txt
|
2023-05-05 01:06:11 +03:00
|
|
|
cp \
|
|
|
|
external_libs/fmt/LICENSE* \
|
2023-06-15 19:30:34 +03:00
|
|
|
./lightgbm-python/external_libs/fmt/
|
2023-05-05 01:06:11 +03:00
|
|
|
|
2023-06-15 19:30:34 +03:00
|
|
|
mkdir -p ./lightgbm-python/external_libs/fmt/include/fmt
|
2023-05-05 01:06:11 +03:00
|
|
|
cp \
|
|
|
|
external_libs/fmt/include/fmt/*.h \
|
2023-06-15 19:30:34 +03:00
|
|
|
./lightgbm-python/external_libs/fmt/include/fmt/
|
2023-05-05 01:06:11 +03:00
|
|
|
|
|
|
|
#########
|
|
|
|
# Eigen #
|
|
|
|
#########
|
2023-06-15 19:30:34 +03:00
|
|
|
mkdir -p ./lightgbm-python/external_libs/eigen/Eigen
|
2023-05-05 01:06:11 +03:00
|
|
|
cp \
|
|
|
|
external_libs/eigen/CMakeLists.txt \
|
2023-06-15 19:30:34 +03:00
|
|
|
./lightgbm-python/external_libs/eigen/CMakeLists.txt
|
2023-05-05 01:06:11 +03:00
|
|
|
|
|
|
|
modules="Cholesky Core Dense Eigenvalues Geometry Householder Jacobi LU QR SVD"
|
|
|
|
for eigen_module in ${modules}; do
|
|
|
|
cp \
|
|
|
|
external_libs/eigen/Eigen/${eigen_module} \
|
2023-06-15 19:30:34 +03:00
|
|
|
./lightgbm-python/external_libs/eigen/Eigen/${eigen_module}
|
2023-05-05 01:06:11 +03:00
|
|
|
if [ ${eigen_module} != "Dense" ]; then
|
2023-06-15 19:30:34 +03:00
|
|
|
mkdir -p ./lightgbm-python/external_libs/eigen/Eigen/src/${eigen_module}/
|
2023-05-05 01:06:11 +03:00
|
|
|
cp \
|
|
|
|
-R \
|
|
|
|
external_libs/eigen/Eigen/src/${eigen_module}/* \
|
2023-06-15 19:30:34 +03:00
|
|
|
./lightgbm-python/external_libs/eigen/Eigen/src/${eigen_module}/
|
2023-05-05 01:06:11 +03:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-06-15 19:30:34 +03:00
|
|
|
mkdir -p ./lightgbm-python/external_libs/eigen/Eigen/misc
|
2023-05-05 01:06:11 +03:00
|
|
|
cp \
|
|
|
|
-R \
|
|
|
|
external_libs/eigen/Eigen/src/misc \
|
2023-06-15 19:30:34 +03:00
|
|
|
./lightgbm-python/external_libs/eigen/Eigen/src/misc/
|
2023-05-05 01:06:11 +03:00
|
|
|
|
2023-06-15 19:30:34 +03:00
|
|
|
mkdir -p ./lightgbm-python/external_libs/eigen/Eigen/plugins
|
2023-05-05 01:06:11 +03:00
|
|
|
cp \
|
|
|
|
-R \
|
|
|
|
external_libs/eigen/Eigen/src/plugins \
|
2023-06-15 19:30:34 +03:00
|
|
|
./lightgbm-python/external_libs/eigen/Eigen/src/plugins/
|
2023-05-05 01:06:11 +03:00
|
|
|
|
|
|
|
###################
|
|
|
|
# compute (Boost) #
|
|
|
|
###################
|
2023-06-15 19:30:34 +03:00
|
|
|
mkdir -p ./lightgbm-python/external_libs/compute
|
2023-05-05 01:06:11 +03:00
|
|
|
cp \
|
|
|
|
-R \
|
|
|
|
external_libs/compute/include \
|
2023-06-15 19:30:34 +03:00
|
|
|
./lightgbm-python/external_libs/compute/include/
|
2023-05-05 01:06:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
create_isolated_source_dir
|
|
|
|
|
|
|
|
cd ./lightgbm-python
|
|
|
|
|
|
|
|
# installation involves building the wheel + `pip install`-ing it
|
|
|
|
if test "${INSTALL}" = true; then
|
|
|
|
if test "${PRECOMPILE}" = true; then
|
2023-06-15 19:30:34 +03:00
|
|
|
BUILD_SDIST=true
|
|
|
|
BUILD_WHEEL=false
|
|
|
|
BUILD_ARGS=""
|
|
|
|
rm -rf \
|
|
|
|
./cmake \
|
|
|
|
./CMakeLists.txt \
|
|
|
|
./external_libs \
|
|
|
|
./include \
|
|
|
|
./src \
|
|
|
|
./swig \
|
|
|
|
./windows
|
|
|
|
# use regular-old setuptools for these builds, to avoid
|
|
|
|
# trying to recompile the shared library
|
|
|
|
sed -i.bak -e '/start:build-system/,/end:build-system/d' pyproject.toml
|
|
|
|
echo '[build-system]' >> ./pyproject.toml
|
|
|
|
echo 'requires = ["setuptools"]' >> ./pyproject.toml
|
|
|
|
echo 'build-backend = "setuptools.build_meta"' >> ./pyproject.toml
|
|
|
|
echo "" >> ./pyproject.toml
|
2024-04-23 07:15:32 +03:00
|
|
|
echo "recursive-include lightgbm *.dll *.dylib *.so" > ./MANIFEST.in
|
2023-06-15 19:30:34 +03:00
|
|
|
echo "" >> ./MANIFEST.in
|
|
|
|
mkdir -p ./lightgbm/lib
|
|
|
|
if test -f ../lib_lightgbm.so; then
|
|
|
|
echo "found pre-compiled lib_lightgbm.so"
|
|
|
|
cp ../lib_lightgbm.so ./lightgbm/lib/lib_lightgbm.so
|
2024-04-23 07:15:32 +03:00
|
|
|
elif test -f ../lib_lightgbm.dylib; then
|
|
|
|
echo "found pre-compiled lib_lightgbm.dylib"
|
|
|
|
cp ../lib_lightgbm.dylib ./lightgbm/lib/lib_lightgbm.dylib
|
2023-06-15 19:30:34 +03:00
|
|
|
elif test -f ../Release/lib_lightgbm.dll; then
|
|
|
|
echo "found pre-compiled Release/lib_lightgbm.dll"
|
|
|
|
cp ../Release/lib_lightgbm.dll ./lightgbm/lib/lib_lightgbm.dll
|
|
|
|
elif test -f ../windows/x64/DLL/lib_lightgbm.dll; then
|
|
|
|
echo "found pre-compiled windows/x64/DLL/lib_lightgbm.dll"
|
|
|
|
cp ../windows/x64/DLL/lib_lightgbm.dll ./lightgbm/lib/lib_lightgbm.dll
|
|
|
|
cp ../windows/x64/DLL/lib_lightgbm.lib ./lightgbm/lib/lib_lightgbm.lib
|
|
|
|
fi
|
|
|
|
rm -f ./*.bak
|
2023-05-05 01:06:11 +03:00
|
|
|
else
|
|
|
|
BUILD_SDIST="false"
|
|
|
|
BUILD_WHEEL="true"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test "${BUILD_SDIST}" = true; then
|
|
|
|
echo "--- building sdist ---"
|
|
|
|
rm -f ../dist/*.tar.gz
|
2023-06-15 19:30:34 +03:00
|
|
|
python -m build \
|
|
|
|
--sdist \
|
|
|
|
--outdir ../dist \
|
2023-08-21 04:24:55 +03:00
|
|
|
${BUILD_ARGS} \
|
2023-06-15 19:30:34 +03:00
|
|
|
.
|
2023-05-05 01:06:11 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if test "${BUILD_WHEEL}" = true; then
|
2023-05-06 20:34:20 +03:00
|
|
|
echo "--- building wheel ---"
|
2023-05-05 01:06:11 +03:00
|
|
|
rm -f ../dist/*.whl || true
|
2023-06-15 19:30:34 +03:00
|
|
|
python -m build \
|
|
|
|
--wheel \
|
|
|
|
--outdir ../dist \
|
|
|
|
${BUILD_ARGS} \
|
|
|
|
.
|
2023-05-05 01:06:11 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if test "${INSTALL}" = true; then
|
|
|
|
echo "--- installing lightgbm ---"
|
|
|
|
cd ../dist
|
2024-07-29 17:45:55 +03:00
|
|
|
if test "${BUILD_WHEEL}" = true; then
|
|
|
|
PACKAGE_NAME="lightgbm*.whl"
|
|
|
|
else
|
|
|
|
PACKAGE_NAME="lightgbm*.tar.gz"
|
|
|
|
fi
|
2024-04-20 05:48:18 +03:00
|
|
|
# ref for use of '--find-links': https://stackoverflow.com/a/52481267/3986677
|
2023-05-05 01:06:11 +03:00
|
|
|
pip install \
|
|
|
|
${PIP_INSTALL_ARGS} \
|
2024-07-29 17:45:55 +03:00
|
|
|
--force-reinstall \
|
2023-06-30 15:52:34 +03:00
|
|
|
--no-cache-dir \
|
2024-07-10 12:33:37 +03:00
|
|
|
--no-deps \
|
2023-05-05 01:06:11 +03:00
|
|
|
--find-links=. \
|
2024-07-29 17:45:55 +03:00
|
|
|
${PACKAGE_NAME}
|
2023-05-05 01:06:11 +03:00
|
|
|
cd ../
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "cleaning up"
|
|
|
|
rm -rf ./lightgbm-python
|