From d955405245b150bc5f92f0520cd061a7651fed3f Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Tue, 8 Aug 2023 10:04:41 -0400 Subject: [PATCH] Continued restructuring and started adding skbuild to the python side to help automate the building of the extension module --- .gitignore | 2 ++ Dockerfile | 28 +++++++++++++++++----------- python/CMakeLists.txt | 4 ++++ python/setup.py | 8 ++++++-- python/setup.py.in | 8 ++++++-- src/CMakeLists.txt | 2 +- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index fff9d130a..bfbcc463e 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,8 @@ dump* **/.DS_Store !python/swiftest/tests/test_suite.py !version.txt +**/_skbuild + #Documentation diff --git a/Dockerfile b/Dockerfile index ef73edf90..3114bb0e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -76,8 +76,19 @@ RUN cd netcdf-fortran-4.6.1 && \ make install FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build_driver -SHELL ["/bin/bash", "--login", "-c"] +SHELL ["/bin/bash", "-c"] COPY --from=build_deps /usr/local/. /usr/local/ +ENV PATH /root/miniconda3/bin:$PATH + +RUN wget https://repo.anaconda.com/miniconda/Miniconda3-py311_23.5.2-0-Linux-x86_64.sh && \ + /bin/bash Miniconda3-py311_23.5.2-0-Linux-x86_64.sh -b && \ + /root/miniconda3/bin/conda init bash && \ + source /root/.bashrc && conda update --all -y && \ + conda install conda-libmamba-solver -y && \ + conda config --set solver libmamba && \ + conda install -c conda-forge scikit-build -y&& \ + conda install -c anaconda cython -y + ENV INSTALL_DIR="/usr/local" ENV CC="${ONEAPI_ROOT}/compiler/latest/linux/bin/icx" ENV FC="${ONEAPI_ROOT}/compiler/latest/linux/bin/ifx" @@ -103,26 +114,21 @@ ENV NETCDF_FORTRAN_HOME=${NETCDF_HOME} ENV NETCDF_LIBRARY=${NETCDF_HOME} ENV FOR_COARRAY_NUM_IMAGES=1 ENV OMP_NUM_THREADS=1 + ENV FC="${ONEAPI_ROOT}/mpi/latest/bin/mpiifort" +ENV CC="${ONEAPI_ROOT}/mpi/latest/bin/mpicc -cc=icx" +ENV CXX="${ONEAPI_ROOT}/mpi/latest/bin/mpicc -cc=icpx" ENV FFLAGS="-fPIC -standard-semantics" ENV LDFLAGS="-L/usr/local/lib" ENV LIBS="-lhdf5_hl -lhdf5 -lz" -ENV PATH /root/miniconda3/bin:$PATH COPY ./cmake/ /swiftest/cmake/ COPY ./src/ /swiftest/src/ COPY ./CMakeLists.txt /swiftest/ COPY ./python/ /swiftest/python/ COPY ./version.txt /swiftest/ -RUN wget https://repo.anaconda.com/miniconda/Miniconda3-py311_23.5.2-0-Linux-x86_64.sh && \ - /usr/bin/bash Miniconda3-py311_23.5.2-0-Linux-x86_64.sh -b && \ - /root/miniconda3/bin/conda init bash && \ - source /root/.bashrc && conda update --all -y && \ - conda install conda-libmamba-solver -y && \ - conda config --set solver libmamba && \ - conda install -c conda-forge numpy -y&& \ - conda install -c anaconda cython -y && \ - cd swiftest && \ + +RUN cd swiftest && \ cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \ -DMACHINE_CODE_VALUE=${MACHINE_CODE_VALUE} \ -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 1bfe6dba0..9a6026279 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -8,3 +8,7 @@ SET(SETUP_PY_IN "${PY}/setup.py.in") SET(SETUP_PY_OUT "${PY}/setup.py") CONFIGURE_FILE(${SETUP_PY_IN} ${SETUP_PY_OUT}) + +# ADD_LIBRARY(pybindings MODULE hello/_hello.cxx) +# python_extension_module(_hello) +# install(TARGETS _hello LIBRARY DESTINATION hello) \ No newline at end of file diff --git a/python/setup.py b/python/setup.py index cc21e2f32..bb22ad5ce 100644 --- a/python/setup.py +++ b/python/setup.py @@ -10,7 +10,9 @@ If not, see: https://www.gnu.org/licenses. """ -from setuptools import setup, find_packages, Extension +#from skbuild import setup +from setuptools import setup +from setuptools import find_packages, Extension from Cython.Build import cythonize import os @@ -19,7 +21,7 @@ include_dirs = "/Users/daminton/git/swiftest/apple_install/usr/local/include;/Users/daminton/git/swiftest/apple_install/usr/local/include" include_dirs = include_dirs.split() include_dirs.append(root_dir) -link_flags = " -static-libgfortran -static-libgcc -static-libstdc++" +link_flags = " -static-libgfortran -static-libgcc -static-libstdc++ -L/Users/daminton/git/swiftest/lib -lswiftest /Users/daminton/git/swiftest/apple_install/usr/local/lib/libnetcdff.a /Users/daminton/git/swiftest/apple_install/usr/local/lib/libnetcdf.a -L/Users/daminton/git/swiftest/apple_install/usr/local/lib -lhdf5_hl -lhdf5 -lm -lz -lbz2 -lxml2 -lcurl" link_flags = link_flags.split() pybindings_extension = [Extension('swiftest.bindings', @@ -34,5 +36,7 @@ author='David A. Minton', author_email='daminton@purdue.edu', url='https://github.itap.purdue.edu/MintonGroup/swiftest', + python_requires=">3.8", + license="GPLv3", ext_modules = cythonize(pybindings_extension), packages=find_packages()) diff --git a/python/setup.py.in b/python/setup.py.in index 8a111a7d5..e59a074e2 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -10,7 +10,9 @@ If not, see: https://www.gnu.org/licenses. """ -from setuptools import setup, find_packages, Extension +#from skbuild import setup +from setuptools import setup +from setuptools import find_packages, Extension from Cython.Build import cythonize import os @@ -19,7 +21,7 @@ root_dir = 'pybindings' include_dirs = "${SWIFTEST_INCLUDE_DIR}" include_dirs = include_dirs.split() include_dirs.append(root_dir) -link_flags = "${CMAKE_Fortran_LINK_FLAGS}" +link_flags = "${SWIFTEST_LINK_FLAGS}" link_flags = link_flags.split() pybindings_extension = [Extension('swiftest.bindings', @@ -34,5 +36,7 @@ setup(name='swiftest', author='David A. Minton', author_email='daminton@purdue.edu', url='https://github.itap.purdue.edu/MintonGroup/swiftest', + python_requires=">3.8", + license="GPLv3", ext_modules = cythonize(pybindings_extension), packages=find_packages()) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 686a0627c..b10437cba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -131,7 +131,7 @@ IF(USE_COARRAY) SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY LINK_FLAGS "${Coarray_Fortran_FLAGS} ") ENDIF(USE_COARRAY) -STRING(REPLACE ";" " " SWIFTEST_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS} ${CMAKE_LINK_LIBRARY_FLAG}${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS}") +STRING(REPLACE ";" " " SWIFTEST_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS} -L${LIB} ${CMAKE_LINK_LIBRARY_FLAG}${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS}") SET(SWIFTEST_LINK_FLAGS "${SWIFTEST_LINK_FLAGS}" CACHE STRING "Link flags to pass to setup.py") GET_TARGET_PROPERTY(SWIFTEST_INCLUDE_DIR ${SWIFTEST_DRIVER} INCLUDE_DIRECTORIES)