diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 0000000000..21e694405f --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,6 @@ +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") + +sh_binary( + name = "install_for_bazel", + srcs = ["bazel/install.sh"], +) diff --git a/MODULE.bazel b/MODULE.bazel index 574d678f5d..9687e51c48 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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( diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 45ece7112e..ffe386712a 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -124,7 +124,8 @@ "https://bcr.bazel.build/modules/rules_python/1.2.0/MODULE.bazel": "5aeeb48b2a6c19d668b48adf2b8a2b209a6310c230db0ce77450f148a89846e4", "https://bcr.bazel.build/modules/rules_python/1.2.0/source.json": "5b7892685c9a843526fd5a31e7d7a93eb819c59fd7b7fc444b5b143558e1b073", "https://bcr.bazel.build/modules/rules_shell/0.2.0/MODULE.bazel": "fda8a652ab3c7d8fee214de05e7a9916d8b28082234e8d2c0094505c5268ed3c", - "https://bcr.bazel.build/modules/rules_shell/0.2.0/source.json": "7f27af3c28037d9701487c4744b5448d26537cc66cdef0d8df7ae85411f8de95", + "https://bcr.bazel.build/modules/rules_shell/0.6.1/MODULE.bazel": "72e76b0eea4e81611ef5452aa82b3da34caca0c8b7b5c0c9584338aa93bae26b", + "https://bcr.bazel.build/modules/rules_shell/0.6.1/source.json": "20ec05cd5e592055e214b2da8ccb283c7f2a421ea0dc2acbf1aa792e11c03d0c", "https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8", "https://bcr.bazel.build/modules/stardoc/0.5.3/MODULE.bazel": "c7f6948dae6999bf0db32c1858ae345f112cacf98f174c7a8bb707e41b974f1c", "https://bcr.bazel.build/modules/stardoc/0.6.2/MODULE.bazel": "7060193196395f5dd668eda046ccbeacebfd98efc77fed418dbe2b82ffaa39fd", diff --git a/bazel/install.sh b/bazel/install.sh new file mode 100755 index 0000000000..21a3f48c01 --- /dev/null +++ b/bazel/install.sh @@ -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" diff --git a/docs/user/BuildLocally.md b/docs/user/BuildLocally.md index 79a2dd09aa..120b4f943e 100644 --- a/docs/user/BuildLocally.md +++ b/docs/user/BuildLocally.md @@ -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