Skip to content

Commit 3000fc7

Browse files
authored
Merge pull request #4527 from vvbandeira/openroad-bazel
build: install OpenROAD with Bazel
2 parents bc5af8c + f0a810d commit 3000fc7

6 files changed

Lines changed: 80 additions & 45 deletions

File tree

‎Dockerfile‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ WORKDIR /OpenROAD-flow-scripts
77
COPY --from=openroad/yosys /install ./tools/install/yosys
88

99
# openroad binary
10-
COPY --from=openroad/ubuntu22.04-builder-gcc /OpenROAD/build/src/openroad ./tools/install/OpenROAD/bin/openroad
10+
COPY --from=openroad/ubuntu22.04-builder-gcc \
11+
/OpenROAD/install/bin/openroad \
12+
./tools/install/OpenROAD/bin/openroad
1113

1214
# flow files
1315
COPY ./env.sh .

‎build_openroad.sh‎

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ INSTALL_PATH="$(pwd)/tools/install"
2323
YOSYS_USER_ARGS=""
2424
YOSYS_ARGS=""
2525

26-
OPENROAD_APP_USER_ARGS=""
27-
OPENROAD_APP_ARGS=""
26+
OPENROAD_APP_USER_ARGS=()
27+
OPENROAD_APP_ARGS=()
2828

2929
DOCKER_OS_NAME="ubuntu22.04"
3030
PROC=-1
@@ -77,11 +77,12 @@ Options:
7777
to the Verific source folder.
7878
7979
--openroad-args-overwrite
80-
Do not use default flags set by this script during
81-
OpenROAD app compilation.
80+
Do not use the default OpenROAD Build.sh arguments.
8281
83-
--openroad-args STRING Additional compilation flags for OpenROAD app
84-
compilation.
82+
--openroad-args STRING Additional arguments for OpenROAD Build.sh.
83+
For example: '-no-gui'. Quotes group one argument
84+
that holds spaces. All other characters, a
85+
backslash included, are literal.
8586
8687
--install-path PATH Path to install tools. Default is ${INSTALL_PATH}.
8788
@@ -104,6 +105,49 @@ Options valid only for Docker builds:
104105
EOF
105106
}
106107

