Skip to content

Commit 533abfc

Browse files
authored
Merge pull request #9762 from alokkumardalei-wq/feature/bazel-options-dependency-installer
Add -bazel and -bazel-dev options to DependencyInstaller and Build scripts
2 parents 65b977f + be6ca9a commit 533abfc

2 files changed

Lines changed: 150 additions & 21 deletions

File tree

etc/Build.sh

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ EOF
1919
numThreads=2
2020
fi
2121
cmakeOptions=()
22-
isNinja=no
2322
cleanBefore=no
2423
depsPrefixesFile=""
2524
compiler=gcc
25+
useBazel=no
26+
noGui=no
2627

2728
_help() {
2829
cat <<EOF
@@ -54,6 +55,7 @@ OPTIONS:
5455
-keep-log Keep a compile log in build dir
5556
-help Shows this message
5657
-gpu Enable GPU to accelerate the process
58+
-bazel Use Bazel instead of CMake to build
5759
-deps-prefixes-file=FILE File with CMake packages roots,
5860
its content extends -cmake argument.
5961
By default, "openroad_deps_prefixes.txt"
@@ -97,16 +99,11 @@ while [ "$#" -gt 0 ]; do
9799
;;
98100
-no-gui)
99101
cmakeOptions+=("-DBUILD_GUI=OFF")
102+
noGui=yes
100103
;;
101104
-no-tests)
102105
cmakeOptions+=("-DENABLE_TESTS=OFF")
103106
;;
104-
-ninja)
105-
cmakeOptions+=("-DCMAKE_C_COMPILER_LAUNCHER=ccache")
106-
cmakeOptions+=("-DCMAKE_CXX_COMPILER_LAUNCHER=ccache")
107-
cmakeOptions+=("-GNinja")
108-
isNinja=yes
109-
;;
110107
-cpp20)
111108
cmakeOptions+=("-DCMAKE_CXX_STANDARD=20")
112109
;;
@@ -125,8 +122,12 @@ while [ "$#" -gt 0 ]; do
125122
cmakeOptions+=("-DCMAKE_EXE_LINKER_FLAGS=-lgcov")
126123
;;
127124
-cmake=*)
128-
read -ra temp_arr <<< "${1#*=}"
129-
cmakeOptions+=("${temp_arr[@]}")
125+
# Use xargs to safely parse the quoted string into array elements without eval
126+
while IFS= read -r arg; do
127+
if [[ -n "$arg" ]]; then
128+
cmakeOptions+=("$arg")
129+
fi
130+
done < <(echo "${1#*=}" | xargs printf '%s\n')
130131
;;
131132
-clean )
132133
cleanBefore=yes
@@ -155,6 +156,9 @@ while [ "$#" -gt 0 ]; do
155156
-gpu)
156157
cmakeOptions+=("-DGPU=ON")
157158
;;
159+
-bazel)
160+
useBazel=yes
161+
;;
158162
*)
159163
echo "unknown option: ${1}" >&2
160164
_help
@@ -171,8 +175,11 @@ if [[ -z "$depsPrefixesFile" ]]; then
171175
fi
172176
fi
173177
if [[ -f "$depsPrefixesFile" ]]; then
174-
read -ra newOpts <<< "$(cat "$depsPrefixesFile")"
175-
cmakeOptions+=("${newOpts[@]}")
178+
while IFS= read -r arg; do
179+
if [[ -n "$arg" ]]; then
180+
cmakeOptions+=("$arg")
181+
fi
182+
done < <(xargs printf '%s\n' < "$depsPrefixesFile")
176183
echo "[INFO] Using additional CMake parameters from $depsPrefixesFile"
177184
else
178185
echo "[INFO] Auto-generated prefix file does not exist - CMake will choose the dependencies automatically"
@@ -333,10 +340,19 @@ echo -e "${GREEN}All pre-compilation checks passed! Proceeding...${NC}\n"
333340
# ==============================================================================
334341

335342
echo "[INFO] Using ${numThreads} threads."
336-
if [[ "$isNinja" == "yes" ]]; then
337-
cmake "${cmakeOptions[@]}" -B "${buildDir}" .
338-
cd "${buildDir}"
339-
CLICOLOR_FORCE=1 ninja build_and_test
343+
if [[ "$useBazel" == "yes" ]]; then
344+
echo "[INFO] Building with Bazel."
345+
bazel_cmd="bazel"
346+
if command -v bazelisk &> /dev/null; then
347+
bazel_cmd="bazelisk"
348+
fi
349+
bazelArgs=("--config=opt" "--jobs=${numThreads}")
350+
if [[ "$noGui" == "yes" ]]; then
351+
bazelArgs+=("--//:platform=cli")
352+
else
353+
bazelArgs+=("--//:platform=gui")
354+
fi
355+
"${bazel_cmd}" build "${bazelArgs[@]}" //:openroad
340356
exit 0
341357
fi
342358
cmake "${cmakeOptions[@]}" -B "${buildDir}" .

