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

Commit

Permalink
Made significant changes to build scripts. Now use CMake to build dep…
Browse files Browse the repository at this point in the history
…endencies for speed
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Sep 21, 2023
1 parent d43cab7 commit e7b86b4
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 48 deletions.
8 changes: 6 additions & 2 deletions buildscripts/_build_getopts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ set -a
SCRIPT_DIR=$(realpath $(dirname $0))
ROOT_DIR=$(realpath ${SCRIPT_DIR}/..)

# Get platform and architecture
read -r OS ARCH < <($SCRIPT_DIR/get_platform.sh)

# Parse arguments
USTMT="Usage: ${0} [-d /path/to/dependency/source] [-p /prefix/path] [-m MACOSX_DEPLOYMENT_TARGET]"
MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"$(sw_vers --ProductVersion)"}
if [ $OS = "MacOSX" ]; then
MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"$(sw_vers --ProductVersion)"}
fi

while getopts ":d:p:m:h" ARG; do
case "${ARG}" in
Expand Down Expand Up @@ -44,7 +49,6 @@ while getopts ":d:p:m:h" ARG; do
esac
done

read -r OS ARCH < <($SCRIPT_DIR/get_platform.sh)
BUILD_DIR=${BUILD_DIR:-$(mktemp -ut swiftest_build.XXXXXXXX)}
PREFIX=${PREFIX:-${ROOT_DIR}}
DEPENDENCY_DIR=${DEPENDENCY_DIR:-${BUILD_DIR}}
Expand Down
12 changes: 1 addition & 11 deletions buildscripts/build_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,9 @@ SCRIPT_DIR=$(realpath $(dirname $0))
set -a
ARGS=$@
. ${SCRIPT_DIR}/_build_getopts.sh ${ARGS}
NPROC=$(nproc)

cd $ROOT_DIR
printf "*********************************************************\n"
printf "* STARTING DEPENDENCY BUILD *\n"
printf "*********************************************************\n"
printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n"
printf "Installing to ${PREFIX}\n"
printf "\n"

# Get the OpenMP Libraries
if [ $OS = "MacOSX" ]; then
${SCRIPT_DIR}/get_lomp.sh ${ARGS}
fi

set -e
${SCRIPT_DIR}/build_zlib.sh ${ARGS}
Expand Down
29 changes: 17 additions & 12 deletions buildscripts/build_hdf5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ SCRIPT_DIR=$(realpath $(dirname $0))
set -a
ARGS=$@
. ${SCRIPT_DIR}/_build_getopts.sh ${ARGS}
. ${SCRIPT_DIR}/set_compilers.sh
# Get the OpenMP Libraries
if [ $OS = "MacOSX" ]; then
${SCRIPT_DIR}/get_lomp.sh ${ARGS}
fi

printf "*********************************************************\n"
printf "* STARTING DEPENDENCY BUILD *\n"
printf "*********************************************************\n"
printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n"
printf "Installing to ${PREFIX}\n"
printf "\n"

HDF5_VER="1_14_2"
printf "*********************************************************\n"
Expand Down Expand Up @@ -51,20 +63,13 @@ printf "LDFLAGS: ${LDFLAGS}\n"
printf "*********************************************************\n"

cd ${DEPENDENCY_DIR}/hdfsrc
if [ $OS = "MacOSX" ]; then
read -r OS ARCH < <($SCRIPT_DIR/get_platform.sh)
if [ $ARCH = "arm64" ]; then
printf "Manually setting bin/config.sub to arm-apple-darwin\n"
printf "echo arm-apple-darwin" > bin/config.sub
fi
fi
COPTS="--enable-build-mode=production --enable-tests=no --enable-tools=no --disable-fortran --disable-java --disable-cxx --prefix=${PREFIX} --with-zlib=${PREFIX}"
./configure ${COPTS}
make
ZLIB_ROOT=${PREFIX}
cmake -B build -S . -G Ninja
cmake --build build -j${NPROC}
if [ -w ${PREFIX} ]; then
make install
cmake --install build --prefix ${PREFIX}
else
sudo make install
sudo cmake --install build --prefix ${PREFIX}
fi

