Skip to content

Commit b680150

Browse files
committed
Add mt_build.sh and update CUB dependency
1 parent 037a041 commit b680150

2 files changed

Lines changed: 96 additions & 1 deletion

File tree

dependencies/cub

Submodule cub updated from 29f42ba to 4aa85ca

mt_build.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
# Copyright (c) 2023-2024 Moore Threads Technology Co., Ltd("Moore Threads"). All rights reserved.
3+
# Terms of the MIT License
4+
5+
set -euo pipefail
6+
7+
SCRIPT_DIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"
8+
BUILD_DIR="${SCRIPT_DIR}/build"
9+
OP_TYPE="install"
10+
INSTALL_PREFIX="/usr/local/musa"
11+
12+
usage() {
13+
cat <<EOF_USAGE
14+
musa toolkits install script
15+
Usage:
16+
$0 <options>
17+
[-i | --install]
18+
[-u | --uninstall]
19+
[-d | --prefix=<install_prefix>]
20+
[-h | --help]
21+
EOF_USAGE
22+
}
23+
24+
die() {
25+
echo "$*" >&2
26+
exit 2
27+
}
28+
29+
needs_arg() {
30+
if [ -z "${OPTARG:-}" ]; then
31+
usage
32+
die "No arg for --$OPT option"
33+
fi
34+
}
35+
36+
run_install() {
37+
mkdir -p "${BUILD_DIR}"
38+
pushd "${BUILD_DIR}" >/dev/null
39+
cmake \
40+
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
41+
-DTHRUST_ENABLE_HEADER_TESTING=OFF \
42+
-DTHRUST_ENABLE_TESTING=OFF \
43+
-DTHRUST_ENABLE_EXAMPLES=OFF \
44+
-DTHRUST_ENABLE_BENCHMARKS=OFF \
45+
-DTHRUST_INCLUDE_CUB_CMAKE=OFF \
46+
-DTHRUST_INSTALL_CUB_HEADERS=OFF \
47+
.. 2>&1 | tee cmake.log
48+
cmake --build . 2>&1 | tee build.log
49+
if [ ! -w "${INSTALL_PREFIX}" ]; then
50+
sudo cmake --build . --target install 2>&1 | tee install.log
51+
else
52+
cmake --build . --target install 2>&1 | tee install.log
53+
fi
54+
popd >/dev/null
55+
}
56+
57+
run_uninstall() {
58+
if [ "$UID" -ne "0" ]; then
59+
sudo rm -vrf "${INSTALL_PREFIX}/include/thrust"
60+
sudo rm -vrf "${INSTALL_PREFIX}/lib/cmake/thrust"
61+
sudo rm -vrf "${INSTALL_PREFIX}/lib64/cmake/thrust"
62+
sudo rm -vf "${INSTALL_PREFIX}/bin/Thrust_version"
63+
else
64+
rm -vrf "${INSTALL_PREFIX}/include/thrust"
65+
rm -vrf "${INSTALL_PREFIX}/lib/cmake/thrust"
66+
rm -vrf "${INSTALL_PREFIX}/lib64/cmake/thrust"
67+
rm -vf "${INSTALL_PREFIX}/bin/Thrust_version"
68+
fi
69+
}
70+
71+
while getopts d:-:iuh OPT; do
72+
if [ "$OPT" = "-" ]; then
73+
OPT="${OPTARG%%=*}"
74+
OPTARG="${OPTARG#$OPT}"
75+
OPTARG="${OPTARG#=}"
76+
fi
77+
case "$OPT" in
78+
i | install ) OP_TYPE="install" ;;
79+
u | uninstall ) OP_TYPE="uninstall" ;;
80+
d | prefix ) needs_arg; INSTALL_PREFIX="$OPTARG" ;;
81+
h | help ) usage; exit 0 ;;
82+
??* ) die "Illegal option --$OPT" ;;
83+
? ) exit 2 ;;
84+
esac
85+
done
86+
87+
if [ "${OP_TYPE}" = "install" ]; then
88+
echo "install ..."
89+
run_install
90+
fi
91+
92+
if [ "${OP_TYPE}" = "uninstall" ]; then
93+
echo "uninstall ..."
94+
run_uninstall
95+
fi

0 commit comments

Comments
 (0)