From c509e29b526cdc67332265bbb3d6446052d2eaee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=B6jdh?= Date: Tue, 29 Oct 2024 11:19:20 +0100 Subject: [PATCH] building with scikit build --- conda-recipe/build.sh | 20 ------- conda-recipe/copy_lib.sh | 19 ------- conda-recipe/meta.yaml | 116 ++++++++++----------------------------- pyproject.toml | 14 +++++ python/CMakeLists.txt | 30 ++++++---- python/aare/__init__.py | 5 +- 6 files changed, 64 insertions(+), 140 deletions(-) delete mode 100644 conda-recipe/build.sh delete mode 100644 conda-recipe/copy_lib.sh create mode 100644 pyproject.toml diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh deleted file mode 100644 index f8f77c7..0000000 --- a/conda-recipe/build.sh +++ /dev/null @@ -1,20 +0,0 @@ - - -mkdir build -mkdir install -cd build -cmake .. \ - -DCMAKE_PREFIX_PATH=$CONDA_PREFIX \ - -DCMAKE_INSTALL_PREFIX=install \ - -DAARE_SYSTEM_LIBRARIES=ON \ - -DAARE_TESTS=ON \ - -DAARE_PYTHON_BINDINGS=ON \ - -DCMAKE_BUILD_TYPE=Release \ - - -NCORES=$(getconf _NPROCESSORS_ONLN) -echo "Building using: ${NCORES} cores" -cmake --build . -- -j${NCORES} -cmake --build . --target install - -# CTEST_OUTPUT_ON_FAILURE=1 ctest -j 1 \ No newline at end of file diff --git a/conda-recipe/copy_lib.sh b/conda-recipe/copy_lib.sh deleted file mode 100644 index 996e05b..0000000 --- a/conda-recipe/copy_lib.sh +++ /dev/null @@ -1,19 +0,0 @@ -mkdir -p $PREFIX/lib -mkdir -p $PREFIX/bin -mkdir -p $PREFIX/include/aare - - -#Shared and static libraries -cp build/install/lib/* $PREFIX/lib/ - -#Binaries -# cp build/install/bin/sls_detector_acquire $PREFIX/bin/. -# cp build/install/bin/sls_detector_get $PREFIX/bin/. -# cp build/install/bin/sls_detector_put $PREFIX/bin/. -# cp build/install/bin/sls_detector_help $PREFIX/bin/. -# cp build/install/bin/slsReceiver $PREFIX/bin/. -# cp build/install/bin/slsMultiReceiver $PREFIX/bin/. - - -cp build/install/include/aare/* $PREFIX/include/aare -cp -rv build/install/share $PREFIX \ No newline at end of file diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index 5b9a88d..2697af8 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -1,104 +1,44 @@ - - package: - name: aare_software - version: {{ environ.get('GIT_DESCRIBE_TAG', '') }} + name: aare + version: 2024.10.29.dev0 #TODO! how to not duplicate this? source: - - path: .. + path: .. build: number: 0 - binary_relocation: True - rpaths: - - lib/ + script: + - unset CMAKE_GENERATOR && {{ PYTHON }} -m pip install . -vv # [not win] + - {{ PYTHON }} -m pip install . -vv # [win] requirements: build: - - {{ compiler('c') }} - - {{compiler('cxx')}} - - cmake - # - qt 5.* - # - xorg-libx11 - # - xorg-libice - # - xorg-libxext - # - xorg-libsm - # - xorg-libxau - # - xorg-libxrender - # - xorg-libxfixes - # - {{ cdt('mesa-libgl-devel') }} # [linux] - # - {{ cdt('mesa-libegl-devel') }} # [linux] - # - {{ cdt('mesa-dri-drivers') }} # [linux] - # - {{ cdt('libselinux') }} # [linux] - # - {{ cdt('libxdamage') }} # [linux] - # - {{ cdt('libxxf86vm') }} # [linux] - # - expat + - python + - {{ compiler('cxx') }} host: - # - libstdcxx-ng - # - libgcc-ng - # - xorg-libx11 - # - xorg-libice - # - xorg-libxext - # - xorg-libsm - # - xorg-libxau - # - xorg-libxrender - # - xorg-libxfixes - # - expat + - cmake + - ninja + - python + - pip + - scikit-build-core + - pybind11 >=2.13.0 + - fmt run: - # - libstdcxx-ng - # - libgcc-ng + - python -outputs: - - name: aarelib - script: copy_lib.sh +test: + imports: + - aare + # requires: + # - pytest + # source_files: + # - tests + # commands: + # - pytest tests - requirements: - build: - - {{ compiler('c') }} - - {{compiler('cxx')}} - - catch2 - - zstd - - # - libstdcxx-ng - # - libgcc-ng - - - run: - # - libstdcxx-ng - # - libgcc-ng - - # - name: aare - - # script: build_pylib.sh - - # requirements: - # build: - # - python - # - {{ compiler('c') }} - # - {{compiler('cxx')}} - # - {{ pin_subpackage('slsdetlib', exact=True) }} - # - setuptools - # - pybind11=2.11 - - # host: - # - python - # - {{ pin_subpackage('slsdetlib', exact=True) }} - # - pybind11=2.11 - - - # run: - # - libstdcxx-ng - # - libgcc-ng - # - python - # - numpy - # - {{ pin_subpackage('slsdetlib', exact=True) }} - - - # test: - # imports: - # - slsdet - - \ No newline at end of file +about: + summary: An example project built with pybind11 and scikit-build. + # license_file: LICENSE \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..090203a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[build-system] +requires = ["scikit-build-core>=0.10", "pybind11"] +build-backend = "scikit_build_core.build" + +[project] +name = "aare" +version = "2024.10.29.dev0" + +[tool.scikit-build] +cmake.verbose = true + +[tool.scikit-build.cmake.define] +AARE_PYTHON_BINDINGS = "ON" +AARE_SYSTEM_LIBRARIES = "ON" \ No newline at end of file diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 98436ac..b104cd2 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,34 +1,44 @@ +# Download or find pybind11 depending on configuration if(AARE_FETCH_PYBIND11) FetchContent_Declare( pybind11 GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG v2.11.0 + GIT_TAG v2.13.0 ) FetchContent_MakeAvailable(pybind11) else() - find_package(pybind11 2.11 REQUIRED) + find_package(pybind11 2.13 REQUIRED) endif() - +# Add the compiled python extension pybind11_add_module( - _aare - src/module.cpp + _aare # name of the module + src/module.cpp # source file ) + set_target_properties(_aare PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} ) target_link_libraries(_aare PRIVATE aare_core aare_compiler_flags) +# List of python files to be copied to the build directory set( PYTHON_FILES aare/__init__.py ) +# Copy the python files to the build directory foreach(FILE ${PYTHON_FILES}) - configure_file( ${FILE} - ${CMAKE_BINARY_DIR}/${FILE} ) + configure_file(${FILE} ${CMAKE_BINARY_DIR}/${FILE} ) endforeach(FILE ${PYTHON_FILES}) +set_target_properties(_aare PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/aare +) -configure_file( examples/play.py - ${CMAKE_BINARY_DIR}/play.py -) \ No newline at end of file + + +# Copy the examples/scripts to the build directory +configure_file(examples/play.py ${CMAKE_BINARY_DIR}/play.py) + + +install(TARGETS _aare DESTINATION aare) \ No newline at end of file diff --git a/python/aare/__init__.py b/python/aare/__init__.py index 96b9308..8709bca 100644 --- a/python/aare/__init__.py +++ b/python/aare/__init__.py @@ -1,3 +1,2 @@ - - -from _aare import File \ No newline at end of file +# Make the compiled classes that live in _aare available from aare. +from ._aare import File \ No newline at end of file