etc/DependencyInstaller.sh

Lines changed: 119 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ set -euo pipefail
1616
PREFIX=""
1717
CI="no"
1818
SAVE_DEPS_PREFIXES=""
19-
if [[ "$OSTYPE" == "darwin"* ]]; then
20-
NUM_THREADS=$(sysctl -n hw.logicalcpu)
21-
else
22-
NUM_THREADS=$(nproc)
23-
fi
19+
NUM_THREADS=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
2420
SKIP_SYSTEM_OR_TOOLS="false"
2521
BASE_DIR=$(mktemp -d /tmp/DependencyInstaller-XXXXXX)
2622
CMAKE_PACKAGE_ROOT_ARGS=""
@@ -76,6 +72,15 @@ FLEX_CHECKSUM="2882e3179748cc9f9c23ec593d6adc8d"
7672
OR_TOOLS_VERSION_BIG="9.14"
7773
OR_TOOLS_VERSION_SMALL="${OR_TOOLS_VERSION_BIG}.6206"
7874
EQUIVALENCE_DEPS="no"
75+
INSTALL_BAZEL="no"
76+
INSTALL_BAZEL_DEV="no"
77+
NO_GUI="no"
78+
BAZELISK_VERSION="1.28.1"
79+
BAZELISK_CHECKSUM_AMD64="2dc74b7ad6bdd6b6b08f6802d14fc1fd"
80+
BAZELISK_CHECKSUM_ARM64="94415d08ed2f86a49375f25a7f2f9cca"
81+
BUILDIFIER_VERSION="8.5.1"
82+
BUILDIFIER_CHECKSUM_AMD64="72f5953ab6dcc309a4447c2e2d79c680"
83+
BUILDIFIER_CHECKSUM_ARM64="06f52f0872bde33685c6260110261cf7"
7984
# ... configuration variables will be added here ...
8085

