From 8f61a97b158abeeaea4d38b3aca0c73d3afb4749 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 14 Aug 2023 17:17:53 -0400 Subject: [PATCH] Got a working Dockerfile for GNU --- Dockerfile.GNU-Linux | 92 +++++++++++++++++++++-------- buildscripts/fetch_dependencies.sh | 22 ++++++- cmake/Modules/SetFortranFlags.cmake | 12 ++-- setup.py | 1 - src/CMakeLists.txt | 1 - 5 files changed, 96 insertions(+), 32 deletions(-) diff --git a/Dockerfile.GNU-Linux b/Dockerfile.GNU-Linux index b8becbe6d..1e8a87a0d 100644 --- a/Dockerfile.GNU-Linux +++ b/Dockerfile.GNU-Linux @@ -13,40 +13,77 @@ # dynamically. # This build target compiles all dependencies and the swiftest driver itself -FROM condaforge/mambaforge:23.1.0-4 as build-deps -ENV SCRIPT_DIR="buildscripts" +FROM continuumio/miniconda3:23.5.2-0 as build-deps SHELL ["/bin/bash", "--login", "-c"] -ENV SHELL="/bin/bash" +ENV PATH="/opt/conda/bin:${PATH}" WORKDIR /swiftest -# Compile the dependencies -COPY ./${SCRIPT_DIR}/get_platform.sh ./${SCRIPT_DIR}/ -COPY ./${SCRIPT_DIR}/make_build_environment.sh ./${SCRIPT_DIR} -COPY ./${SCRIPT_DIR}/build_dependencies.sh ./${SCRIPT_DIR}/ -COPY ./${SCRIPT_DIR}/swiftest-build-env.yml ./${SCRIPT_DIR}/ -COPY ./${SCRIPT_DIR}/fetch_dependencies.sh ./${SCRIPT_DIR}/ -RUN ${SCRIPT_DIR}/fetch_dependencies.sh -RUN ${SCRIPT_DIR}/make_build_environment.sh && \ - echo "conda activate swiftest-build-env" >> ~/.bashrc && \ - /bin/bash -lic "${SCRIPT_DIR}/build_dependencies.sh GNU-Linux" +ENV INSTALL_DIR=/usr/local +ENV NCDIR="${INSTALL_DIR}" +ENV NFDIR="${INSTALL_DIR}" +ENV HDF5_ROOT="${INSTALL_DIR}" +ENV HDF5_LIBDIR="${HDF5_ROOT}/lib" +ENV HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" +ENV HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" +ENV LD_LIBRARY_PATH="${INSTALL_DIR}/lib" +ENV LDFLAGS="-L${INSTALL_DIR}/lib" +ENV CPPFLAGS="-I${INSTALL_DIR}/include" + +COPY ./buildscripts/swiftest-build-env.yml ./ +COPY ./buildscripts/fetch_dependencies.sh ./ +RUN ./fetch_dependencies.sh -d ./ + +# Get the HDF5, NetCDF-C, and NetCDF-Fortran libraries +RUN conda update --all -y && \ + conda install conda-libmamba-solver -y && \ + conda config --set solver libmamba && \ + conda env create --file swiftest-build-env.yml --name swiftest-build-env && \ + conda init bash && \ + echo "conda activate swiftest-build-env" >> ~/.bashrc -FROM condaforge/mambaforge:23.1.0-4 as build-swiftest -ENV SCRIPT_DIR="buildscripts" +RUN cd zlib-* && \ + ./configure \ + --prefix=${INSTALL_DIR} \ + --static && \ + make && make install && \ + cd ../hdf5-* && \ + ./configure \ + --prefix=${INSTALL_DIR} \ + --disable-shared \ + --enable-build-mode=production \ + --disable-fortran \ + --disable-java \ + --disable-cxx \ + --with-zlib=${INSTALL_DIR} && \ + make && make install && \ + cd ../netcdf-c-* && \ + ./configure \ + --prefix=${INSTALL_DIR} \ + --disable-shared \ + --disable-dap \ + --disable-libxml2 \ + --disable-byterange && \ + make && make install && \ + cd ../netcdf-fortran-* && \ + export CFLAGS="-fPIC" && \ + export FCFLAGS="${CFLAGS}" && \ + export FFLAGS=${CFLAGS} && \ + export LIBS=$(${INSTALL_DIR}/bin/nc-config --libs --static) && \ + ./configure --disable-shared --prefix=${NFDIR} && \ + make && make install + +FROM continuumio/miniconda3:23.5.2-0 as build-swiftest 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/ +ENV INSTALL_DIR=/usr/local +COPY --from=build-deps ${INSTALL_DIR}/ ${INSTALL_DIR}/ COPY --from=build-deps /opt/conda/envs/ /opt/conda/envs/ COPY --from=build-deps /root/.bashrc /root/ # Compile the Swiftest project -COPY ./buildscripts/build_swiftest.sh ./buildscripts/ COPY ./cmake/ ./cmake/ COPY ./src/ ./src/ COPY ./swiftest/ ./swiftest/ @@ -56,9 +93,18 @@ COPY ./environment.yml ./ COPY ./pyproject.toml ./ COPY ./requirements.txt ./ COPY ./version.txt ./ + +# Generate the build environment in conda ENV PIP_ROOT_USER_ACTION=ignore -RUN /bin/bash -lic "${SCRIPT_DIR}/build_swiftest.sh GNU-Linux /usr/local" +ENV LDFLAGS="-L${INSTALL_DIR}/lib" +ENV CFLAGS="-fPIC" +ENV FFLAGS=${CFLAGS} +ENV SKBUILD_CONFIGURE_OPTIONS="-DBUILD_SHARED_LIBS=OFF -DMACHINE_CODE_VALUE=\"native\"" +RUN export NFCFG="${INSTALL_DIR}/bin/nf-config" && \ + export LIBS=$($NFCFG --flibs) && \ + python3 -m pip install build pip && \ + python3 -m build --wheel #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 +COPY --from=build-swiftest /swiftest/dist/ ./ \ No newline at end of file diff --git a/buildscripts/fetch_dependencies.sh b/buildscripts/fetch_dependencies.sh index dc31aff66..f0e615633 100755 --- a/buildscripts/fetch_dependencies.sh +++ b/buildscripts/fetch_dependencies.sh @@ -12,10 +12,26 @@ # If not, see: https://www.gnu.org/licenses. SCRIPT_DIR=$(realpath $(dirname $0)) ROOT_DIR=$(realpath ${SCRIPT_DIR}/..) -BUILD_DIR="${ROOT_DIR}/build" -mkdir -p ${BUILD_DIR} -cd $BUILD_DIR +# Parse arguments +USTMT="Usage: ${0} <-d /path/to/download]" +DOWNLOAD_DIR="${ROOT_DIR}/build" +while getopts ":d:" ARG; do + case "${ARG}" in + d) + DOWNLOAD_DIR="${OPTARG}" + ;; + :) + echo "Error: -${OPTARG} requires an argument." + echo $USTMT + exit 1 + ;; + *) + ;; + esac +done +mkdir -p ${DOWNLOAD_DIR} +cd $DOWNLOAD_DIR wget -qO- https://www.zlib.net/zlib-1.2.13.tar.gz | tar xvz wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.1/src/hdf5-1.14.1-2.tar.gz | tar xvz wget -qO- https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz | tar xvz diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index 95c7f5d3f..eebd974c6 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -144,12 +144,12 @@ IF (NOT BUILD_SHARED_LIBS) ENDIF (NOT BUILD_SHARED_LIBS) IF (USE_SIMD) - SET(MACHINE_CODE_VALUE "Host") IF (COMPILER_OPTIONS STREQUAL "Intel") + SET(MACHINE_CODE_VALUE "Host" CACHE STRING "Tells the compiler which processor features it may target, including which instruction sets and optimizations it may generate.") IF (MACHINE_CODE_VALUE STREQUAL "generic") - SET(MACHINE_CODE_VALUE "SSE2" FORCE) # SSE2 is the Intel equivalent of generic + SET(MACHINE_CODE_VALUE "SSE2" CACHE STRING "SSE2 is the safest option when compiling for non-host compatibility" FORCE) ENDIF() # Enables OpenMP SIMD compilation when OpenMP parallelization is disabled. @@ -172,6 +172,7 @@ IF (USE_SIMD) "/Qvecabi:cmdtarget" # Intel Windows ) ELSEIF (COMPILER_OPTIONS STREQUAL "GNU") + SET(MACHINE_CODE_VALUE "native" CACHE STRING "Tells the compiler which processor features it may target, including which instruction sets and optimizations it may generate.") # Enables OpenMP SIMD compilation when OpenMP parallelization is disabled. IF (NOT USE_OPENMP) @@ -180,8 +181,8 @@ IF (USE_SIMD) ) ENDIF (NOT USE_OPENMP) - IF (MACHINE_CODE_VALUE STREQUAL "host") - SET(MACHINE_CODE_VALUE "native" CACHE STRING "Tells the compiler which processor features it may target, including which instruction sets and optimizations it may generate.") + IF (MACHINE_CODE_VALUE STREQUAL "Host") + SET(MACHINE_CODE_VALUE "native" CACHE STRING "native is the GNU equivalent of Host" FORCE) ENDIF () IF (APPLE) @@ -192,6 +193,9 @@ IF (USE_SIMD) SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-march=${MACHINE_CODE_VALUE}" ) + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + Fortran "-mtune=${MACHINE_CODE_VALUE}" + ) ENDIF () ENDIF () diff --git a/setup.py b/setup.py index 8b9053d68..def08d578 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,6 @@ cmake_args = [ '-DCMAKE_BUILD_TYPE=RELEASE', - '-DMACHINE_CODE_VALUE="generic"', '-DUSE_COARRAY:BOOL=OFF', '-DUSE_OPENMP:BOOL=ON', ] diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d30edc85f..59a89a4b6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,7 +34,6 @@ ENDIF () # RELEASE, PROFILING, and TESTING. INCLUDE(SetFortranFlags) - # Add the source files SET(STRICT_MATH_FILES ${SRC}/collision/collision_generate.f90