Skip to content

Commit 8ad0ff7

Browse files
authored
Merge pull request #4003 from Pinata-Consulting/bazel-install
Add bazelisk run //:install
2 parents 4ba75de + 5d9832d commit 8ad0ff7

5 files changed

Lines changed: 159 additions & 13 deletions

File tree

BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
2+
3+
sh_binary(
4+
name = "install_for_bazel",
5+
srcs = ["bazel/install.sh"],
6+
)

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ git_override(
1616
)
1717

1818
bazel_dep(name = "rules_python", version = "1.2.0")
19+
bazel_dep(name = "rules_shell", version = "0.6.1")
1920

2021
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
2122
python.toolchain(

MODULE.bazel.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bazel/install.sh

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# ORFS developer install script
5+
# Builds and installs OpenROAD, Yosys, and yosys-slang to tools/install/
6+
# where flow/Makefile expects them.
7+
#
8+
# Uses stamp files for fast no-op re-runs (seconds when nothing changed).
9+
10+
WORKSPACE="${BUILD_WORKSPACE_DIRECTORY:-.}"
11+
INSTALL_DIR="${WORKSPACE}/tools/install"
12+
NUM_THREADS=$(nproc)
13+
14+
# --- Check system dependencies for yosys/slang builds ---
15+
check_deps() {
16+
local missing_cmds=()
17+
18+
for cmd in bison flex gawk g++ pkg-config tclsh git cmake; do
19+
if ! command -v "$cmd" &>/dev/null; then
20+
missing_cmds+=("$cmd")
21+
fi
22+
done
23+
24+
if [[ ${#missing_cmds[@]} -eq 0 ]]; then
25+
return
26+
fi
27+
28+
echo "ERROR: Missing commands: ${missing_cmds[*]}"
29+
echo ""
30+
31+
# Platform-specific install hint
32+
if [[ "$(uname -s)" == "Darwin" ]]; then
33+
echo " brew install bison flex gawk cmake pkg-config tcl-tk"
34+
elif command -v apt-get &>/dev/null; then
35+
echo " sudo apt-get install bison flex gawk g++ pkg-config tcl cmake git"
36+
elif command -v dnf &>/dev/null; then
37+
echo " sudo dnf install bison flex gawk gcc-c++ pkgconf tcl cmake git"
38+
elif command -v yum &>/dev/null; then
39+
echo " sudo yum install bison flex gawk gcc-c++ pkgconf tcl cmake git"
40+
elif command -v zypper &>/dev/null; then
41+
echo " sudo zypper install bison flex gawk gcc-c++ pkg-config tcl cmake git"
42+
fi
43+
exit 1
44+
}
45+
46+
check_deps
47+
48+
BUILD_OPENROAD=1
49+
50+
usage() {
51+
cat <<'EOF'
52+
Usage: bazelisk run //:install_for_bazel [-- OPTIONS]
53+
54+
Options:
55+
--help, -h Show this help
56+
--skip-openroad Skip OpenROAD build
57+
--threads N Compilation threads (default: nproc)
58+
EOF
59+
exit 0
60+
}
61+
62+
while [[ $# -gt 0 ]]; do
63+
case "$1" in
64+
--help|-h)
65+
usage
66+
;;
67+
--skip-openroad)
68+
BUILD_OPENROAD=0
69+
;;
70+
--threads)
71+
NUM_THREADS="$2"
72+
shift
73+
;;
74+
*)
75+
echo "Unknown option: $1"
76+
usage
77+
;;
78+
esac
79+
shift
80+
done
81+
82+
# --- Check submodules are initialized ---
83+
for sub in tools/OpenROAD tools/yosys tools/yosys-slang; do
84+
if [[ ! -d "${WORKSPACE}/${sub}" ]] || [[ -z "$(ls -A "${WORKSPACE}/${sub}" 2>/dev/null)" ]]; then
85+
echo "ERROR: ${sub} not initialized."
86+
echo "Run: git submodule update --init --recursive"
87+
exit 1
88+
fi
89+
done
90+
91+
# --- OpenROAD (delegates to its own //:install) ---
92+
if [[ $BUILD_OPENROAD -eq 1 ]]; then
93+
echo "=== Building OpenROAD with GUI support ==="
94+
(cd "${WORKSPACE}/tools/OpenROAD" && bazelisk run --//:platform=gui //:install)
95+
fi
96+
97+
# --- Yosys ---
98+
# Uses stamp file for fast no-op: if the yosys submodule commit hasn't
99+
# changed, skip the build entirely.
100+
YOSYS_INSTALL="${INSTALL_DIR}/yosys"
101+
YOSYS_STAMP="${YOSYS_INSTALL}/.yosys_commit"
102+
YOSYS_COMMIT="$(git -C "${WORKSPACE}/tools/yosys" rev-parse HEAD)"
103+
104+
if [[ -f "${YOSYS_STAMP}" ]] && [[ "$(cat "${YOSYS_STAMP}")" == "${YOSYS_COMMIT}" ]]; then
105+
echo "=== Yosys already up to date (${YOSYS_COMMIT:0:12}) ==="
106+
else
107+
echo "=== Building Yosys ==="
108+
(
109+
cd "${WORKSPACE}/tools/yosys"
110+
make -j "${NUM_THREADS}" PREFIX="${YOSYS_INSTALL}" ABC_ARCHFLAGS=-Wno-register
111+
make install PREFIX="${YOSYS_INSTALL}"
112+
)
113+
echo "${YOSYS_COMMIT}" > "${YOSYS_STAMP}"
114+
echo "Yosys installed to ${YOSYS_INSTALL}/bin/yosys"
115+
fi
116+
117+
# --- yosys-slang ---
118+
SLANG_STAMP="${YOSYS_INSTALL}/.slang_commit"
119+
SLANG_COMMIT="$(git -C "${WORKSPACE}/tools/yosys-slang" rev-parse HEAD)"
120+
121+
if [[ -f "${SLANG_STAMP}" ]] && [[ "$(cat "${SLANG_STAMP}")" == "${SLANG_COMMIT}" ]]; then
122+
echo "=== yosys-slang already up to date (${SLANG_COMMIT:0:12}) ==="
123+
else
124+
echo "=== Building yosys-slang ==="
125+
(
126+
cd "${WORKSPACE}/tools/yosys-slang"
127+
cmake -S . -B build \
128+
-DYOSYS_CONFIG="${YOSYS_INSTALL}/bin/yosys-config" \
129+
-DCMAKE_BUILD_TYPE=Release \
130+
-DYOSYS_SLANG_REVISION=unknown \
131+
-DSLANG_REVISION=unknown
132+
cmake --build build -j "${NUM_THREADS}"
133+
cmake --install build --prefix "${YOSYS_INSTALL}"
134+
)
135+
echo "${SLANG_COMMIT}" > "${SLANG_STAMP}"
136+
echo "yosys-slang installed to ${YOSYS_INSTALL}/share/yosys/plugins/"
137+
fi
138+
139+
echo ""
140+
echo "=== Done ==="
141+
echo "cd flow && make"

docs/user/BuildLocally.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,20 @@ cd OpenROAD-flow-scripts
1212
sudo ./setup.sh
1313
```
1414

15-
## Using Bazel to build OpenROAD and run the ORFS flow
15+
## Using Bazel to build OpenROAD and run the ORFS flow (unsupported)
1616

17-
Long story short: OpenROAD will eventually switch to using Bazel for downloading dependencies and building OpenROAD for all the reasons that the DependencyInstaller.sh and cmake are hard to support and brittle across platforms.
18-
19-
Currently the simplest way to build OpenROAD and run ORFS is to run one test, which will download all OpenROAD dependencies and build OpenROAD in the exec configuration:
17+
For ORFS/OpenROAD developers. Most of `./setup.sh` isn't needed when
18+
building OpenROAD with Bazel — this provides the bare minimum to build
19+
OpenROAD and test ORFS flows. No sudo required.
20+
Install [Bazelisk](https://bazel.build/install/bazelisk) first.
2021

2122
``` shell
22-
cd tools/OpenROAD
23-
bazelisk test src/drt/...
24-
cd ../../flow
25-
make OPENROAD_EXE=$(pwd)/../tools/OpenROAD/bazel-out/k8-opt-exec-ST-*/bin/openroad
23+
git clone --recursive https://github.com/The-OpenROAD-Project/OpenROAD-flow-scripts
24+
cd OpenROAD-flow-scripts
25+
bazelisk run //:install_for_bazel
26+
cd flow && make
2627
```
2728

28-
Bazel could similarly be used to download and make available pre-built binaries for tools such as Yosys, eqy and KLayout.
29-
30-
Running some quick tests will cause the desired exec config of OpenROAD to be built. There's no explicit Bazel way to build an exec config of an executable and we want to to use an exec config that is the same binary as is used for a local OpenROAD modify + test Bazel cycle.
31-
3229
## Build
3330

3431
``` shell

0 commit comments

Comments
 (0)