-
Notifications
You must be signed in to change notification settings - Fork 294
/
build_openroad.sh
executable file
·349 lines (296 loc) · 11.3 KB
/
build_openroad.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#!/usr/bin/env bash
# This script builds the OpenROAD Flow tools locally or in a Docker image.
# Exit on first error, do not allow unbound variables
set -eu
# Make sure we are on the correct folder before beginning
DIR="$(dirname $(readlink -f $0))"
cd "$DIR"
# Set up paths to dependencies, such as cmake and boost. Safe no-op
# if tools were set up elsewhere in the path.
. dev_env.sh
# Defaults variable values
NICE=""
OPENROAD_APP_REMOTE="origin"
OPENROAD_APP_BRANCH="master"
INSTALL_PATH="$(pwd)/tools/install"
YOSYS_USER_ARGS=""
YOSYS_ARGS="CONFIG=clang"
OPENROAD_APP_USER_ARGS=""
OPENROAD_APP_ARGS=""
DOCKER_OS_NAME="ubuntu22.04"
PROC=-1
function usage() {
cat << EOF
Usage: $0 [-h|--help] [-o|--local] [-l|--latest]
[--or_branch BRANCH_NAME] [--or_repo REPO_URL] [--no_init]
[-n|--nice] [-t|--threads N]
[--yosys-args-overwrite] [--yosys-args STRING]
[--openroad-args-overwrite] [--openroad-args STRING]
[--install-path PATH] [--clean] [--clean-force]
[-c|--copy-platforms]
Options:
-h, --help Print this help message.
-o, --local Build locally instead of building a Docker image.
-l, --latest Use the head of branch --or_branch or 'master'
by default for tools/OpenROAD.
--or_branch BRANCH_NAME Use the head of branch BRANCH for tools/OpenROAD.
--or_repo REPO_URL Use a fork at REPO-URL (https/ssh) for tools/OpenROAD.
--no_init Skip initializing submodules.
-t, --threads N Use N cpus when compiling software.
-n, --nice Nice all jobs. Use all cpus unless --threads is
also given, then use N threads.
--yosys-args-overwrite Do not use default flags set by this scrip during
Yosys compilation.
--yosys-args STRING Additional compilation flags for Yosys compilation.
--openroad-args-overwrite
Do not use default flags set by this scrip during
OpenROAD app compilation.
--openroad-args STRING Additional compilation flags for OpenROAD app
compilation.
--install-path PATH Path to install tools. Default is ${INSTALL_PATH}.
--clean Call git clean interactively before compile.
Useful to remove old build files.
--clean-force Call git clean before compile. WARNING: this option
will not ask for confirmation. Useful to remove
old build files.
Options valid only for Docker builds:
-c, --copy-platforms Copy platforms to inside docker image.
--os=DOCKER_OS_NAME Choose between ubuntu22.04 (default), ubuntu20.04.
This script builds the OpenROAD tools: openroad, yosys and yosys plugins.
By default, the tools will be built from the linked submodule hashes.
EOF
}
# Parse arguments
__CMD="$0 $@"
while (( "$#" )); do
case "$1" in
-h|--help)
usage 2> /dev/null
exit
;;
-o|--local)
LOCAL_BUILD=1
;;
-l|--latest)
USE_OPENROAD_APP_LATEST=1
;;
--or_branch)
OPENROAD_APP_BRANCH="$2"
shift
;;
--or_repo)
OPENROAD_APP_GIT_URL="$2"
shift
;;
--no_init)
OPENROAD_FLOW_NO_GIT_INIT=1
;;
-t|--threads)
PROC="$2"
shift
;;
-n|--nice)
NICE="nice"
;;
-c|--copy-platforms)
DOCKER_COPY_PLATFORMS=1
;;
--yosys-args-overwrite)
YOSYS_OVERWRITE_ARGS=1
;;
--yosys-args)
YOSYS_USER_ARGS="$2"
shift
;;
--openroad-args-overwrite)
OPENROAD_APP_OVERWRITE_ARGS=1
;;
--openroad-args)
OPENROAD_APP_USER_ARGS="$2"
shift
;;
--install-path)
INSTALL_PATH="$2"
shift
;;
--clean)
CLEAN_BEFORE=1
;;
--clean-force)
CLEAN_BEFORE=1
CLEAN_FORCE=1
;;
--os=* )
DOCKER_OS_NAME="${1#*=}"
;;
-*|--*) # unsupported flags
echo "[ERROR FLW-0005] Unsupported flag $1." >&2
usage 2> /dev/null
exit 1
;;
esac
shift
done
if [[ "$PROC" == "-1" ]]; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
PROC=$(nproc --all)
elif [[ "$OSTYPE" == "darwin"* ]]; then
PROC=$(sysctl -n hw.ncpu)
else
cat << EOF
[WARNING FLW-0025] Unsupported OSTYPE: cannot determine number of host CPUs"
Defaulting to 2 threads. Use --threads N to use N threads"
EOF
PROC=2
fi
fi
echo "[INFO FLW-0028] Compiling with ${PROC} threads."
# Only add install prefix variables after parsing arguments.
YOSYS_ARGS+=" PREFIX=${INSTALL_PATH}/yosys"
OPENROAD_APP_ARGS+=" -D CMAKE_INSTALL_PREFIX=${INSTALL_PATH}/OpenROAD"
if [ -n "$CMAKE_INSTALL_RPATH" ]; then
OPENROAD_APP_ARGS+=" -D CMAKE_INSTALL_RPATH=${CMAKE_INSTALL_RPATH}"
OPENROAD_APP_ARGS+=" -D CMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE"
fi
__args_setup() {
if [ ! -z "${YOSYS_OVERWRITE_ARGS+x}" ]; then
echo "[INFO FLW-0014] Overwriting Yosys compilation flags."
YOSYS_ARGS="${YOSYS_USER_ARGS}"
else
YOSYS_ARGS+=" ${YOSYS_USER_ARGS}"
fi
if [ ! -z "${OPENROAD_APP_OVERWRITE_ARGS+x}" ]; then
echo "[INFO FLW-0015] Overwriting OpenROAD app compilation flags."
OPENROAD_APP_ARGS="${OPENROAD_APP_USER_ARGS}"
else
OPENROAD_APP_ARGS+=" ${OPENROAD_APP_USER_ARGS}"
fi
}
__docker_build()
{
echo "[INFO FLW-0020] Building docker image for OpenROAD Flow."
if [ ! -z "${DOCKER_COPY_PLATFORMS+x}" ]; then
cp .dockerignore{,.bak}
sed -i '/flow\/platforms/d' .dockerignore
fi
./etc/DockerHelper.sh create -target=dev -os="${DOCKER_OS_NAME}" -threads="${PROC}"
./etc/DockerHelper.sh create -target=builder -os="${DOCKER_OS_NAME}" -threads="${PROC}"
if [ ! -z "${DOCKER_COPY_PLATFORMS+x}" ]; then
mv .dockerignore{.bak,}
fi
}
__local_build()
{
if [[ "$OSTYPE" == "darwin"* ]]; then
export PATH="$(brew --prefix bison)/bin:$(brew --prefix flex)/bin:$(brew --prefix tcl-tk)/bin:$PATH"
export CMAKE_PREFIX_PATH=$(brew --prefix or-tools)
fi
if [[ -f "/opt/rh/rh-python38/enable" ]]; then
set +u
source /opt/rh/rh-python38/enable
set -u
fi
if [[ -f "/opt/rh/devtoolset-8/enable" ]]; then
# the scl script has unbound variables
set +u
source /opt/rh/devtoolset-8/enable
set -u
fi
YOSYS_ABC_PATH=tools/yosys/abc
if [[ -d "${YOSYS_ABC_PATH}/.git" ]]; then
# update indexes to make sure git diff-index uses correct data
git --work-tree=${YOSYS_ABC_PATH} --git-dir=${YOSYS_ABC_PATH}/.git update-index --refresh
fi
echo "[INFO FLW-0017] Compiling Yosys."
${NICE} make install -C tools/yosys -j "${PROC}" ${YOSYS_ARGS}
echo "[INFO FLW-0018] Compiling OpenROAD."
eval ${NICE} ./tools/OpenROAD/etc/Build.sh -dir="$DIR/tools/OpenROAD/build" -threads=${PROC} -cmake=\'${OPENROAD_APP_ARGS}\'
${NICE} cmake --build tools/OpenROAD/build --target install -j "${PROC}"
}
__update_openroad_app_remote()
(
cd tools/OpenROAD
remotes=$(git remote)
SAVEIFS=$IFS
IFS=$'\n'
remotes=($remotes)
IFS=$SAVEIFS
if [[ ! " ${remotes[@]} " =~ " ${OPENROAD_APP_REMOTE} " ]]; then
git remote add "${OPENROAD_APP_REMOTE}" "${OPENROAD_APP_GIT_URL}"
fi
)
__change_openroad_app_remote()
{
base_url=$(dirname "${OPENROAD_APP_GIT_URL}")
if [[ ${base_url##*/} = $base_url ]]; then
OPENROAD_APP_REMOTE=${base_url##*:}
else
OPENROAD_APP_REMOTE=${base_url##*/}
fi
__update_openroad_app_remote
}
__update_openroad_app_latest()
(
cd tools/OpenROAD
git fetch "${OPENROAD_APP_REMOTE}"
git checkout "${OPENROAD_APP_REMOTE}/${OPENROAD_APP_BRANCH}"
git pull "${OPENROAD_APP_REMOTE}" "${OPENROAD_APP_BRANCH}"
git submodule update --init --recursive
)
__common_setup()
{
# Clone repositories
if [ -z "${OPENROAD_FLOW_NO_GIT_INIT+x}" ]; then
echo "[INFO FLW-0002] Updating git submodules."
git submodule update --init --recursive
fi
if [ ! -z "${OPENROAD_APP_GIT_URL+x}" ]; then
echo -n "[INFO FLW-0003] Changing OpenROAD app remote to"
echo " ${OPENROAD_APP_GIT_URL}."
__change_openroad_app_remote
fi
if [ ! -z "${USE_OPENROAD_APP_LATEST+x}" ] || [ "${OPENROAD_APP_BRANCH}" != "master" ]; then
echo -n "[INFO FLW-0004] Updating OpenROAD app to the HEAD"
echo " of ${OPENROAD_APP_REMOTE}/${OPENROAD_APP_BRANCH}."
__update_openroad_app_latest
fi
}
__logging()
{
local log_file="build_openroad.log"
echo "[INFO FLW-0027] Saving logs to ${log_file}"
echo "[INFO FLW-0028] $__CMD"
exec > >(tee -i "${log_file}")
exec 2>&1
}
__cleanup()
{
if [ ! -z "${CLEAN_FORCE+x}" ]; then
CLEAN_CMD="-x -d --force"
else
CLEAN_CMD="-x -d --interactive"
fi
echo "[INFO FLW-0026] Cleaning up previous binaries and build files."
git clean ${CLEAN_CMD} tools
YOSYS_ABC_PATH="tools/yosys/abc"
if [[ -d "${YOSYS_ABC_PATH}" ]]; then
echo "Entering '${YOSYS_ABC_PATH}'"
git --work-tree=${YOSYS_ABC_PATH} --git-dir=${YOSYS_ABC_PATH}/.git clean ${CLEAN_CMD}
fi
git submodule foreach --recursive git clean ${CLEAN_CMD}
}
__logging
if [ ! -z "${CLEAN_BEFORE+x}" ]; then
__cleanup
fi
__args_setup
__common_setup
# Choose install method
if [ -z "${LOCAL_BUILD+x}" ] && command -v docker &> /dev/null; then
echo -n "[INFO FLW-0000] Using docker build method."
__docker_build
else
echo -n "[INFO FLW-0001] Using local build method."
echo " This will create binaries at 'tools/install' unless overwritten."
__local_build
fi