File size: 19,264 Bytes
d664931 | 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 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | #!/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=""
OPENROAD_APP_USER_ARGS=()
OPENROAD_APP_ARGS=()
DOCKER_OS_NAME="ubuntu26.04"
PROC=-1
WITH_VERIFIC=0
VERIFIC_SRC=""
VERIFIC_COMPONENTS='database util containers pct hier_tree verilog'
VERIFIC_ARGS=" -DYOSYS_VERIFIC_DIR=\"${DIR}/tools/yosys/verific\""
function usage() {
cat << EOF
Usage: $0 [-h|--help] [-o|--local] [-l|--latest]
[--or_branch BRANCH_NAME] [--or_repo REPO_URL] [--no_init]
[-s|--skip_openroad] [--openroad_only]
[-n|--nice] [-t|--threads N]
[--yosys-args-overwrite] [--yosys-args STRING]
[--with-verific PATH]
[--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.
-s, --skip_openroad Skip building and all git operations on OpenROAD.
--openroad_only Build only OpenROAD; skip Yosys, Verific and
kepler-formal. Requires --local.
--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 script during
Yosys compilation.
--yosys-args STRING Additional compilation flags for Yosys compilation.
--with-verific PATH Compile Yosys with Verific support. PATH is the path
to the Verific source folder.
--openroad-args-overwrite
Do not use the default OpenROAD Build.sh arguments.
--openroad-args STRING Additional arguments for OpenROAD Build.sh.
For example: '-no-gui'. Quotes group one argument
that holds spaces. All other characters, a
backslash included, are literal.
--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 Use ubuntu26.04 (default) or ubuntu24.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
}
# Split a shell-like string into words and add them to
# OPENROAD_APP_USER_ARGS. A single or double quote groups a word. Every other
# character, a backslash included, is literal, and there is no escape
# character. A quoted word therefore cannot hold its own quote character.
# Nothing is expanded, so text such as $(...) stays literal.
__append_openroad_args()
{
local text="$1"
local word="" quote="" char="" have_word=0 index
for (( index = 0; index < ${#text}; index++ )); do
char="${text:index:1}"
if [ -n "${quote}" ]; then
if [ "${char}" = "${quote}" ]; then
quote=""
else
word+="${char}"
fi
elif [ "${char}" = "'" ] || [ "${char}" = '"' ]; then
quote="${char}"
have_word=1
elif [[ "${char}" =~ [[:space:]] ]]; then
if [ "${have_word}" -eq 1 ]; then
OPENROAD_APP_USER_ARGS+=("${word}")
word=""
have_word=0
fi
else
word+="${char}"
have_word=1
fi
done
if [ -n "${quote}" ]; then
echo "[ERROR FLW-0006] Unbalanced ${quote} quote in OpenROAD build arguments: ${text}" >&2
exit 1
fi
if [ "${have_word}" -eq 1 ]; then
OPENROAD_APP_USER_ARGS+=("${word}")
fi
}
# 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
;;
-s|--skip_openroad)
SKIP_OPENROAD=1
;;
--openroad_only)
OPENROAD_ONLY=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
;;
--with-verific)
WITH_VERIFIC=1
VERIFIC_SRC=${2}
if [ ! -d "${VERIFIC_SRC}" ]; then
echo "[ERROR] Verific path '${VERIFIC_SRC}' does not exist." >&2
exit 1
fi
YOSYS_USER_ARGS+="${VERIFIC_ARGS}"
shift
;;
--openroad-args-overwrite)
OPENROAD_APP_OVERWRITE_ARGS=1
;;
--openroad-args)
__append_openroad_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 [ ! -z "${OPENROAD_ONLY+x}" ]; then
if [ -z "${LOCAL_BUILD+x}" ]; then
echo "[ERROR FLW-0033] --openroad_only requires --local." >&2
exit 1
fi
if [ ! -z "${SKIP_OPENROAD+x}" ]; then
echo "[ERROR FLW-0033] --openroad_only and --skip_openroad are mutually exclusive." >&2
exit 1
fi
fi
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+=" -DCMAKE_INSTALL_PREFIX=\"${INSTALL_PATH}/yosys\""
# Build.sh always builds with Bazel --config=release, which includes
# --config=opt (-O3 and ThinLTO).
OPENROAD_APP_ARGS=(
"-prefix=${INSTALL_PATH}/OpenROAD"
"-threads=${PROC}"
)
__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 build arguments."
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
local options=()
if [ "${WITH_VERIFIC}" -eq 1 ]; then
cp -r "${VERIFIC_SRC}" tools/verific
options=("-buildArgs=--build-arg verificPath=tools/verific")
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}" "${options[@]}"
rm -rf tools/verific
if [ ! -z "${DOCKER_COPY_PLATFORMS+x}" ]; then
mv .dockerignore{.bak,}
fi
}
__local_build()
{
if [[ "$OSTYPE" == "darwin"* ]]; then
_bison=$(brew --prefix bison 2>/dev/null || true)
_flex=$(brew --prefix flex 2>/dev/null || true)
_ortools=$(brew --prefix or-tools 2>/dev/null || true)
if [[ -z "$_bison" || ! -d "$_bison/bin" ]]; then
echo "[ERROR] bison not found or broken. Run: brew install bison" >&2
exit 1
fi
if [[ -z "$_flex" || ! -d "$_flex/bin" ]]; then
echo "[ERROR] flex not found or broken. Run: brew install flex" >&2
exit 1
fi
if [[ -z "$_ortools" || ! -d "$_ortools/lib" || ! -d "$_ortools/include" ]]; then
echo "[ERROR] or-tools not found or broken. Run: brew install or-tools" >&2
exit 1
fi
export PATH="$_bison/bin:$_flex/bin:$PATH"
export CMAKE_PREFIX_PATH="${_ortools}"
_qt5=$(brew --prefix qt@5 2>/dev/null || true)
if [[ -z "$_qt5" || ! -d "$_qt5/lib" ]]; then
echo "[ERROR] qt@5 not found or broken. Run: brew install qt@5" >&2
exit 1
fi
cmakeOptions+=" -DQt5_DIR=$_qt5/lib/cmake/Qt5"
_tcl8=$(brew --prefix tcl-tk@8 2>/dev/null || true)
if [[ -z "$_tcl8" || ! -d "$_tcl8/lib" || ! -d "$_tcl8/include" ]]; then
echo "[ERROR] tcl-tk@8 not found or broken. Run: brew install tcl-tk@8" >&2
exit 1
fi
cmakeOptions+=" -DTCL_LIBRARY=$_tcl8/lib/libtcl8.6.dylib"
cmakeOptions+=" -DTCL_INCLUDE_PATH=$_tcl8/include"
cmakeOptions+=" -DFLEX_INCLUDE_DIR=$_flex/include"
cmakeOptions+=" -DCMAKE_CXX_FLAGS=-DBOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED"
_icu="$(brew --prefix icu4c 2>/dev/null || true)"
if [[ -z "$_icu" || ! -d "$_icu/lib" ]]; then
echo "[ERROR] icu4c not found or broken. Run: brew install icu4c" >&2
exit 1
fi
export LDFLAGS="-L$_icu/lib"
export CPPFLAGS="-I$_icu/include"
export PKG_CONFIG_PATH="$_icu/lib/pkgconfig"
_extra_lib_paths=("/opt/homebrew/lib")
_joined_paths="$(IFS=:; echo "${_extra_lib_paths[*]}")"
export LIBRARY_PATH="${_joined_paths}${LIBRARY_PATH:+:$LIBRARY_PATH}"
echo "[INFO] General LIBRARY_PATH=$LIBRARY_PATH"
fi
# EL8: the default GCC 8 is too old for Yosys, which needs C++20.
# It stays active for kepler-formal, which uses the host compiler
# where no downloaded clang is registered (aarch64).
if [[ -f "/opt/rh/gcc-toolset-13/enable" ]]; then
set +u
source /opt/rh/gcc-toolset-13/enable
set -u
fi
if [ -z "${SKIP_OPENROAD+x}" ]; then
echo "[INFO FLW-0018] Compiling OpenROAD."
${NICE} ./tools/OpenROAD/etc/Build.sh "${OPENROAD_APP_ARGS[@]}"
fi
if [ ! -z "${OPENROAD_ONLY+x}" ]; then
return
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
if [ ${WITH_VERIFIC} -eq 1 ]; then
echo "[INFO FLW-0031] Compiling Verific components."
cp -r "${VERIFIC_SRC}" tools/yosys/verific
for c in ${VERIFIC_COMPONENTS}; do
make -j -C "tools/yosys/verific/${c}" clean
make -j -C "tools/yosys/verific/${c}"
done
fi
echo "[INFO FLW-0017] Compiling Yosys."
eval ${NICE} cmake -B tools/yosys/build tools/yosys \
-DCMAKE_BUILD_TYPE=Release \
-DYOSYS_SKIP_ABC_SUBMODULE_CHECK=ON \
${YOSYS_ARGS}
${NICE} cmake --build tools/yosys/build --target install -j "${PROC}"
echo "[INFO FLW-0031] Installing kepler-formal"
# etc/kepler-formal pins kepler-formal; Bazel downloads it, its
# dependencies and the compiler. See etc/kepler-formal/README.md.
if ! command -v bazelisk &> /dev/null; then
echo "[ERROR FLW-0034] kepler-formal needs bazelisk; run etc/DependencyInstaller.sh -common." >&2
exit 1
fi
KEPLER_PREFIX="${INSTALL_PATH}/kepler-formal"
if [[ "${KEPLER_PREFIX}" != /* ]]; then
KEPLER_PREFIX="$(pwd)/${KEPLER_PREFIX}"
fi
(cd "${DIR}/etc/kepler-formal" && \
${NICE} bazelisk run --jobs="${PROC}" //:install -- "${KEPLER_PREFIX}" && \
./install_licenses.sh "${KEPLER_PREFIX}")
if [ ${WITH_VERIFIC} -eq 1 ]; then
echo "[INFO FLW-0032] Cleaning up Verific components."
rm -rf tools/yosys/verific
fi
}
__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 "${SKIP_OPENROAD+x}" ] && ( [ ! -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 "[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
|