#!/bin/bash
set -e
MFUSION_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/" && pwd )"
BUILD_DIR="${MFUSION_DIR}/build"
THREAD_NUM=$(nproc)
BUILD_TYPE="Release"
BUILD_TESTS="OFF"
ENABLE_ASAN="OFF"
usage()
{
echo "Usage:"
echo "bash build.sh [-a on|off] [-d] [-h] [-i] [-j[n]] [-s path] [-t]"
echo ""
echo "Options:"
echo " -a on|off Enable AddressSanitizer (implies Debug mode), default off"
echo " -d Debug mode, default release mode"
echo " -h Print usage"
echo " -i Incremental build"
echo " -j[n] Set the threads when building (Default: the number of cpu)"
echo " -s Specifies the CMAKE_PREFIX_PATH for dependencies"
echo " -t Enable unit test (Default: disable)"
}
while getopts 'a:dhij:s:t' opt
do
case "${opt}" in
a)
case "${OPTARG}" in
on)
ENABLE_ASAN="ON"
BUILD_TYPE=Debug
;;
off)
ENABLE_ASAN="OFF"
;;
*)
echo "Invalid value for -a: ${OPTARG}, expected 'on' or 'off'"
usage
exit 1
;;
esac
;;
d)
BUILD_TYPE=Debug
;;
h)
usage
exit 0
;;
i)
INC_BUILD=1
;;
j)
THREAD_NUM=${OPTARG}
;;
s)
PREFIX_PATH=${OPTARG}
;;
t)
BUILD_TESTS="ON"
;;
*)
echo "Unknown option ${opt}!"
usage
exit 1
esac
done
python -c "import build" 2>/dev/null || {
echo "Installing Python build package..."
pip install build
}
python -c "
import packaging
from packaging.version import parse
assert parse(packaging.__version__) >= parse('24.2'), f'packaging {packaging.__version__} < 24.2'
" 2>/dev/null || pip install "packaging>=24.2"
if [[ "X$INC_BUILD" != "X1" ]]; then
if [[ -d "${BUILD_DIR}" ]]; then
echo "Removing build directory for clean build"
rm -rf "${BUILD_DIR}"
fi
fi
mkdir -pv "${BUILD_DIR}"
echo "---------------- MFusion: build start ----------------"
export BUILD_JOBS=${THREAD_NUM}
export BUILD_TYPE=${BUILD_TYPE}
export BUILD_TESTS=${BUILD_TESTS}
export ENABLE_ASAN=${ENABLE_ASAN}
if [[ -n "${PREFIX_PATH}" ]]; then
export CMAKE_PREFIX_PATH="${PREFIX_PATH}"
fi
if [[ "X$INC_BUILD" = "X1" ]]; then
export INC_BUILD=1
else
unset INC_BUILD
fi
set -x
python -m build --wheel --no-isolation
set +x
mkdir -p output
cp dist/*.whl output/
rm -rf dist
echo "---------------- MFusion: build end ----------------"