diff --git a/Dockerfile b/Dockerfile index 98864db40d..d533dac4d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,9 @@ WORKDIR /OpenROAD-flow-scripts COPY --from=openroad/yosys /install ./tools/install/yosys # openroad binary -COPY --from=openroad/ubuntu22.04-builder-gcc /OpenROAD/build/src/openroad ./tools/install/OpenROAD/bin/openroad +COPY --from=openroad/ubuntu22.04-builder-gcc \ + /OpenROAD/install/bin/openroad \ + ./tools/install/OpenROAD/bin/openroad # flow files COPY ./env.sh . diff --git a/build_openroad.sh b/build_openroad.sh index 3c8ec800ad..9566ee5dcc 100755 --- a/build_openroad.sh +++ b/build_openroad.sh @@ -23,8 +23,8 @@ INSTALL_PATH="$(pwd)/tools/install" YOSYS_USER_ARGS="" YOSYS_ARGS="" -OPENROAD_APP_USER_ARGS="" -OPENROAD_APP_ARGS="" +OPENROAD_APP_USER_ARGS=() +OPENROAD_APP_ARGS=() DOCKER_OS_NAME="ubuntu22.04" PROC=-1 @@ -77,11 +77,12 @@ Options: to the Verific source folder. --openroad-args-overwrite - Do not use default flags set by this script during - OpenROAD app compilation. + Do not use the default OpenROAD Build.sh arguments. - --openroad-args STRING Additional compilation flags for OpenROAD app - compilation. + --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}. @@ -104,6 +105,49 @@ Options valid only for Docker builds: 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 @@ -163,7 +207,7 @@ while (( "$#" )); do OPENROAD_APP_OVERWRITE_ARGS=1 ;; --openroad-args) - OPENROAD_APP_USER_ARGS="$2" + __append_openroad_args "$2" shift ;; --install-path) @@ -207,11 +251,14 @@ echo "[INFO FLW-0028] Compiling with ${PROC} threads." # Only add install prefix variables after parsing arguments. YOSYS_ARGS+=" -DCMAKE_INSTALL_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 +# -lto selects Bazel --config=opt (-O3 and LTO). The default Bazel build is +# -O2 without LTO, which produces a slower binary with different QoR than the +# previous CMake RELEASE build. +OPENROAD_APP_ARGS=( + "-prefix=${INSTALL_PATH}/OpenROAD" + "-threads=${PROC}" + "-lto" +) __args_setup() { if [ ! -z "${YOSYS_OVERWRITE_ARGS+x}" ]; then @@ -222,10 +269,10 @@ __args_setup() { 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}" + echo "[INFO FLW-0015] Overwriting OpenROAD build arguments." + OPENROAD_APP_ARGS=("${OPENROAD_APP_USER_ARGS[@]}") else - OPENROAD_APP_ARGS+=" ${OPENROAD_APP_USER_ARGS}" + OPENROAD_APP_ARGS+=("${OPENROAD_APP_USER_ARGS[@]}") fi } @@ -325,26 +372,7 @@ __local_build() if [ -z "${SKIP_OPENROAD+x}" ]; then echo "[INFO FLW-0018] Compiling OpenROAD." - if [ -f "${DIR}/openroad_deps_prefixes.txt" ]; then - DEPS_PREFIX_ARG="${DIR}/openroad_deps_prefixes.txt" - elif [ -f "${DIR}/tools/OpenROAD/etc/openroad_deps_prefixes.txt" ]; then - DEPS_PREFIX_ARG="${DIR}/tools/OpenROAD/etc/openroad_deps_prefixes.txt" - elif [ -f /etc/openroad_deps_prefixes.txt ]; then - DEPS_PREFIX_ARG="/etc/openroad_deps_prefixes.txt" - else - DEPS_PREFIX_ARG="" - fi - if [[ -n "${DEPS_PREFIX_ARG}" ]]; then - echo "[INFO FLW-0029] Found OpenROAD dependencies prefixes file: '${DEPS_PREFIX_ARG}'." - DEPS_PREFIX_ARG="-deps-prefixes-file=${DEPS_PREFIX_ARG}" - fi - eval ${NICE} ./tools/OpenROAD/etc/Build.sh \ - -cmake-build \ - -dir="$DIR/tools/OpenROAD/build" \ - -threads=${PROC} \ - -cmake=\'${OPENROAD_APP_ARGS}\' \ - ${DEPS_PREFIX_ARG} - ${NICE} cmake --build tools/OpenROAD/build --target install -j "${PROC}" + ${NICE} ./tools/OpenROAD/etc/Build.sh "${OPENROAD_APP_ARGS[@]}" fi YOSYS_ABC_PATH=tools/yosys/abc diff --git a/docker/Dockerfile.builder b/docker/Dockerfile.builder index a5a18d80b6..7e8275b284 100644 --- a/docker/Dockerfile.builder +++ b/docker/Dockerfile.builder @@ -24,7 +24,6 @@ ENV PATH="/usr/local/bin/wrapped-cc:$PATH" COPY --link tools tools ARG numThreads=$(nproc) -ARG openroadVersion=NotSet ARG verificPath="" RUN <] # $0 -base # Installs OpenROAD's dependencies using - # package managers (-common must be - # executed in another command). + # package managers, including Bazel + # (bazelisk). -common must be executed + # in another command. $0 -common # Installs OpenROAD's common dependencies # (-base must be executed in another @@ -443,6 +444,12 @@ if [[ "${option}" == "none" ]]; then fi OR_INSTALLER_ARGS="${OR_INSTALLER_ARGS} -${option}" +# build_openroad.sh builds OpenROAD with Bazel, so bazelisk and its runtime +# libraries are base dependencies. They need root, and -common may run +# unprivileged, so they ride along with -base only. +if [[ "${option}" == "base" || "${option}" == "all" ]]; then + OR_INSTALLER_ARGS="${OR_INSTALLER_ARGS} -bazel" +fi platform="$(uname -s)" case "${platform}" in diff --git a/etc/DockerHelper.sh b/etc/DockerHelper.sh index 1d31edbb69..430e349bcd 100755 --- a/etc/DockerHelper.sh +++ b/etc/DockerHelper.sh @@ -28,7 +28,8 @@ usage: $0 [CMD] [OPTIONS] copy source code and build app -threads=N Max number of threads to use if compiling. Default = \$(nproc) - -tag=TAG Use as the image tag. Default is git commit sha. + -tag=TAG Use as the image tag. Default includes the + OpenROAD version and image content hash. -username=USERNAME Username to loging at the docker registry. -password=PASSWORD Password to loging at the docker registry. -ci Install CI tools in image @@ -66,9 +67,6 @@ _setup() { fromImage="${FROM_IMAGE_OVERRIDE:-"${org}/flow-${os}-dev"}:${imageTag}" context="." buildArgs+=" --build-arg numThreads=${numThreads}" - orVersion=$(git -C tools/OpenROAD describe --tags) - echo "OpenROAD version: ${orVersion}" - buildArgs+=" --build-arg openroadVersion=${orVersion}" ;; "dev" ) fromImage="${FROM_IMAGE_OVERRIDE:-$osBaseImage}" diff --git a/etc/DockerTag.sh b/etc/DockerTag.sh index 3234061637..70e87e1e3d 100755 --- a/etc/DockerTag.sh +++ b/etc/DockerTag.sh @@ -12,7 +12,9 @@ if [[ "$@" == "-dev" ]]; then "./etc/requirements-pip_lock.txt" "./tools/OpenROAD/etc/DependencyInstaller.sh" ) - cat "${file_list[@]}" | sha256sum | awk '{print substr($1, 1, 6)}' + or_version=$(git -C tools/OpenROAD describe --tags --always) + image_hash=$(cat "${file_list[@]}" | sha256sum | awk '{print substr($1, 1, 6)}') + echo "${or_version}-${image_hash}" elif [[ "$@" == "-master" ]]; then git fetch --tags >&2 git -C tools/OpenROAD fetch --tags >&2