if [ $? -ne 0 ]; then
Expand Down
23 changes: 15 additions & 8 deletions buildscripts/build_netcdf-c.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@
# You should have received a copy of the GNU General Public License along with Swiftest.
# If not, see: https://www.gnu.org/licenses.
SCRIPT_DIR=$(realpath $(dirname $0))

set -a
ARGS=$@
. ${SCRIPT_DIR}/_build_getopts.sh ${ARGS}
. ${SCRIPT_DIR}/set_compilers.sh
# Get the OpenMP Libraries
if [ $OS = "MacOSX" ]; then
${SCRIPT_DIR}/get_lomp.sh ${ARGS}
fi

printf "*********************************************************\n"
printf "* STARTING DEPENDENCY BUILD *\n"
printf "*********************************************************\n"
printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n"
printf "Installing to ${PREFIX}\n"
printf "\n"

NC_VER="4.9.2"

Expand Down Expand Up @@ -43,15 +53,12 @@ printf "HDF5_ROOT: ${HDF5_ROOT}\n"
printf "*********************************************************\n"

cd ${DEPENDENCY_DIR}/netcdf-c-*
COPTS="--disable-testsets --disable-nczarr --prefix=${PREFIX}"
printf "COPTS: ${COPTS}\n"
./configure $COPTS
make && make check

cmake -B build -S . -G Ninja
cmake --build build -j${NPROC}
if [ -w ${PREFIX} ]; then
make install
cmake --install build --prefix ${PREFIX}
else
sudo make install
sudo cmake --install build --prefix ${PREFIX}
fi

if [ $? -ne 0 ]; then
Expand Down
29 changes: 24 additions & 5 deletions buildscripts/build_netcdf-fortran.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ SCRIPT_DIR=$(realpath $(dirname $0))
set -a
ARGS=$@
. ${SCRIPT_DIR}/_build_getopts.sh ${ARGS}
. ${SCRIPT_DIR}/set_compilers.sh
# Get the OpenMP Libraries
if [ $OS = "MacOSX" ]; then
${SCRIPT_DIR}/get_lomp.sh ${ARGS}
fi

printf "*********************************************************\n"
printf "* STARTING DEPENDENCY BUILD *\n"
printf "*********************************************************\n"
printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n"
printf "Installing to ${PREFIX}\n"
printf "\n"

NF_VER="4.6.1"
printf "*********************************************************\n"
Expand All @@ -24,7 +36,8 @@ if [ ! -d ${DEPENDENCY_DIR}/netcdf-fortran-${NF_VER} ]; then
[ -d ${DEPENDENCY_DIR}/netcdf-fortran-* ] && rm -rf ${DEPENDENCY_DIR}/netcdf-fortran-*
curl -s -L https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v${NF_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR}
fi

CFLAGS="$(nc-config --cflags) $CFLAGS"
LIBS="$(nc-config --libs) $LIBS"
printf "\n"
printf "*********************************************************\n"
printf "* BUILDING NETCDF-FORTRAN LIBRARY *\n"
Expand All @@ -38,12 +51,18 @@ printf "LDFLAGS: ${LDFLAGS}\n"
printf "*********************************************************\n"

cd ${DEPENDENCY_DIR}/netcdf-fortran-*
./configure --enable-large-file-tests=no --enable-static=no --enable-filter-test=no --prefix=${PREFIX}
make && make check i

