From fce218775c325564d7459104000527e4038f9bdc Mon Sep 17 00:00:00 2001 From: alokkumardalei-wq Date: Sun, 12 Apr 2026 10:44:35 +0530 Subject: [PATCH 1/3] etc: add -bazel and -bazel-dev options to DependencyInstaller and Build scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #9594. Adds Bazel setup options to make it easier for developers to get started with the Bazel build. DependencyInstaller.sh: -bazel — installs bazelisk + xcb libs for GUI support -bazel-dev — installs buildifier for formatting BUILD/.bzl files (implies -bazel) Both flags work standalone or combined with -all/-base/-common. Supports Linux (apt/yum) and macOS (Homebrew). Downloads are verified with _verify_checksum. Build.sh: -bazel — builds with Bazel instead of CMake, using bazelisk if available. Honors -no-gui (--//:platform=cli) and uses --config=opt with -j for thread count. Also refactors cmakeOptions from a string to a Bash array to safely handle quoted strings without eval, as suggested in review. Signed-off-by: alokkumardalei-wq --- etc/Build.sh | 65 ++++++++++++++++----- etc/DependencyInstaller.sh | 116 ++++++++++++++++++++++++++++++++++++- 2 files changed, 165 insertions(+), 16 deletions(-) diff --git a/etc/Build.sh b/etc/Build.sh index 356a5281807..b1a6a753b1a 100755 --- a/etc/Build.sh +++ b/etc/Build.sh @@ -18,10 +18,12 @@ WARNING: Unsupported OSTYPE: cannot determine number of host CPUs" EOF numThreads=2 fi -cmakeOptions="" +cmakeOptions=() cleanBefore=no depsPrefixesFile="" compiler=gcc +useBazel=no +noGui=no _help() { cat <&2 @@ -147,7 +159,11 @@ if [[ -z "$depsPrefixesFile" ]]; then fi fi if [[ -f "$depsPrefixesFile" ]]; then - cmakeOptions+=" $(cat "$depsPrefixesFile")" + while IFS= read -r arg; do + if [[ -n "$arg" ]]; then + cmakeOptions+=("$arg") + fi + done < <(xargs printf '%s\n' < "$depsPrefixesFile") echo "[INFO] Using additional CMake parameters from $depsPrefixesFile" else echo "[INFO] Auto-generated prefix file does not exist - CMake will choose the dependencies automatically" @@ -252,5 +268,26 @@ echo -e "${GREEN}All pre-compilation checks passed! Proceeding...${NC}\n" # ============================================================================== echo "[INFO] Using ${numThreads} threads." -eval cmake "${cmakeOptions}" -B "${buildDir}" . -eval time cmake --build "${buildDir}" -j "${numThreads}" +if [[ "$useBazel" == "yes" ]]; then + echo "[INFO] Building with Bazel." + bazel_cmd="bazel" + if command -v bazelisk &> /dev/null; then + bazel_cmd="bazelisk" + fi + bazelArgs=("--config=opt" "--jobs=${numThreads}") + if [[ "$noGui" == "yes" ]]; then + bazelArgs+=("--//:platform=cli") + else + bazelArgs+=("--//:platform=gui") + fi + "${bazel_cmd}" build "${bazelArgs[@]}" //:openroad + exit 0 +fi +if [[ "$isNinja" == "yes" ]]; then + cmake "${cmakeOptions[@]}" -B "${buildDir}" . + cd "${buildDir}" + CLICOLOR_FORCE=1 ninja build_and_test + exit 0 +fi +cmake "${cmakeOptions[@]}" -B "${buildDir}" . +time cmake --build "${buildDir}" -j "${numThreads}" diff --git a/etc/DependencyInstaller.sh b/etc/DependencyInstaller.sh index c116af1a153..f6cdf8cf84f 100755 --- a/etc/DependencyInstaller.sh +++ b/etc/DependencyInstaller.sh @@ -16,7 +16,7 @@ set -euo pipefail PREFIX="" CI="no" SAVE_DEPS_PREFIXES="" -NUM_THREADS=$(nproc) +NUM_THREADS=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2) SKIP_SYSTEM_OR_TOOLS="false" BASE_DIR=$(mktemp -d /tmp/DependencyInstaller-XXXXXX) CMAKE_PACKAGE_ROOT_ARGS="" @@ -71,6 +71,14 @@ FLEX_CHECKSUM="2882e3179748cc9f9c23ec593d6adc8d" OR_TOOLS_VERSION_BIG="9.14" OR_TOOLS_VERSION_SMALL="${OR_TOOLS_VERSION_BIG}.6206" EQUIVALENCE_DEPS="no" +INSTALL_BAZEL="no" +INSTALL_BAZEL_DEV="no" +BAZELISK_VERSION="1.28.1" +BAZELISK_CHECKSUM_AMD64="2dc74b7ad6bdd6b6b08f6802d14fc1fd" +BAZELISK_CHECKSUM_ARM64="94415d08ed2f86a49375f25a7f2f9cca" +BUILDIFIER_VERSION="8.5.1" +BUILDIFIER_CHECKSUM_AMD64="72f5953ab6dcc309a4447c2e2d79c680" +BUILDIFIER_CHECKSUM_ARM64="06f52f0872bde33685c6260110261cf7" # ... configuration variables will be added here ... # ============================================================================== @@ -779,6 +787,91 @@ _install_or_tools() { # Each dependency will have its own dedicated function for installation and # version management. This modular approach makes the script easier to # maintain and extend. +# ------------------------------------------------------------------------------ +# Bazel +# ------------------------------------------------------------------------------ +_install_bazel() { + local bazel_prefix=${PREFIX:-"/usr/local"} + log "Checking Bazel (via bazelisk)" + if _command_exists "bazelisk"; then + log "bazelisk already installed, skipping." + INSTALL_SUMMARY+=("Bazel: system=found, required=any, status=skipped") + return + fi + if [[ "$OSTYPE" == "darwin"* ]]; then + _execute "Installing bazelisk via Homebrew..." brew install bazelisk + else + local arch + arch=$(uname -m) + local bazelisk_arch="amd64" + if [[ "${arch}" == "aarch64" ]]; then + bazelisk_arch="arm64" + fi + local bazelisk_checksum="${BAZELISK_CHECKSUM_AMD64}" + if [[ "${bazelisk_arch}" == "arm64" ]]; then + bazelisk_checksum="${BAZELISK_CHECKSUM_ARM64}" + fi + ( + cd "${BASE_DIR}" + _execute "Downloading bazelisk v${BAZELISK_VERSION}..." curl -Lo bazelisk \ + "https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK_VERSION}/bazelisk-linux-${bazelisk_arch}" + _verify_checksum "${bazelisk_checksum}" "bazelisk" || error "Bazelisk checksum failed." + chmod +x bazelisk + _execute "Installing bazelisk..." mv bazelisk "${bazel_prefix}/bin/bazelisk" + ) + # Install xcb libraries needed for GUI support with Bazel builds + if _command_exists "apt-get"; then + _execute "Installing xcb libraries for GUI support..." \ + apt-get -y install --no-install-recommends \ + libxcb1-dev libxcb-util-dev libxcb-icccm4-dev libxcb-image0-dev \ + libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev \ + libxcb-xinerama0-dev libxcb-xkb-dev + elif _command_exists "yum"; then + _execute "Installing xcb libraries for GUI support..." \ + yum install -y \ + libxcb-devel xcb-util-devel xcb-util-image-devel \ + xcb-util-keysyms-devel xcb-util-renderutil-devel xcb-util-wm-devel + fi + fi + INSTALL_SUMMARY+=("Bazel: system=none, required=latest, status=installed") +} + +# ------------------------------------------------------------------------------ +# Bazel Dev Tools (buildifier, etc.) +# ------------------------------------------------------------------------------ +_install_bazel_dev() { + local bazel_prefix=${PREFIX:-"/usr/local"} + log "Checking Bazel dev tools (buildifier)" + if _command_exists "buildifier"; then + log "buildifier already installed, skipping." + INSTALL_SUMMARY+=("buildifier: system=found, required=any, status=skipped") + return + fi + if [[ "$OSTYPE" == "darwin"* ]]; then + _execute "Installing buildifier via Homebrew..." brew install buildifier + else + local arch + arch=$(uname -m) + local buildifier_arch="amd64" + if [[ "${arch}" == "aarch64" ]]; then + buildifier_arch="arm64" + fi + local buildifier_checksum="${BUILDIFIER_CHECKSUM_AMD64}" + if [[ "${buildifier_arch}" == "arm64" ]]; then + buildifier_checksum="${BUILDIFIER_CHECKSUM_ARM64}" + fi + ( + cd "${BASE_DIR}" + _execute "Downloading buildifier v${BUILDIFIER_VERSION}..." curl -Lo buildifier \ + "https://github.com/bazelbuild/buildtools/releases/download/v${BUILDIFIER_VERSION}/buildifier-linux-${buildifier_arch}" + _verify_checksum "${buildifier_checksum}" "buildifier" || error "Buildifier checksum failed." + chmod +x buildifier + _execute "Installing buildifier..." mv buildifier "${bazel_prefix}/bin/buildifier" + ) + fi + INSTALL_SUMMARY+=("buildifier: system=none, required=latest, status=installed") +} + _install_common_dev() { log "Install common development dependencies (-common or -all)" rm -rf "${BASE_DIR}" @@ -1038,6 +1131,8 @@ Options: -base Install base dependencies using package managers. Requires privileged access. -common Install common dependencies. -eqy Install equivalence dependencies (yosys, eqy, sby). + -bazel Download and install bazel (via bazelisk). + -bazel-dev Download and install bazel developer tools (buildifier, etc.). -prefix=DIR Install common dependencies in a user-specified directory. -local Install common dependencies in \${HOME}/.local. -ci Install dependencies required for CI. @@ -1063,6 +1158,8 @@ main() { -base) option="base" ;; -common) option="common" ;; -eqy) EQUIVALENCE_DEPS="yes" ;; + -bazel) INSTALL_BAZEL="yes" ;; + -bazel-dev) INSTALL_BAZEL_DEV="yes" ;; -ci) CI="yes" ;; -verbose) VERBOSE_MODE="yes" ;; -local) @@ -1109,8 +1206,23 @@ main() { shift 1 done + if [[ "${option}" == "none" && "${INSTALL_BAZEL}" == "no" && "${INSTALL_BAZEL_DEV}" == "no" ]]; then + error "You must use one of: -all, -base, -common, -bazel, or -bazel-dev." + fi + + # -bazel-dev implies -bazel (you need bazelisk to use buildifier) + if [[ "${INSTALL_BAZEL}" == "yes" || "${INSTALL_BAZEL_DEV}" == "yes" ]]; then + _install_bazel + fi + + if [[ "${INSTALL_BAZEL_DEV}" == "yes" ]]; then + _install_bazel_dev + fi + if [[ "${option}" == "none" ]]; then - error "You must use one of: -all, -base, or -common." + _print_summary + rm -rf "${BASE_DIR}" + return fi OR_TOOLS_PATH=${PREFIX:-"/opt/or-tools"} From e89327a9de928dbe484f964ef1e4cd01f7714eb5 Mon Sep 17 00:00:00 2001 From: alokkumardalei-wq Date: Mon, 27 Apr 2026 09:08:45 +0530 Subject: [PATCH 2/3] etc/Build.sh: drop dead isNinja block to fix unbound variable The isNinja branch was never reachable (no code path sets it) and under 'set -euo pipefail' it terminated the script with 'isNinja: unbound variable' at line 358 once master's removal of the ninja option (commit 4e494dfd64) was merged in. Remove the dead block. Reported by maliberty in #9762. Signed-off-by: alokkumardalei-wq --- etc/Build.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/etc/Build.sh b/etc/Build.sh index ec8157c16ad..d6729d45d8c 100755 --- a/etc/Build.sh +++ b/etc/Build.sh @@ -355,11 +355,5 @@ if [[ "$useBazel" == "yes" ]]; then "${bazel_cmd}" build "${bazelArgs[@]}" //:openroad exit 0 fi -if [[ "$isNinja" == "yes" ]]; then - cmake "${cmakeOptions[@]}" -B "${buildDir}" . - cd "${buildDir}" - CLICOLOR_FORCE=1 ninja build_and_test - exit 0 -fi cmake "${cmakeOptions[@]}" -B "${buildDir}" . time cmake --build "${buildDir}" -j "${numThreads}" From be6ca9a62726277d9bff448ecd44c2750f93dbfb Mon Sep 17 00:00:00 2001 From: alokkumardalei-wq Date: Tue, 28 Apr 2026 14:11:10 +0530 Subject: [PATCH 3/3] etc/DependencyInstaller: add -no-gui to skip xcb install Signed-off-by: alokkumardalei-wq --- etc/DependencyInstaller.sh | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/etc/DependencyInstaller.sh b/etc/DependencyInstaller.sh index 2bed2854f4a..0ea38cffbf8 100755 --- a/etc/DependencyInstaller.sh +++ b/etc/DependencyInstaller.sh @@ -74,6 +74,7 @@ OR_TOOLS_VERSION_SMALL="${OR_TOOLS_VERSION_BIG}.6206" EQUIVALENCE_DEPS="no" INSTALL_BAZEL="no" INSTALL_BAZEL_DEV="no" +NO_GUI="no" BAZELISK_VERSION="1.28.1" BAZELISK_CHECKSUM_AMD64="2dc74b7ad6bdd6b6b08f6802d14fc1fd" BAZELISK_CHECKSUM_ARM64="94415d08ed2f86a49375f25a7f2f9cca" @@ -820,18 +821,20 @@ _install_bazel() { chmod +x bazelisk _execute "Installing bazelisk..." mv bazelisk "${bazel_prefix}/bin/bazelisk" ) - # Install xcb libraries needed for GUI support with Bazel builds - if _command_exists "apt-get"; then - _execute "Installing xcb libraries for GUI support..." \ - apt-get -y install --no-install-recommends \ - libxcb1-dev libxcb-util-dev libxcb-icccm4-dev libxcb-image0-dev \ - libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev \ - libxcb-xinerama0-dev libxcb-xkb-dev - elif _command_exists "yum"; then - _execute "Installing xcb libraries for GUI support..." \ - yum install -y \ - libxcb-devel xcb-util-devel xcb-util-image-devel \ - xcb-util-keysyms-devel xcb-util-renderutil-devel xcb-util-wm-devel + if [[ "${NO_GUI}" != "yes" ]]; then + # Install xcb libraries needed for GUI support with Bazel builds + if _command_exists "apt-get"; then + _execute "Installing xcb libraries for GUI support..." \ + apt-get -y install --no-install-recommends \ + libxcb1-dev libxcb-util-dev libxcb-icccm4-dev libxcb-image0-dev \ + libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev \ + libxcb-xinerama0-dev libxcb-xkb-dev + elif _command_exists "yum"; then + _execute "Installing xcb libraries for GUI support..." \ + yum install -y \ + libxcb-devel xcb-util-devel xcb-util-image-devel \ + xcb-util-keysyms-devel xcb-util-renderutil-devel xcb-util-wm-devel + fi fi fi INSTALL_SUMMARY+=("Bazel: system=none, required=latest, status=installed") @@ -1134,6 +1137,7 @@ Options: -eqy Install equivalence dependencies (yosys, eqy, sby). -bazel Download and install bazel (via bazelisk). -bazel-dev Download and install bazel developer tools (buildifier, etc.). + -no-gui Skip GUI-only dependencies (e.g. xcb libraries) when used with -bazel. -prefix=DIR Install common dependencies in a user-specified directory. -local Install common dependencies in \${HOME}/.local. -ci Install dependencies required for CI. @@ -1161,6 +1165,7 @@ main() { -eqy) EQUIVALENCE_DEPS="yes" ;; -bazel) INSTALL_BAZEL="yes" ;; -bazel-dev) INSTALL_BAZEL_DEV="yes" ;; + -no-gui) NO_GUI="yes" ;; -ci) CI="yes" ;; -verbose) VERBOSE_MODE="yes" ;; -local)