Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Got a working Dockerfile for GNU
Browse files Browse the repository at this point in the history
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Aug 14, 2023
1 parent 304989f commit 8f61a97
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 32 deletions.
92 changes: 69 additions & 23 deletions Dockerfile.GNU-Linux
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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/
COPY --from=build-swiftest /swiftest/dist/ ./
22 changes: 19 additions & 3 deletions buildscripts/fetch_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions cmake/Modules/SetFortranFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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 ()
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

cmake_args = [
'-DCMAKE_BUILD_TYPE=RELEASE',
'-DMACHINE_CODE_VALUE="generic"',
'-DUSE_COARRAY:BOOL=OFF',
'-DUSE_OPENMP:BOOL=ON',
]
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ ENDIF ()
# RELEASE, PROFILING, and TESTING.
INCLUDE(SetFortranFlags)


# Add the source files
SET(STRICT_MATH_FILES
${SRC}/collision/collision_generate.f90
Expand Down

0 comments on commit 8f61a97

Please sign in to comment.