Skip to content

Commit 7489262

Browse files
committed
Merge branch 'master' of https://github.com/The-OpenROAD-Project-private/OpenROAD-flow-scripts into secure-update_or
2 parents b4fd3d0 + 51ad123 commit 7489262

7 files changed

Lines changed: 181 additions & 18 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

‎etc/DependencyInstaller.sh‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ fi
1111

1212
# package versions
1313
klayoutVersion=0.30.3
14-
numThreads=$(nproc)
14+
if [[ "$OSTYPE" == "darwin"* ]]; then
15+
numThreads=$(sysctl -n hw.ncpu)
16+
else
17+
numThreads=$(nproc)
18+
fi
1519

1620
_versionCompare() {
1721
local a b IFS=. ; set -f

‎setup.sh‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ set -euo pipefail
55
# allow this script to be invoked from any folder
66
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
77

8-
if [ $EUID -ne 0 ]; then
9-
echo "This script must be run with sudo"
8+
if [[ "$OSTYPE" == "darwin"* ]] && [[ $EUID -eq 0 ]]; then
9+
echo "Do NOT run this script with sudo on macOS"
10+
exit 1
11+
fi
12+
13+
if [[ "$OSTYPE" != "darwin"* ]] && [[ $EUID -ne 0 ]]; then
14+
echo "This script must be run with sudo on Linux"
1015
exit 1
1116
fi
1217

@@ -17,7 +22,11 @@ tmpfile=$(mktemp)
1722
git submodule status --recursive > "$tmpfile"
1823

1924
if grep -q "^-" "$tmpfile"; then
20-
sudo -u $SUDO_USER git submodule update --init --recursive
25+
if [[ "$OSTYPE" == "darwin"* ]]; then
26+
git submodule update --init --recursive
27+
else
28+
sudo -u $SUDO_USER git submodule update --init --recursive
29+
fi
2130
elif grep -q "^+" "$tmpfile"; then
2231
# Make it easy for users who are not hacking ORFS to do the right thing,
2332
# run with current submodules, at the cost of having ORFS
@@ -27,4 +36,8 @@ elif grep -q "^+" "$tmpfile"; then
2736
fi
2837

2938
"$DIR/etc/DependencyInstaller.sh" -base
30-
sudo -u $SUDO_USER "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies"
39+
if [[ "$OSTYPE" == "darwin"* ]]; then
40+
"$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies"
41+
else
42+
sudo -u $SUDO_USER "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies"
43+
fi

0 commit comments

Comments
 (0)