diff --git a/.github/workflows/windows-arm64-wheels.yml b/.github/workflows/windows-arm64-wheels.yml index 0735c19..aa0269d 100644 --- a/.github/workflows/windows-arm64-wheels.yml +++ b/.github/workflows/windows-arm64-wheels.yml @@ -3,7 +3,7 @@ name: Build Windows ARM64 wheels on: [push] env: - MLPACK_COMMIT: 4.2.1 + MLPACK_COMMIT: 4.3.0 CIBW_TEST_COMMAND: python -c 'import mlpack; import numpy as np; x = np.random.rand(100, 10); o = mlpack.pca(input_=x, new_dimensionality=5, verbose=True)' jobs: @@ -87,6 +87,10 @@ jobs: git clone https://github.com/mlpack/mlpack cd mlpack git checkout $MLPACK_VERSION + # Apply patches to install Python headers. + cp ../ConfigureFileOnly.cmake CMake/ + cp ../mlpack.pc.in src/mlpack/bindings/python/ + patch -p1 < ../python-install-headers.patch - name: Generate setup.py shell: powershell diff --git a/ConfigureFileOnly.cmake b/ConfigureFileOnly.cmake new file mode 100644 index 0000000..2c57370 --- /dev/null +++ b/ConfigureFileOnly.cmake @@ -0,0 +1,11 @@ +# ConfigureFileOnly.cmake: generate an mlpack binding file given input +# arguments, using the @ONLY option. +# +# This file depends on the following variables being set: +# +# * GENERATE_CPP_IN: the .cpp.in file to configure. +# * GENERATE_CPP_OUT: the .cpp file we'll generate. +# +# Any other defined variables will be passed on to the file that is being +# generated. +configure_file(${GENERATE_CPP_IN} ${GENERATE_CPP_OUT} @ONLY) diff --git a/Jenkinsfile b/Jenkinsfile index 737e018..9ed4166 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ pipeline environment { - MLPACK_VERSION = '4.2.1' + MLPACK_VERSION = '4.3.0' TWINE_PYPI_TOKEN = credentials('twine-pypi-token') } @@ -23,6 +23,11 @@ pipeline cd mlpack/ git checkout $MLPACK_VERSION + # Apply patches. + cp ../ConfigureFileOnly.cmake CMake/ + cp ../mlpack.pc.in src/mlpack/bindings/python/ + patch -p1 < ../python-install-headers.patch + mkdir build/ cd build/ cmake -DBUILD_PYTHON_BINDINGS=ON ../ diff --git a/azure-pipelines-macos-steps.yml b/azure-pipelines-macos-steps.yml index f6caccd..bc74812 100644 --- a/azure-pipelines-macos-steps.yml +++ b/azure-pipelines-macos-steps.yml @@ -11,6 +11,11 @@ steps: git clone https://github.com/mlpack/mlpack cd mlpack git checkout $(MLPACK_VERSION) + + # Apply patches to install Python headers. + cp ../ConfigureFileOnly.cmake CMake/ + cp ../mlpack.pc.in src/mlpack/bindings/python/ + patch -p1 < ../python-install-headers.patch displayName: Clone mlpack - bash: | diff --git a/azure-pipelines-windows-steps.yml b/azure-pipelines-windows-steps.yml index 0c0bba7..4606cfb 100644 --- a/azure-pipelines-windows-steps.yml +++ b/azure-pipelines-windows-steps.yml @@ -53,6 +53,11 @@ steps: git clone https://github.com/mlpack/mlpack cd mlpack git checkout $(MLPACK_VERSION) + + # Apply patches to install Python headers. + cp ../ConfigureFileOnly.cmake CMake/ + cp ../mlpack.pc.in src/mlpack/bindings/python/ + patch -p1 < ../python-install-headers.patch displayName: Clone mlpack - powershell: | diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a5a6808..3dbcebc 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -62,7 +62,7 @@ jobs: timeoutInMinutes: 0 # No limit for build time. pool: {vmImage: 'macOS-11'} variables: - MLPACK_VERSION: 4.2.1 + MLPACK_VERSION: 4.3.0 CIBW_TEST_COMMAND: python -c 'import mlpack; import numpy as np; x = np.random.rand(100, 10); o = mlpack.pca(input_=x, new_dimensionality=5, verbose=True)' # The PYPI_TOKEN variable is automatically set by Azure Pipelines. TWINE_PYPI_TOKEN: $(PYPI_TOKEN) @@ -163,7 +163,7 @@ jobs: timeoutInMinutes: 0 # No limit for build time. pool: {vmImage: 'windows-2019'} variables: - MLPACK_VERSION: 4.2.1 + MLPACK_VERSION: 4.3.0 # The PYPI_TOKEN variable is automatically set by Azure Pipelines. TWINE_PYPI_TOKEN: $(PYPI_TOKEN) steps: diff --git a/mlpack.pc.in b/mlpack.pc.in new file mode 100644 index 0000000..3b67ef3 --- /dev/null +++ b/mlpack.pc.in @@ -0,0 +1,7 @@ +prefix=${pcfiledir}/../../ +includedir=${prefix}/include + +Name: mlpack +Description: a flexible, fast machine learning library +Version: @PACKAGE_VERSION@ +Cflags: -I${includedir} diff --git a/python-install-headers.patch b/python-install-headers.patch new file mode 100644 index 0000000..ee28807 --- /dev/null +++ b/python-install-headers.patch @@ -0,0 +1,50 @@ +--- mlpack-4.3.0/src/mlpack/bindings/python/setup.py.in 2023-11-27 13:27:20.000000000 -0500 ++++ mlpack-4.3.0-mod/src/mlpack/bindings/python/setup.py.in 2023-12-11 16:58:43.457383940 -0500 +@@ -116,6 +116,12 @@ + else '${DISABLE_CFLAGS}'.split(' ')) \ + for name in pyxs] + ++# Find all include files. ++include_files = [] ++for (path, directories, filenames) in os.walk('include/'): ++ for filename in filenames: ++ include_files.append(os.path.join('..', path, filename)) ++ + setup(name='mlpack', + version='${PACKAGE_VERSION}', + description='a flexible, fast machine learning library', +@@ -141,6 +147,8 @@ + install_requires=['cython>=0.24', 'numpy', 'pandas'], + package_dir={ '': '.' }, # Might be superfluous. + packages=['mlpack'], ++ package_data={ '': include_files + ['share/pkgconfig/mlpack.pc'] }, ++ include_package_data=True, + cmdclass={ 'build_ext': build_ext }, + ext_modules = modules, + setup_requires=['cython', 'pytest-runner'], +--- mlpack-4.3.0/src/mlpack/bindings/python/CMakeLists.txt 2023-11-27 13:27:20.000000000 -0500 ++++ mlpack-4.3.0-mod/src/mlpack/bindings/python/CMakeLists.txt 2023-12-11 16:59:03.689447094 -0500 +@@ -158,6 +158,23 @@ + ${CMAKE_CURRENT_SOURCE_DIR}/setup_readme.md + ${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/) + ++# Copy all mlpack headers for inclusion in the package. ++add_custom_command(TARGET python_copy PRE_BUILD ++ COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory ++ ${CMAKE_SOURCE_DIR}/src/ ++ ${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/include/) ++ ++# Generate pkgconfig file for easy use of included headers. ++add_custom_target(python_pkgconfig ++ COMMAND ${CMAKE_COMMAND} ++ -D GENERATE_CPP_IN=${CMAKE_SOURCE_DIR}/src/mlpack/bindings/python/mlpack.pc.in ++ -D GENERATE_CPP_OUT=${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/share/pkgconfig/mlpack.pc ++ -D PACKAGE_VERSION="${PACKAGE_VERSION}" ++ -P "${CMAKE_SOURCE_DIR}/CMake/ConfigureFileOnly.cmake" ++ BYPRODUCTS "${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/share/pkgconfig/mlpack.pc" ++ COMMENT "Configuring Python mlpack.pc...") ++add_dependencies(python_copy python_pkgconfig) ++ + if (BUILD_TESTS) + foreach(test_file ${TEST_SOURCES}) + add_custom_command(TARGET python_copy PRE_BUILD