From 88e40e5bc6b908ce4845307a93f2b6e35ccf1442 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 11 Aug 2023 16:26:51 -0400 Subject: [PATCH] More updates to get an automated build working and exporting a Python wheel file for a particular build --- .dockerignore | 1 + Dockerfile | 32 ++++++++++++++++++++++++++++++-- buildscripts/build_swiftest.sh | 11 +++++++---- cmake/Modules/FindNETCDF.cmake | 10 +++++----- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/.dockerignore b/.dockerignore index 1d60b6d6e..70c189136 100644 --- a/.dockerignore +++ b/.dockerignore @@ -17,5 +17,6 @@ !swiftest/*.h !swiftest/tests/*.py !src/*/*.f90 +!src/globals/globals_module.f90.in !buildscripts/*.sh !buildscripts/*.yml diff --git a/Dockerfile b/Dockerfile index a89fe35ec..9f79ef685 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,11 @@ ENV SHELL="/bin/bash" WORKDIR /swiftest # Compile the dependencies -COPY ./buildscripts ./buildscripts/ +COPY ./buildscripts/fetch_dependencies.sh ./buildscripts/ +COPY ./buildscripts/get_platform.sh ./buildscripts/ +COPY ./buildscripts/make_build_environment.sh ./buildscripts/ +COPY ./buildscripts/build_dependencies.sh ./buildscripts/ +COPY ./buildscripts/swiftest-build-env.yml ./buildscripts/ RUN ${SCRIPT_DIR}/fetch_dependencies.sh RUN if [ "$BUILDIMAGE" = "intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04" ]; then \ apt-get update && \ @@ -33,7 +37,22 @@ RUN if [ "$BUILDIMAGE" = "intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04" ]; the echo "conda activate swiftest-build-env" >> ~/.bashrc && \ /bin/bash -lic "${SCRIPT_DIR}/build_dependencies.sh GNU"; \ fi + +FROM ${BUILDIMAGE} as build-swiftest +ENV SCRIPT_DIR="buildscripts" +SHELL ["/bin/bash", "--login", "-c"] +ENV SHELL="/bin/bash" +WORKDIR /swiftest +ENV BUILD_DIR=/swiftest/build + +# Copy build artifacts over to the swiftest package builder stage +COPY --from=build-deps ${BUILD_DIR}/lib/ /usr/local/lib/ +COPY --from=build-deps ${BUILD_DIR}/include/ /usr/local/include/ +COPY --from=build-deps ${BUILD_DIR}/bin/ /usr/local/bin/ +COPY --from=build-deps ${BUILD_DIR}/share/ /usr/local/share/ + # Compile the Swiftest project +COPY ./buildscripts/build_swiftest.sh ./buildscripts/ COPY ./cmake/ ./cmake/ COPY ./src/ ./src/ COPY ./swiftest/ ./swiftest/ @@ -43,4 +62,13 @@ COPY ./environment.yml ./ COPY ./pyproject.toml ./ COPY ./requirements.txt ./ COPY ./version.txt ./ -RUN /bin/bash -lic "${SCRIPT_DIR}/build_swiftest.sh" \ No newline at end of file +ENV PIP_ROOT_USER_ACTION=ignore +RUN if [ "$BUILDIMAGE" = "intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04" ]; then \ + /bin/bash -lic "${SCRIPT_DIR}/build_swiftest.sh Intel"; \ + else \ + /bin/bash -lic "${SCRIPT_DIR}/build_swiftest.sh GNU"; \ + fi + +#Export the generated wheel file to the host machine +FROM scratch as export-wheel +COPY --from=build-swiftest /swiftest/dist/ /dist/ \ No newline at end of file diff --git a/buildscripts/build_swiftest.sh b/buildscripts/build_swiftest.sh index bb4dc18f5..b7973895f 100755 --- a/buildscripts/build_swiftest.sh +++ b/buildscripts/build_swiftest.sh @@ -49,9 +49,10 @@ esac export F77=${FC} echo "Using $COMPILER compilers:\nFC: $FC\nCC: $CC\nCXX: $CXX\n" -export CPATH=$DEPDIR -export LD_LIBRARY_PATH="${CPATH}/lib:${LD_LIBRARY_PATH}" -export LIBS="-lhdf5_hl -lhdf5 -lz" +export CPATH=$DEPDIR/include +export NETCDF_FORTRAN_HOME=$DEPDIR +export LD_LIBRARY_PATH="${DEPDIR}/lib:${LD_LIBRARY_PATH}" +export LIBS=$(${DEPDIR}/bin/nf-config --all) export LDFLAGS="-L${DEPDIR}/lib" export CFLAGS="-fPIC" export CMAKE_ARGS="-DBUILD_SHARED_LIBS=OFF" @@ -64,4 +65,6 @@ else export FFLAGS="${CFLAGS}" fi cd $ROOT_DIR -pip install . +python -m pip install build +python -m build --wheel + diff --git a/cmake/Modules/FindNETCDF.cmake b/cmake/Modules/FindNETCDF.cmake index 0a641f714..5ba87662e 100644 --- a/cmake/Modules/FindNETCDF.cmake +++ b/cmake/Modules/FindNETCDF.cmake @@ -9,12 +9,12 @@ # - Finds the NetCDF libraries -find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN_HOME ENV CPATH) -find_library(NETCDF_FORTRAN_LIBRARY NAMES netcdff HINTS ENV NETCDF_FORTRAN_HOME ENV LD_LIBRARY_PATH) -find_library(NETCDF_LIBRARY NAMES netcdf HINTS ENV NETCDF_FORTRAN_HOME ENV LD_LIBRARY_PATH) +find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN_HOME) +find_library(NETCDF_FORTRAN_LIBRARY NAMES netcdff HINTS ENV NETCDF_FORTRAN_HOME) +find_library(NETCDF_LIBRARY NAMES netcdf HINTS ENV NETCDF_FORTRAN_HOME) set(NETCDF_FOUND TRUE) # Note for posterity: When building static libraries, NETCDF_FORTRAN_LIBRARY must come *before* NETCDF_LIBRARY. Otherwise you get a bunch of "undefined reference to" errors -set(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY} CACHE STRING "NetCDF libraries") -mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR) \ No newline at end of file +mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR) +set(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY} CACHE STRING "NetCDF libraries") \ No newline at end of file