Skip to content

Commit c50a4a0

Browse files
oharboeclaude
andcommitted
Add bazelisk run //:install
bazelisk run //:install Builds and installs OpenROAD (with GUI), Yosys, and yosys-slang to tools/install/. Re-runs are instant (stamp file per submodule commit). No sudo required. On Ubuntu, checks for missing -dev packages before building and fails fast with the apt install command. Other platforms not checked (we can't test them, contributions welcome). Docs updated to present Bazel / Nix / CMake as three equal paths. Zero churn: no changes to DependencyInstaller.sh, flow/, setup.sh, build_openroad.sh, or Nix flakes. Tested: gcd/nangate45 synth, asap7/uart synth (yosys-slang). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> Signed-off-by: Øyvind Harboe <[email protected]>
1 parent a6f355a commit c50a4a0

5 files changed

Lines changed: 210 additions & 35 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",
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: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# ORFS install script
5+
# Single user-facing entry point: bazelisk run //:install
6+
#
7+
# Builds and installs tools to tools/install/ where flow/Makefile expects them.
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+
usage() {
15+
cat <<'EOF'
16+
Usage: bazelisk run //:install [-- OPTIONS]
17+
18+
Installs tools required for the ORFS flow/Makefile.
19+
20+
Installed:
21+
openroad OpenROAD with GUI support
22+
yosys Yosys synthesis tool
23+
yosys-slang Yosys SystemVerilog plugin
24+
25+
Not yet supported (use sudo ./setup.sh):
26+
klayout KLayout layout viewer
27+
kepler Kepler formal verification
28+
29+
Nix users: nix develop already provides all tools. See flake.nix.
30+
31+
Options:
32+
--help, -h Show this help
33+
--skip-openroad Skip OpenROAD build
34+
--threads N Compilation threads (default: nproc)
35+
EOF
36+
exit 0
37+
}
38+
39+
# Check for required system dependencies before expensive builds.
40+
# ORFS checks deps for what it builds (yosys/slang). OpenROAD checks
41+
# its own deps in tools/OpenROAD/bazel/install.sh (separation of concerns).
42+
#
43+
# Currently only Ubuntu/Debian is checked. Dependency checking for
44+
# other platforms (macOS, RHEL, Fedora, etc.) is not implemented
45+
# because we cannot test them. Contributions welcome.
46+
check_ubuntu_deps() {
47+
local missing_cmds=()
48+
local missing_pkgs=()
49+
50+
# Commands needed for yosys build
51+
command -v bison &>/dev/null || { missing_cmds+=(bison); missing_pkgs+=(bison); }
52+
command -v flex &>/dev/null || { missing_cmds+=(flex); missing_pkgs+=(flex); }
53+
command -v gawk &>/dev/null || { missing_cmds+=(gawk); missing_pkgs+=(gawk); }
54+
command -v g++ &>/dev/null || { missing_cmds+=(g++); missing_pkgs+=(g++); }
55+
command -v pkg-config &>/dev/null || { missing_cmds+=(pkg-config); missing_pkgs+=(pkg-config); }
56+
command -v tclsh &>/dev/null || { missing_cmds+=(tclsh); missing_pkgs+=(tcl); }
57+
command -v git &>/dev/null || { missing_cmds+=(git); missing_pkgs+=(git); }
58+
command -v cmake &>/dev/null || { missing_cmds+=(cmake); missing_pkgs+=(cmake); }
59+
60+
# Dev libraries needed for yosys/slang compilation (check via dpkg)
61+
for pkg in tcl-dev libffi-dev libreadline-dev zlib1g-dev; do
62+
if ! dpkg -s "$pkg" &>/dev/null 2>&1; then
63+
missing_pkgs+=("$pkg")
64+
fi
65+
done
66+
67+
if [[ ${#missing_pkgs[@]} -gt 0 ]]; then
68+
echo "ERROR: Missing dependencies for Yosys build."
69+
if [[ ${#missing_cmds[@]} -gt 0 ]]; then
70+
echo " Missing commands: ${missing_cmds[*]}"
71+
fi
72+
echo ""
73+
echo "On Ubuntu this would be:"
74+
echo " sudo apt install ${missing_pkgs[*]}"
75+
exit 1
76+
fi
77+
}
78+
79+
if command -v dpkg &>/dev/null; then
80+
check_ubuntu_deps
81+
fi
82+
83+
BUILD_OPENROAD=1
84+
85+
while [[ $# -gt 0 ]]; do
86+
case "$1" in
87+
--help|-h)
88+
usage
89+
;;
90+
--skip-openroad)
91+
BUILD_OPENROAD=0
92+
;;
93+
--threads)
94+
NUM_THREADS="$2"
95+
shift
96+
;;
97+
*)
98+
echo "Unknown option: $1"
99+
usage
100+
;;
101+
esac
102+
shift
103+
done
104+
105+
# --- Check submodules are initialized ---
106+
for sub in tools/OpenROAD tools/yosys tools/yosys-slang; do
107+
if [[ ! -d "${WORKSPACE}/${sub}" ]] || [[ -z "$(ls -A "${WORKSPACE}/${sub}" 2>/dev/null)" ]]; then
108+
echo "ERROR: ${sub} not initialized."
109+
echo "Run: git submodule update --init --recursive"
110+
exit 1
111+
fi
112+
done
113+
114+
# --- OpenROAD (delegates to its own //:install) ---
115+
if [[ $BUILD_OPENROAD -eq 1 ]]; then
116+
echo "=== Building OpenROAD with GUI support ==="
117+
(cd "${WORKSPACE}/tools/OpenROAD" && bazelisk run --//:platform=gui //:install)
118+
fi
119+
120+
# --- Yosys ---
121+
# Uses stamp file for fast no-op: if the yosys submodule commit hasn't
122+
# changed, skip the build entirely.
123+
YOSYS_INSTALL="${INSTALL_DIR}/yosys"
124+
YOSYS_STAMP="${YOSYS_INSTALL}/.yosys_commit"
125+
YOSYS_COMMIT="$(git -C "${WORKSPACE}/tools/yosys" rev-parse HEAD)"
126+
127+
if [[ -f "${YOSYS_STAMP}" ]] && [[ "$(cat "${YOSYS_STAMP}")" == "${YOSYS_COMMIT}" ]]; then
128+
echo "=== Yosys already up to date (${YOSYS_COMMIT:0:12}) ==="
129+
else
130+
echo "=== Building Yosys ==="
131+
(
132+
cd "${WORKSPACE}/tools/yosys"
133+
make -j "${NUM_THREADS}" PREFIX="${YOSYS_INSTALL}" ABC_ARCHFLAGS=-Wno-register
134+
make install PREFIX="${YOSYS_INSTALL}"
135+
)
136+
echo "${YOSYS_COMMIT}" > "${YOSYS_STAMP}"
137+
echo "Yosys installed to ${YOSYS_INSTALL}/bin/yosys"
138+
fi
139+
140+
# --- yosys-slang ---
141+
SLANG_STAMP="${YOSYS_INSTALL}/.slang_commit"
142+
SLANG_COMMIT="$(git -C "${WORKSPACE}/tools/yosys-slang" rev-parse HEAD)"
143+
144+
if [[ -f "${SLANG_STAMP}" ]] && [[ "$(cat "${SLANG_STAMP}")" == "${SLANG_COMMIT}" ]]; then
145+
echo "=== yosys-slang already up to date (${SLANG_COMMIT:0:12}) ==="
146+
else
147+
echo "=== Building yosys-slang ==="
148+
(
149+
cd "${WORKSPACE}/tools/yosys-slang"
150+
cmake -S . -B build \
151+
-DYOSYS_CONFIG="${YOSYS_INSTALL}/bin/yosys-config" \
152+
-DCMAKE_BUILD_TYPE=Release \
153+
-DYOSYS_SLANG_REVISION=unknown \
154+
-DSLANG_REVISION=unknown
155+
cmake --build build -j "${NUM_THREADS}"
156+
cmake --install build --prefix "${YOSYS_INSTALL}"
157+
)
158+
echo "${SLANG_COMMIT}" > "${SLANG_STAMP}"
159+
echo "yosys-slang installed to ${YOSYS_INSTALL}/share/yosys/plugins/"
160+
fi
161+
162+
echo ""
163+
echo "=== Done ==="
164+
echo "cd flow && make"

docs/user/BuildLocally.md

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
11
# Build from sources locally
22

3-
## Clone and Install Dependencies
3+
## Choose Your Build Path
44

5-
The `setup.sh` script installs all of the dependencies, including OpenROAD dependencies, if they are not already installed.
5+
| Path | Prerequisites | sudo? | Best for |
6+
|------|--------------|-------|----------|
7+
| **Bazel** | [Bazelisk](https://bazel.build/install/bazelisk) | No | Most users |
8+
| **Nix** | [Nix](https://github.com/DeterminateSystems/nix-installer) | No | Nix users |
9+
| **CMake** | `sudo ./setup.sh` | Yes | Existing CMake developers |
610

7-
Supported configurations are: Ubuntu 20.04, Ubuntu 22.04, Ubuntu 22.04(aarch64), RHEL 8, RockyLinux 9 and Debian 11.
11+
### Bazel (recommended)
12+
13+
Install [Bazelisk](https://bazel.build/install/bazelisk) following the
14+
[official instructions](https://bazel.build/install/bazelisk).
815

916
``` shell
1017
git clone --recursive https://github.com/The-OpenROAD-Project/OpenROAD-flow-scripts
1118
cd OpenROAD-flow-scripts
12-
sudo ./setup.sh
19+
bazelisk run //:install
20+
cd flow && make
1321
```
1422

15-
## Using Bazel to build OpenROAD and run the ORFS flow
16-
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.
23+
For options: `bazelisk run //:install -- --help`
1824

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:
25+
### Nix
2026

2127
``` 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
28+
git clone --recursive https://github.com/The-OpenROAD-Project/OpenROAD-flow-scripts
29+
cd OpenROAD-flow-scripts
30+
nix develop
31+
cd flow && make
2632
```
2733

28-
Bazel could similarly be used to download and make available pre-built binaries for tools such as Yosys, eqy and KLayout.
34+
### CMake (existing path)
35+
36+
## Clone and Install Dependencies
37+
38+
The `setup.sh` script installs all of the dependencies, including OpenROAD dependencies, if they are not already installed.
39+
40+
Supported configurations are: Ubuntu 20.04, Ubuntu 22.04, Ubuntu 22.04(aarch64), RHEL 8, RockyLinux 9 and Debian 11.
2941

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.
42+
``` shell
43+
git clone --recursive https://github.com/The-OpenROAD-Project/OpenROAD-flow-scripts
44+
cd OpenROAD-flow-scripts
45+
sudo ./setup.sh
46+
```
3147

3248
## Build
3349

@@ -72,35 +88,22 @@ Set up environment variables using `dev_env.sh`, then start Visual Studio Code.
7288
code tools/OpenROAD/
7389
```
7490

75-
## Build OpenROAD and run a few ORFS flows with Bazel
76-
77-
Local use case:
91+
## Build and run ORFS flows with Bazel
7892

79-
- Install Bazelisk and no other dependencies, no need to run `sudo ./setup.sh`
80-
- Modify & build OpenROAD
81-
- Test built OpenROAD with a few ORFS flows
93+
ORFS uses [bazel-orfs](https://github.com/The-OpenROAD-Project/bazel-orfs) to run
94+
the flow entirely within Bazel. This is separate from `bazelisk run //:install` above
95+
which installs tools for the Makefile-based flow.
8296

83-
The Bazel support in OpenROAD and ORFS is work in progress and some Bazel experience is recommended before going spelunking in the Bazel builds.
84-
85-
Contributions welcome!
86-
87-
To build `designs/asap7/gcd:gcd_floorplan`:
88-
89-
cd flow
90-
(cd ../tools/OpenROAD && bazel build :openroad -c opt) && bazelisk build designs/asap7/gcd:gcd_floorplan
91-
92-
Or to run all flows currently available in Bazel
97+
To build a design with Bazel:
9398

9499
cd flow
95-
(cd ../tools/OpenROAD && bazel build :openroad -c opt) && bazelisk build ...
100+
bazelisk build designs/asap7/gcd:gcd_floorplan
96101

97-
Note! ORFS uses the OpenROAD Bazel built binary in stop-gap way until OpenROAD has been switched to bzlmod, after which to build all flows becomes simpler as ORFS will build the requisite OpenROAD directly:
102+
Or to run all flows currently available in Bazel:
98103

99104
cd flow
100105
bazelisk build ...
101106

102-
ORFS uses [bazel-orfs](https://github.com/The-OpenROAD-Project/bazel-orfs) to implement the flow and gets some depedencies, like yosys, from the Docker image. Over time, all dependencies should be built with Bazel and the dependency on the ORFS Docker image will be phased out.
103-
104107
### Upgrading MODULE.bazel with the latest bazel-orfs and ORFS Docker image
105108

106109
Run:

0 commit comments

Comments
 (0)