Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

sh_binary(
name = "install_for_bazel",
srcs = ["bazel/install.sh"],
)
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ git_override(
)

bazel_dep(name = "rules_python", version = "1.2.0")
bazel_dep(name = "rules_shell", version = "0.6.1")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
Expand Down
3 changes: 2 additions & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 141 additions & 0 deletions bazel/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/bin/bash
set -e

# ORFS developer install script
# Builds and installs OpenROAD, Yosys, and yosys-slang to tools/install/
# where flow/Makefile expects them.
#
# Uses stamp files for fast no-op re-runs (seconds when nothing changed).

WORKSPACE="${BUILD_WORKSPACE_DIRECTORY:-.}"
INSTALL_DIR="${WORKSPACE}/tools/install"
NUM_THREADS=$(nproc)

# --- Check system dependencies for yosys/slang builds ---
check_deps() {
local missing_cmds=()

for cmd in bison flex gawk g++ pkg-config tclsh git cmake; do
if ! command -v "$cmd" &>/dev/null; then
missing_cmds+=("$cmd")
fi
done

if [[ ${#missing_cmds[@]} -eq 0 ]]; then
return
fi

echo "ERROR: Missing commands: ${missing_cmds[*]}"
echo ""

# Platform-specific install hint
if [[ "$(uname -s)" == "Darwin" ]]; then
echo " brew install bison flex gawk cmake pkg-config tcl-tk"
elif command -v apt-get &>/dev/null; then
echo " sudo apt-get install bison flex gawk g++ pkg-config tcl cmake git"
elif command -v dnf &>/dev/null; then
echo " sudo dnf install bison flex gawk gcc-c++ pkgconf tcl cmake git"
elif command -v yum &>/dev/null; then
echo " sudo yum install bison flex gawk gcc-c++ pkgconf tcl cmake git"
elif command -v zypper &>/dev/null; then
echo " sudo zypper install bison flex gawk gcc-c++ pkg-config tcl cmake git"
fi
exit 1
}

check_deps

BUILD_OPENROAD=1

usage() {
cat <<'EOF'
Usage: bazelisk run //:install_for_bazel [-- OPTIONS]

Options:
--help, -h Show this help
--skip-openroad Skip OpenROAD build
--threads N Compilation threads (default: nproc)
EOF
exit 0
}

while [[ $# -gt 0 ]]; do
case "$1" in
--help|-h)
usage
;;
--skip-openroad)
BUILD_OPENROAD=0
;;
--threads)
NUM_THREADS="$2"
shift
;;
*)
echo "Unknown option: $1"
usage
;;
esac
shift
done

# --- Check submodules are initialized ---
for sub in tools/OpenROAD tools/yosys tools/yosys-slang; do
if [[ ! -d "${WORKSPACE}/${sub}" ]] || [[ -z "$(ls -A "${WORKSPACE}/${sub}" 2>/dev/null)" ]]; then
echo "ERROR: ${sub} not initialized."
echo "Run: git submodule update --init --recursive"
exit 1
fi
done

# --- OpenROAD (delegates to its own //:install) ---
if [[ $BUILD_OPENROAD -eq 1 ]]; then
echo "=== Building OpenROAD with GUI support ==="
(cd "${WORKSPACE}/tools/OpenROAD" && bazelisk run --//:platform=gui //:install)
fi

# --- Yosys ---
# Uses stamp file for fast no-op: if the yosys submodule commit hasn't
# changed, skip the build entirely.
YOSYS_INSTALL="${INSTALL_DIR}/yosys"
YOSYS_STAMP="${YOSYS_INSTALL}/.yosys_commit"
YOSYS_COMMIT="$(git -C "${WORKSPACE}/tools/yosys" rev-parse HEAD)"

if [[ -f "${YOSYS_STAMP}" ]] && [[ "$(cat "${YOSYS_STAMP}")" == "${YOSYS_COMMIT}" ]]; then
echo "=== Yosys already up to date (${YOSYS_COMMIT:0:12}) ==="
else
echo "=== Building Yosys ==="
(
cd "${WORKSPACE}/tools/yosys"
make -j "${NUM_THREADS}" PREFIX="${YOSYS_INSTALL}" ABC_ARCHFLAGS=-Wno-register
make install PREFIX="${YOSYS_INSTALL}"
)
echo "${YOSYS_COMMIT}" > "${YOSYS_STAMP}"
echo "Yosys installed to ${YOSYS_INSTALL}/bin/yosys"
fi

# --- yosys-slang ---
SLANG_STAMP="${YOSYS_INSTALL}/.slang_commit"
SLANG_COMMIT="$(git -C "${WORKSPACE}/tools/yosys-slang" rev-parse HEAD)"

if [[ -f "${SLANG_STAMP}" ]] && [[ "$(cat "${SLANG_STAMP}")" == "${SLANG_COMMIT}" ]]; then
echo "=== yosys-slang already up to date (${SLANG_COMMIT:0:12}) ==="
else
echo "=== Building yosys-slang ==="
(
cd "${WORKSPACE}/tools/yosys-slang"
cmake -S . -B build \
-DYOSYS_CONFIG="${YOSYS_INSTALL}/bin/yosys-config" \
-DCMAKE_BUILD_TYPE=Release \
-DYOSYS_SLANG_REVISION=unknown \
-DSLANG_REVISION=unknown
cmake --build build -j "${NUM_THREADS}"
cmake --install build --prefix "${YOSYS_INSTALL}"
)
echo "${SLANG_COMMIT}" > "${SLANG_STAMP}"
echo "yosys-slang installed to ${YOSYS_INSTALL}/share/yosys/plugins/"
fi

echo ""
echo "=== Done ==="
echo "cd flow && make"
21 changes: 9 additions & 12 deletions docs/user/BuildLocally.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@ cd OpenROAD-flow-scripts
sudo ./setup.sh
```

## Using Bazel to build OpenROAD and run the ORFS flow
## Using Bazel to build OpenROAD and run the ORFS flow (unsupported)

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.

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:
For ORFS/OpenROAD developers. Most of `./setup.sh` isn't needed when
building OpenROAD with Bazel — this provides the bare minimum to build
OpenROAD and test ORFS flows. No sudo required.
Install [Bazelisk](https://bazel.build/install/bazelisk) first.

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

Bazel could similarly be used to download and make available pre-built binaries for tools such as Yosys, eqy and KLayout.

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.

## Build

``` shell
Expand Down