8186
# ==============================================================================
@@ -784,6 +789,93 @@ _install_or_tools() {
784789
# Each dependency will have its own dedicated function for installation and
785790
# version management. This modular approach makes the script easier to
786791
# maintain and extend.
792+
# ------------------------------------------------------------------------------
793+
# Bazel
794+
# ------------------------------------------------------------------------------
795+
_install_bazel() {
796+
local bazel_prefix=${PREFIX:-"/usr/local"}
797+
log "Checking Bazel (via bazelisk)"
798+
if _command_exists "bazelisk"; then
799+
log "bazelisk already installed, skipping."
800+
INSTALL_SUMMARY+=("Bazel: system=found, required=any, status=skipped")
801+
return
802+
fi
803+
if [[ "$OSTYPE" == "darwin"* ]]; then
804+
_execute "Installing bazelisk via Homebrew..." brew install bazelisk
805+
else
806+
local arch
807+
arch=$(uname -m)
808+
local bazelisk_arch="amd64"
809+
if [[ "${arch}" == "aarch64" ]]; then
810+
bazelisk_arch="arm64"
811+
fi
812+
local bazelisk_checksum="${BAZELISK_CHECKSUM_AMD64}"
813+
if [[ "${bazelisk_arch}" == "arm64" ]]; then
814+
bazelisk_checksum="${BAZELISK_CHECKSUM_ARM64}"
815+
fi
816+
(
817+
cd "${BASE_DIR}"
818+
_execute "Downloading bazelisk v${BAZELISK_VERSION}..." curl -Lo bazelisk \
819+
"https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK_VERSION}/bazelisk-linux-${bazelisk_arch}"
820+
_verify_checksum "${bazelisk_checksum}" "bazelisk" || error "Bazelisk checksum failed."
821+
chmod +x bazelisk
822+
_execute "Installing bazelisk..." mv bazelisk "${bazel_prefix}/bin/bazelisk"
823+
)
824+
if [[ "${NO_GUI}" != "yes" ]]; then
825+
# Install xcb libraries needed for GUI support with Bazel builds
826+
if _command_exists "apt-get"; then
827+
_execute "Installing xcb libraries for GUI support..." \
828+
apt-get -y install --no-install-recommends \
829+
libxcb1-dev libxcb-util-dev libxcb-icccm4-dev libxcb-image0-dev \
830+
libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev \
831+
libxcb-xinerama0-dev libxcb-xkb-dev
832+
elif _command_exists "yum"; then
833+
_execute "Installing xcb libraries for GUI support..." \
834+
yum install -y \
835+
libxcb-devel xcb-util-devel xcb-util-image-devel \
836+
xcb-util-keysyms-devel xcb-util-renderutil-devel xcb-util-wm-devel
837+
fi
838+
fi
839+
fi
840+
INSTALL_SUMMARY+=("Bazel: system=none, required=latest, status=installed")
841+
}
842+
843+
# ------------------------------------------------------------------------------
844+
# Bazel Dev Tools (buildifier, etc.)
845+
# ------------------------------------------------------------------------------
846+
_install_bazel_dev() {
847+
local bazel_prefix=${PREFIX:-"/usr/local"}
848+
log "Checking Bazel dev tools (buildifier)"
849+
if _command_exists "buildifier"; then
850+
log "buildifier already installed, skipping."
851+
INSTALL_SUMMARY+=("buildifier: system=found, required=any, status=skipped")
852+
return
853+
fi
854+
if [[ "$OSTYPE" == "darwin"* ]]; then
855+
_execute "Installing buildifier via Homebrew..." brew install buildifier
856+
else
857+
local arch
858+
arch=$(uname -m)
859+
local buildifier_arch="amd64"
860+
if [[ "${arch}" == "aarch64" ]]; then
861+
buildifier_arch="arm64"
862+
fi
863+
local buildifier_checksum="${BUILDIFIER_CHECKSUM_AMD64}"
864+
if [[ "${buildifier_arch}" == "arm64" ]]; then
865+
buildifier_checksum="${BUILDIFIER_CHECKSUM_ARM64}"
866+
fi
867+
(
868+
cd "${BASE_DIR}"
869+
_execute "Downloading buildifier v${BUILDIFIER_VERSION}..." curl -Lo buildifier \
870+
"https://github.com/bazelbuild/buildtools/releases/download/v${BUILDIFIER_VERSION}/buildifier-linux-${buildifier_arch}"
871+
_verify_checksum "${buildifier_checksum}" "buildifier" || error "Buildifier checksum failed."
872+
chmod +x buildifier
873+
_execute "Installing buildifier..." mv buildifier "${bazel_prefix}/bin/buildifier"
874+
)
875+
fi
876+
INSTALL_SUMMARY+=("buildifier: system=none, required=latest, status=installed")
877+
}
878+
787879
_install_common_dev() {
788880
log "Install common development dependencies (-common or -all)"
789881
rm -rf "${BASE_DIR}"
@@ -1043,6 +1135,9 @@ Options:
10431135
-base Install base dependencies using package managers. Requires privileged access.
10441136
-common Install common dependencies.
10451137
-eqy Install equivalence dependencies (yosys, eqy, sby).
1138+
-bazel Download and install bazel (via bazelisk).
1139+
-bazel-dev Download and install bazel developer tools (buildifier, etc.).
1140+
-no-gui Skip GUI-only dependencies (e.g. xcb libraries) when used with -bazel.
10461141
-prefix=DIR Install common dependencies in a user-specified directory.
10471142
-local Install common dependencies in \${HOME}/.local.
10481143
-ci Install dependencies required for CI.
@@ -1068,6 +1163,9 @@ main() {
10681163
-base) option="base" ;;
10691164
-common) option="common" ;;
10701165
-eqy) EQUIVALENCE_DEPS="yes" ;;
1166+
-bazel) INSTALL_BAZEL="yes" ;;
1167+
-bazel-dev) INSTALL_BAZEL_DEV="yes" ;;
1168+
-no-gui) NO_GUI="yes" ;;
10711169
-ci) CI="yes" ;;
10721170
-verbose) VERBOSE_MODE="yes" ;;
10731171
-local)
@@ -1113,8 +1211,23 @@ main() {
11131211
shift 1
11141212
done
11151213

1214+
if [[ "${option}" == "none" && "${INSTALL_BAZEL}" == "no" && "${INSTALL_BAZEL_DEV}" == "no" ]]; then
1215+
error "You must use one of: -all, -base, -common, -bazel, or -bazel-dev."
1216+
fi
1217+
1218+
# -bazel-dev implies -bazel (you need bazelisk to use buildifier)
1219+
if [[ "${INSTALL_BAZEL}" == "yes" || "${INSTALL_BAZEL_DEV}" == "yes" ]]; then
1220+
_install_bazel
1221+
fi
1222+
1223+
if [[ "${INSTALL_BAZEL_DEV}" == "yes" ]]; then
1224+
_install_bazel_dev
1225+
fi
1226+
11161227
if [[ "${option}" == "none" ]]; then
1117-
error "You must use one of: -all, -base, or -common."
1228+
_print_summary
1229+
rm -rf "${BASE_DIR}"
1230+
return
11181231
fi
11191232

11201233
OR_TOOLS_PATH=${PREFIX:-"/opt/or-tools"}

0 commit comments

Comments
 (0)