if [ $OS = "MacOSX" ]; then
netCDF_LIBRARIES="${PREFIX}/lib/libnetcdf.dylib"
else
netCDF_LIBRARIES="${PREFIX}/lib/libnetcdf.so"
fi
cmake -B build -S . -G Ninja -DnetCDF_INCLUDE_DIR="${PREFIX}/include" -DnetCDF_LIBRARIES="${netCDF_LIBRARIES}"
cmake --build build -j${NPROC}
if [ -w ${PREFIX} ]; then
make install
cmake --install build --prefix ${PREFIX}
else
sudo make install
sudo cmake --install build --prefix ${PREFIX}
fi

if [ $? -ne 0 ]; then
Expand Down
19 changes: 15 additions & 4 deletions buildscripts/build_zlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@ SCRIPT_DIR=$(realpath $(dirname $0))
set -a
ARGS=$@
. ${SCRIPT_DIR}/_build_getopts.sh ${ARGS}
. ${SCRIPT_DIR}/set_compilers.sh
# Get the OpenMP Libraries
if [ $OS = "MacOSX" ]; then
${SCRIPT_DIR}/get_lomp.sh ${ARGS}
fi

printf "*********************************************************\n"
printf "* STARTING DEPENDENCY BUILD *\n"
printf "*********************************************************\n"
printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n"
printf "Installing to ${PREFIX}\n"
printf "\n"

ZLIB_VER="1.3"

Expand All @@ -40,12 +51,12 @@ printf "LDFLAGS: ${LDFLAGS}\n"
printf "*********************************************************\n"

cd ${DEPENDENCY_DIR}/zlib-*
./configure --prefix=${PREFIX}
make
cmake -B build -S . -G Ninja
cmake --build build -j${NPROC}
if [ -w ${PREFIX} ]; then
make install
cmake --install build --prefix ${PREFIX}
else
sudo make install
sudo cmake --install build --prefix ${PREFIX}
fi

if [ $? -ne 0 ]; then
Expand Down
13 changes: 8 additions & 5 deletions buildscripts/set_compilers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with Swiftest.
# If not, see: https://www.gnu.org/licenses.
# Parse arguments
case "$OS" in
Linux|MacOSX)
Linux|MacOSX|Intel)
;;
*)
echo "Unknown compiler type: $OS"
Expand All @@ -25,7 +24,6 @@ case "$OS" in
;;
esac


set -a
# Only replace compiler definitions if they are not already set
case $OS in
Expand All @@ -51,6 +49,12 @@ case $OS in
RANLIB=${COMPILER_PREFIX}/bin/ranlib
LDFLAGS="-Wl,-no_compact_unwind"
;;
Intel)
FC=$(command -v ifx)
CC=$(command -v icx)
CXX=$(command -v icpx)
CPP=$(command -v cpp)
;;
*)
printf "Unknown compiler type: ${OS}\n"
echo "Valid options are Intel, Linux, or MacOSX"
Expand All @@ -59,5 +63,4 @@ case $OS in
;;
esac
F77=${FC}

printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n\n"
F95=${FC}
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ CPP="/usr/bin/cpp"
AR="/usr/bin/ar"
NM="/usr/bin/nm"
RANLIB="/usr/bin/ranlib"
netCDF-Fortran_DIR="${PREFIX}/lib/cmake/netCDF"

[tool.cibuildwheel.macos]
before-all = [
"brew install coreutils",
"LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${PREFIX}/build -m ${MACOSX_DEPLOYMENT_TARGET}"
"LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${HOME}/Downloads -m ${MACOSX_DEPLOYMENT_TARGET}"
]

[tool.cibuildwheel.linux]
Expand All @@ -110,6 +111,7 @@ NETCDF_FORTRAN_HOME="/usr/local"
NETCDF_INCLUDE="/usr/local/include"
LD_LIBRARY_PATH="/usr/local/lib:/project/lib"
CPATH="/usr/local/include:/project/include"
netCDF-Fortran_DIR="${PREFIX}/lib/cmake/netCDF"

[[tool.scikit-build.generate]]
path = "version.txt"
Expand Down

0 comments on commit e7b86b4

Please sign in to comment.