108+
# Split a shell-like string into words and add them to
109+
# OPENROAD_APP_USER_ARGS. A single or double quote groups a word. Every other
110+
# character, a backslash included, is literal, and there is no escape
111+
# character. A quoted word therefore cannot hold its own quote character.
112+
# Nothing is expanded, so text such as $(...) stays literal.
113+
__append_openroad_args()
114+
{
115+
local text="$1"
116+
local word="" quote="" char="" have_word=0 index
117+
118+
for (( index = 0; index < ${#text}; index++ )); do
119+
char="${text:index:1}"
120+
if [ -n "${quote}" ]; then
121+
if [ "${char}" = "${quote}" ]; then
122+
quote=""
123+
else
124+
word+="${char}"
125+
fi
126+
elif [ "${char}" = "'" ] || [ "${char}" = '"' ]; then
127+
quote="${char}"
128+
have_word=1
129+
elif [[ "${char}" =~ [[:space:]] ]]; then
130+
if [ "${have_word}" -eq 1 ]; then
131+
OPENROAD_APP_USER_ARGS+=("${word}")
132+
word=""
133+
have_word=0
134+
fi
135+
else
136+
word+="${char}"
137+
have_word=1
138+
fi
139+
done
140+
141+
if [ -n "${quote}" ]; then
142+
echo "[ERROR FLW-0006] Unbalanced ${quote} quote in OpenROAD build arguments: ${text}" >&2
143+
exit 1
144+
fi
145+
146+
if [ "${have_word}" -eq 1 ]; then
147+
OPENROAD_APP_USER_ARGS+=("${word}")
148+
fi
149+
}
150+
107151
# Parse arguments
108152
__CMD="$0 $@"
109153
while (( "$#" )); do
@@ -163,7 +207,7 @@ while (( "$#" )); do
163207
OPENROAD_APP_OVERWRITE_ARGS=1
164208
;;
165209
--openroad-args)
166-
OPENROAD_APP_USER_ARGS="$2"
210+
__append_openroad_args "$2"
167211
shift
168212
;;
169213
--install-path)
@@ -207,11 +251,14 @@ echo "[INFO FLW-0028] Compiling with ${PROC} threads."
207251

208252
# Only add install prefix variables after parsing arguments.
209253
YOSYS_ARGS+=" -DCMAKE_INSTALL_PREFIX=\"${INSTALL_PATH}/yosys\""
210-
OPENROAD_APP_ARGS+=" -D CMAKE_INSTALL_PREFIX=${INSTALL_PATH}/OpenROAD"
211-
if [ -n "$CMAKE_INSTALL_RPATH" ]; then
212-
OPENROAD_APP_ARGS+=" -D CMAKE_INSTALL_RPATH=${CMAKE_INSTALL_RPATH}"
213-
OPENROAD_APP_ARGS+=" -D CMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE"
214-
fi
254+
# -lto selects Bazel --config=opt (-O3 and LTO). The default Bazel build is
255+
# -O2 without LTO, which produces a slower binary with different QoR than the
256+
# previous CMake RELEASE build.
257+
OPENROAD_APP_ARGS=(
258+
"-prefix=${INSTALL_PATH}/OpenROAD"
259+
"-threads=${PROC}"
260+
"-lto"
261+
)
215262

216263
__args_setup() {
217264
if [ ! -z "${YOSYS_OVERWRITE_ARGS+x}" ]; then
@@ -222,10 +269,10 @@ __args_setup() {
222269
fi
223270

224271
if [ ! -z "${OPENROAD_APP_OVERWRITE_ARGS+x}" ]; then
225-
echo "[INFO FLW-0015] Overwriting OpenROAD app compilation flags."
226-
OPENROAD_APP_ARGS="${OPENROAD_APP_USER_ARGS}"
272+
echo "[INFO FLW-0015] Overwriting OpenROAD build arguments."
273+
OPENROAD_APP_ARGS=("${OPENROAD_APP_USER_ARGS[@]}")
227274
else
228-
OPENROAD_APP_ARGS+=" ${OPENROAD_APP_USER_ARGS}"
275+
OPENROAD_APP_ARGS+=("${OPENROAD_APP_USER_ARGS[@]}")
229276
fi
230277
}
231278

@@ -325,26 +372,7 @@ __local_build()
325372

326373
if [ -z "${SKIP_OPENROAD+x}" ]; then
327374
echo "[INFO FLW-0018] Compiling OpenROAD."
328-
if [ -f "${DIR}/openroad_deps_prefixes.txt" ]; then
329-
DEPS_PREFIX_ARG="${DIR}/openroad_deps_prefixes.txt"
330-
elif [ -f "${DIR}/tools/OpenROAD/etc/openroad_deps_prefixes.txt" ]; then
331-
DEPS_PREFIX_ARG="${DIR}/tools/OpenROAD/etc/openroad_deps_prefixes.txt"
332-
elif [ -f /etc/openroad_deps_prefixes.txt ]; then
333-
DEPS_PREFIX_ARG="/etc/openroad_deps_prefixes.txt"
334-
else
335-
DEPS_PREFIX_ARG=""
336-
fi
337-
if [[ -n "${DEPS_PREFIX_ARG}" ]]; then
338-
echo "[INFO FLW-0029] Found OpenROAD dependencies prefixes file: '${DEPS_PREFIX_ARG}'."
339-
DEPS_PREFIX_ARG="-deps-prefixes-file=${DEPS_PREFIX_ARG}"
340-
fi
341-
eval ${NICE} ./tools/OpenROAD/etc/Build.sh \
342-
-cmake-build \
343-
-dir="$DIR/tools/OpenROAD/build" \
344-
-threads=${PROC} \
345-
-cmake=\'${OPENROAD_APP_ARGS}\' \
346-
${DEPS_PREFIX_ARG}
347-
${NICE} cmake --build tools/OpenROAD/build --target install -j "${PROC}"
375+
${NICE} ./tools/OpenROAD/etc/Build.sh "${OPENROAD_APP_ARGS[@]}"
348376
fi
349377

350378
YOSYS_ABC_PATH=tools/yosys/abc

‎docker/Dockerfile.builder‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ ENV PATH="/usr/local/bin/wrapped-cc:$PATH"
2424

2525
COPY --link tools tools
2626
ARG numThreads=$(nproc)
27-
ARG openroadVersion=NotSet
2827
ARG verificPath=""
2928

3029
RUN <<EOF
@@ -38,7 +37,6 @@ fi
3837
./build_openroad.sh --no_init \
3938
--local \
4039
--threads ${numThreads} \
41-
--openroad-args -DOPENROAD_VERSION=${openroadVersion} \
4240
${verificArgs}
4341
if [ -n "${verificPath}" ]; then
4442
rm -rf "${verificPath}"

‎etc/DependencyInstaller.sh‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,9 @@ Usage: $0 [-all|-base|-common] [-<ARGS>]
339339
#
340340
$0 -base
341341
# Installs OpenROAD's dependencies using
342-
# package managers (-common must be
343-
# executed in another command).
342+
# package managers, including Bazel
343+
# (bazelisk). -common must be executed
344+
# in another command.
344345
$0 -common
345346
# Installs OpenROAD's common dependencies
346347
# (-base must be executed in another
@@ -443,6 +444,12 @@ if [[ "${option}" == "none" ]]; then
443444
fi
444445

445446
OR_INSTALLER_ARGS="${OR_INSTALLER_ARGS} -${option}"
447+
# build_openroad.sh builds OpenROAD with Bazel, so bazelisk and its runtime
448+
# libraries are base dependencies. They need root, and -common may run
449+
# unprivileged, so they ride along with -base only.
450+
if [[ "${option}" == "base" || "${option}" == "all" ]]; then
451+
OR_INSTALLER_ARGS="${OR_INSTALLER_ARGS} -bazel"
452+
fi
446453

447454
platform="$(uname -s)"
448455
case "${platform}" in

‎etc/DockerHelper.sh‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ usage: $0 [CMD] [OPTIONS]
2828
copy source code and build app
2929
-threads=N Max number of threads to use if compiling.
3030
Default = \$(nproc)
31-
-tag=TAG Use as the image tag. Default is git commit sha.
31+
-tag=TAG Use as the image tag. Default includes the
32+
OpenROAD version and image content hash.
3233
-username=USERNAME Username to loging at the docker registry.
3334
-password=PASSWORD Password to loging at the docker registry.
3435
-ci Install CI tools in image
@@ -66,9 +67,6 @@ _setup() {
6667
fromImage="${FROM_IMAGE_OVERRIDE:-"${org}/flow-${os}-dev"}:${imageTag}"
6768
context="."
6869
buildArgs+=" --build-arg numThreads=${numThreads}"
69-
orVersion=$(git -C tools/OpenROAD describe --tags)
70-
echo "OpenROAD version: ${orVersion}"
71-
buildArgs+=" --build-arg openroadVersion=${orVersion}"
7270
;;
7371
"dev" )
7472
fromImage="${FROM_IMAGE_OVERRIDE:-$osBaseImage}"

‎etc/DockerTag.sh‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ if [[ "$@" == "-dev" ]]; then
1212
"./etc/requirements-pip_lock.txt"
1313
"./tools/OpenROAD/etc/DependencyInstaller.sh"
1414
)
15-
cat "${file_list[@]}" | sha256sum | awk '{print substr($1, 1, 6)}'
15+
or_version=$(git -C tools/OpenROAD describe --tags --always)
16+
image_hash=$(cat "${file_list[@]}" | sha256sum | awk '{print substr($1, 1, 6)}')
17+
echo "${or_version}-${image_hash}"
1618
elif [[ "$@" == "-master" ]]; then
1719
git fetch --tags >&2
1820
git -C tools/OpenROAD fetch --tags >&2

0 commit comments

Comments
 (0)