alugowski / fast_matrix_market

Fast and full-featured Matrix Market I/O library for C++, Python, and R
BSD 2-Clause "Simplified" License
75 stars 7 forks source link

Possibility to use [gtest, eigen, blaze, etc] from system-wide if they are installed in compilation time and not duplicate after installation #68

Open carlosal1015 opened 7 months ago

carlosal1015 commented 7 months ago

Hi, I would like to ask if is possible to change the following behavior. In Linux many dependencies are are available in the repositories, for instance,

I am trying to package, but I noticed that FetchContent download and later will install together fast_matrix_market.

pkgname=fast_matrix_market
pkgdesc="Fast and full-featured Matrix Market I/O library"
pkgver=1.7.6
pkgrel=1
arch=(x86_64)
url="https://github.com/alugowski/${pkgname}"
license=(BSD-2-Clause)
depends=(python)
makedepends=(python-build python-installer pybind11 python-scikit-build-core cmake)
checkdepends=(gtest suitesparse eigen blaze armadillo python-scipy python-threadpoolctl python-pytest)
optdepends=('eigen: '
  'blaze: '
  'armadillo: '
  'python-scipy: ') # 'fastmatmr'
source=(${pkgname}-${pkgver}.tar.gz::${url}/archive/v${pkgver}.tar.gz)
sha512sums=('e97da2daf76770502e862a13b7b61aaf8797d9bec9d33f182ff28c2a0b3f8e8b078b559643d980d6c7f3ff57da9cf52bde8807120b9373e61851fd57373d51aa')

build() {
  cmake \
    -S ${pkgname}-${pkgver} \
    -B build \
    -DCMAKE_BUILD_TYPE=None \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_SHARED_LIBS=TRUE \
    -DCMAKE_CXX_STANDARD=23 \
    -DFAST_MATRIX_MARKET_BENCH=ON \
    -DFAST_MATRIX_MARKET_TEST=ON \
    -DFMM_USE_DRAGONBOX=ON \
    -DFMM_USE_FAST_FLOAT=ON \
    -DFMM_USE_RYU=ON \
    -Wno-dev
  cmake --build build --target all

  cd ${pkgname}-${pkgver}/python
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  ctest --verbose --output-on-failure --test-dir build
  cd ${pkgname}-${pkgver}/python
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m pytest
}

package() {
  DESTDIR="${pkgdir}" cmake --build build --target install
  install -Dm 644 ${pkgname}-${pkgver}/LICENSE.txt -t "${pkgdir}/usr/share/licenses/${pkgname}"
  cd ${pkgname}-${pkgver}/python
  PYTHONPYCACHEPREFIX="${PWD}/.cache/cpython/" python -m installer --destdir="${pkgdir}" dist/*.whl
  rm -r ${pkgdir}/usr/include/{blaze,eigen3,gtest,gmock}
  rm -r ${pkgdir}/usr/lib/cmake/GTest
  rm -r ${pkgdir}/usr/share/{blaze,eigen3}
  rm -r ${pkgdir}/usr/lib/lib{gmock*,gtest*}
  rm -r ${pkgdir}/usr/lib/pkgconfig{gmock*,gtest*}
}

The solution could be manually delete files in order to avoid duplication for gtest, blaze, eigen, and so on post cmake installation

alugowski commented 7 months ago

Hi @carlosal1015, can you clarify what you're trying to package? I see both C++ and Python dependencies mixed together even though those are separate packages.

There is already a good Python package on PyPI (built using the standard Python build methods), so I assume you're interested in packaging the C++ library? If so, drop all dependencies with python in their name.

For C++, the only dependency is a C++ 17 build system.

Eigen, Blaze, GraphBLAS, Armadillo, and such are optional test dependencies, to test the bindings for those libraries. FMM does not depend on those libraries in any way. To run the tests without these libraries, set FAST_MATRIX_MARKET_TEST_EXTERNAL_APPS to OFF. https://github.com/alugowski/fast_matrix_market/blob/4477fc30975592196bf03830844a0f6828cee380/tests/CMakeLists.txt#L92C8-L92C45 That would drop all test dependencies apart from GTest, and I believe would not fetchcontent any of them.

Another option for just testing if the library is installed is to compile one of the tiny example problems instead of the entire test suite. If the sample1 example builds and runs then FMM is working. No GTest required at all. If I were packaging for Conan or vcpkg I'd do this.

If running the entire test suite is desired then I'm open to suggestions on how to pull in GTest. Note that this CMakeLists.txt needs to work on Windows and macOS too, not just Linux.

Couple questions:

carlosal1015 commented 7 months ago

Thanks for the hint -DFAST_MATRIX_MARKET_TEST_EXTERNAL_APPS=OFF helped, no more files put over /usr/include/blaze, /usr/include/eigen3.

I setup C++23, because in this line it uses, but I move to C++ 17 now. Now is simplified, in this step I will focus only C+++ side.

asciicast

pkgname=fast_matrix_market
pkgdesc="Fast and full-featured Matrix Market I/O library"
pkgver=1.7.6
pkgrel=1
arch=(x86_64)
url="https://github.com/alugowski/${pkgname}"
license=(BSD-2-Clause)
depends=(gcc-libs)
makedepends=(cmake)
optdepends=('eigen' 'blaze' 'armadillo')
source=(${pkgname}-${pkgver}.tar.gz::${url}/archive/v${pkgver}.tar.gz)
sha512sums=('e97da2daf76770502e862a13b7b61aaf8797d9bec9d33f182ff28c2a0b3f8e8b078b559643d980d6c7f3ff57da9cf52bde8807120b9373e61851fd57373d51aa')

build() {
  cmake \
    -S ${pkgname}-${pkgver} \
    -B build \
    -DCMAKE_BUILD_TYPE=None \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_SHARED_LIBS=TRUE \
    -DCMAKE_CXX_STANDARD=17 \
    -DFAST_MATRIX_MARKET_BENCH=OFF \
    -DFAST_MATRIX_MARKET_TEST=ON \
    -DFAST_MATRIX_MARKET_TEST_EXTERNAL_APPS=OFF \
    -DFMM_USE_DRAGONBOX=ON \
    -DFMM_USE_FAST_FLOAT=ON \
    -DFMM_USE_RYU=ON \
    -Wno-dev
  cmake --build build --target all
}

check() {
  ctest --verbose --output-on-failure --test-dir build
}

package() {
  DESTDIR="${pkgdir}" cmake --build build --target install
  install -Dm 644 ${pkgname}-${pkgver}/LICENSE.txt -t "${pkgdir}/usr/share/licenses/${pkgname}"
  rm -r ${pkgdir}/usr/include/{gtest,gmock}
  rm -r ${pkgdir}/usr/lib/cmake/GTest
  rm -r ${pkgdir}/usr/lib/libgmock*
  rm -r ${pkgdir}/usr/lib/libgtest*
  rm -r ${pkgdir}/usr/lib/pkgconfig/gmock*
  rm -r ${pkgdir}/usr/lib/pkgconfig/gtest*
}
  1. I expected some file like /usr/lib/fast_matrix_market.so or /usr/lib/fast_matrix_market.so or /usr/include/fast_matrix_market/fast_matrix_market.hpp, therefore the script will not install fast_matrix_market.
  2. With -DFAST_MATRIX_MARKET_TEST=ON it will pull gtest, sometimes is nice if user has gtest installed, check if gtest version is compatible and try to use, otherwise pull from internet (for examples offline installation could be fail).

I can try help test almost over GitHub action for Windows or Mac.