-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_pkg.sh
executable file
·194 lines (183 loc) · 6.37 KB
/
build_pkg.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env bash
# MIT License
#
# Copyright (c) 2023-2024 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
echo "ERROR: script must not be sourced";
return 1
fi
set -e
HELP_MSG="
Usage: ./$(basename $0) [OPTIONS]
Options:
--rocm-path Path to a ROCm installation, defaults to variable 'ROCM_PATH' if set or '/opt/rocm'.
--libs Libraries to build as comma separated list without whitespaces, defaults to variable 'ROCM_LLVM_PYTHON_LIBS' if set or '*'.
Add a prefix '^' to NOT build the comma-separated list of libraries that follows but all other libraries.
--no-build Do not build package 'rocm-llvm-python'.
--no-docs Do not build the docs of package 'rocm-llvm-python'.
--no-build-librocmllvm Do not build the librocmllvm shared object.
--no-api-docs Temporarily move the 'rocm-llvm-python/docs/python_api' subfolder so that sphinx does not see it.
--no-clean-docs Do not generate docs from scratch, i.e. don't run sphinx with -E switch.
--run-tests Run the tests.
--no-archive Do not put previously created packages into the archive folder.
-j,--num-jobs Number of build jobs to use. Defaults to 1.
--pre-clean Remove the virtual Python environment subfolder '_venv' --- if it exists --- before all other tasks.
--post-clean Remove the virtual Python environment subfolder '_venv' --- if it exists --- after all other tasks.
-n, --no-_venv Do not create and use a virtual Python environment.
-h, --help Show this help message.
"
NUM_JOBS=1
while [[ $# -gt 0 ]]; do
case $1 in
-b|--pre-clean)
PRE_CLEAN=1
shift
;;
-a|--post-clean)
POST_CLEAN=1
shift
;;
-n|--no-_venv)
NO_VENV=1
shift
;;
--libs)
ROCM_LLVM_PYTHON_LIBS=$2
shift; shift
;;
-h|--help)
echo "${HELP_MSG}"
exit 0
;;
--rocm-path)
ROCM_PATH=$2
shift; shift
;;
--no-build)
NO_BUILD=1
shift
;;
--no-build-librocmllvm)
NO_BUILD_LIBROCMLLVM=1
shift
;;
--run-tests)
RUN_TESTS=1
shift
;;
--no-clean-docs)
NO_CLEAN_DOCS=1
shift
;;
--no-api-docs)
NO_API_DOCS=1
shift
;;
--no-archive)
NO_ARCHIVE_OLD_PACKAGES=1
shift
;;
-j|--num-jobs)
NUM_JOBS=$2
shift; shift
;;
-*|--*)
echo "ERROR: unknown option '$1'"
exit 1
;;
*)
echo "ERROR: unknown option '$1'"
exit 1
;;
esac
done
declare -x ROCM_PATH=${ROCM_PATH:-/opt/rocm}
declare -x ROCM_LLVM_PYTHON_LIBS=${ROCM_LLVM_PYTHON_LIBS:-*}
# note: [ -z {var+x} ] evaluates to true if `var` is unset!
[ -z ${PRE_CLEAN+x} ] || rm -rf _venv
alias PYTHON="python3"
declare -x PYTHON="python3"
if [ -z ${NO_ENV+x} ]; then
[ ! -d "_venv" ] && python3 -m venv _venv
alias PYTHON="$(pwd)/_venv/bin/python3"
declare -x PYTHON="$(pwd)/_venv/bin/python3"
fi
shopt -s expand_aliases
declare -x PYVER=$(PYTHON --version | grep -o "3\.[0-9]\+\." | tr -d '.')
PKG="rocm-llvm-python"
if [ -z ${NO_BUILD+x} ]; then
if [ -z ${NO_BUILD_LIBROCMLLVM+x} ]; then
make -C src clean librocmllvm.so
mv src/librocmllvm.so ${PKG}/rocm/llvm
fi
# build rocm-llvm-python
echo "building package ${PKG}"
mkdir -p ${PKG}/dist/
mkdir -p ${PKG}/dist/archive
if [ -z ${NO_ARCHIVE_OLD_PACKAGES+x} ]; then
mv ${PKG}/dist/*.whl ${PKG}/dist/archive/ 2> /dev/null || true
mv ${PKG}/dist/*.tar.gz ${PKG}/dist/archive/ 2> /dev/null || true
fi
PYTHON -m pip install --upgrade pip
PYTHON -m pip install -r ${PKG}/requirements.txt
PYTHON _render_update_version.py
#PYTHON -m build ${PKG} -n
cd ${PKG}
find . -name "*.cpython*.so" -delete
PYTHON setup.py clean --all build_ext -j ${NUM_JOBS} bdist_wheel
cd ..
fi
# if [ -z ${NO_DOCS+x} ]; then
# echo "building docs for package rocm-llvm-python"
# # build docs
# PYTHON -m pip install --force-reinstall rocm-llvm-python/dist/hip*whl \
# rocm-llvm-python-as-cuda/dist/hip*whl
# PYTHON -m pip install -r rocm-llvm-python/docs/requirements.txt
# DOCS_DIR="rocm-llvm-python/docs"
#
# if [ ! -z ${NO_API_DOCS+x} ]; then
# mv "$DOCS_DIR/python_api" "./_python_api"
# fi
#
# if [ -z ${NO_CLEAN_DOCS+x} ]; then
# PYTHON -m sphinx -j ${NUM_JOBS} -T -E -b html -d _build/doctrees -D language=en ${DOCS_DIR} ${DOCS_DIR}/_build/html
# else
# echo "reuse saved sphinx environment"
# PYTHON -m sphinx -j ${NUM_JOBS} -T -b html -d _build/doctrees -D language=en ${DOCS_DIR} ${DOCS_DIR}/_build/html
# fi
#
# if [ ! -z ${NO_API_DOCS+x} ]; then
# mv "./_python_api" "$DOCS_DIR/python_api"
# fi
# fi
#
if [ ! -z ${RUN_TESTS+x} ]; then
PYTHON -m pip install --upgrade pip
PYTHON -m pip install --force-reinstall $(find . -path "*/dist/rocm_llvm_python*${PYVER}*whl")
PYTHON -m pip install -r examples/requirements.txt
if [ -z ${ROCM_VER+x} ]; then
echo "WARNING: environment variable 'ROCM_VER' not set. Optional tests deactivated."
else
PYTHON -m pip install -i https://test.pypi.org/simple/ hip-python~=${ROCM_VER} || true # try activate optional tests
fi
PYTHON -m pytest -v examples
fi
[ -z ${POST_CLEAN+x} ] || rm -rf _venv