Repository navigation
RFC: install bazel-packaged yosys instead of compiling from scratch #4325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,23 @@ | ||
| load("@bazel-orfs//:yosys_pkg.bzl", "yosys_prefix_tar") | ||
| load("@rules_shell//shell:sh_binary.bzl", "sh_binary") | ||
|
|
||
| sh_binary( | ||
| name = "install_for_bazel", | ||
| srcs = ["bazel/install.sh"], | ||
| # bazel/ is its own package (bazel/BUILD), so a cross-package label | ||
| # is required here; bazel/install.sh silently broke every root-package | ||
| # target once bazel/BUILD appeared. | ||
| srcs = ["//bazel:install.sh"], | ||
| ) | ||
|
|
||
| # Relocatable PREFIX tarball of the hermetic bazel-built yosys | ||
| # (bin/yosys, bin/yosys-abc, share/yosys/..., share/yosys/plugins/slang.so). | ||
| # This is the single source of truth for the yosys that | ||
| # etc/DependencyInstaller.sh and bazel/install.sh install; the version is | ||
| # the @yosys pin in bazel-orfs MODULE.bazel (bump via | ||
| # `bazelisk run @bazel-orfs//:bump`). | ||
| yosys_prefix_tar( | ||
| name = "yosys_tar", | ||
| # Same label as orfs.default(yosys_plugins = ...) in MODULE.bazel, so | ||
| # SYNTH_HDL_FRONTEND=slang works identically in the classic flow. | ||
| plugins = ["@yosys-slang//src/yosys_plugin:slang.so"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| exports_files(glob(["*.patch"])) | ||
| exports_files(glob(["*.patch"]) + ["install.sh"]) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,10 +27,40 @@ _versionCompare() { | |||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| _installORDependencies() { | ||||||||||||||||||||||||||||||||
| if [[ ${YOSYS_VER} == "" ]]; then | ||||||||||||||||||||||||||||||||
| YOSYS_VER=v$(grep 'yosys_ver =' tools/yosys/docs/source/conf.py | awk -F'"' '{print $2}') | ||||||||||||||||||||||||||||||||
| # Bootstrap bazelisk; the bazel-packaged yosys below needs it and it | ||||||||||||||||||||||||||||||||
| # is idempotent (-bazel alone is a valid OpenROAD installer call). | ||||||||||||||||||||||||||||||||
| ./tools/OpenROAD/etc/DependencyInstaller.sh -bazel ${PREFIX:+-prefix=${PREFIX}} | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Install the bazel-packaged yosys. Single source of truth: the | ||||||||||||||||||||||||||||||||
| # @yosys pin in bazel-orfs MODULE.bazel (bump via | ||||||||||||||||||||||||||||||||
| # `bazelisk run @bazel-orfs//:bump`). Bazel caches the build, so | ||||||||||||||||||||||||||||||||
| # re-runs are fast: no git clone, no make, and the same hermetic | ||||||||||||||||||||||||||||||||
| # yosys on every OS. | ||||||||||||||||||||||||||||||||
| _installYosysBazel | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Delegate the rest. Pass the version of the yosys installed above | ||||||||||||||||||||||||||||||||
| # so the OpenROAD installer's _install_yosys version check succeeds | ||||||||||||||||||||||||||||||||
| # and its git-clone-and-make build is a no-op; -eqy still installs | ||||||||||||||||||||||||||||||||
| # eqy/sby against the bazel-built yosys. | ||||||||||||||||||||||||||||||||
| local yosys_version | ||||||||||||||||||||||||||||||||
| yosys_version=$("${PREFIX:-/usr/local}/bin/yosys" --version | awk '{print $2}') | ||||||||||||||||||||||||||||||||
| ./tools/OpenROAD/etc/DependencyInstaller.sh ${OR_INSTALLER_ARGS} -yosys-ver="v${yosys_version}" | ||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the newly installed Yosys binary is missing, not executable, or fails to run,
Suggested change
|
||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| _installYosysBazel() { | ||||||||||||||||||||||||||||||||
| local yosys_prefix=${PREFIX:-"/usr/local"} | ||||||||||||||||||||||||||||||||
| local bazelisk="bazelisk" | ||||||||||||||||||||||||||||||||
| if ! command -v bazelisk &> /dev/null; then | ||||||||||||||||||||||||||||||||
| bazelisk="${yosys_prefix}/bin/bazelisk" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| ./tools/OpenROAD/etc/DependencyInstaller.sh ${OR_INSTALLER_ARGS} -yosys-ver="${YOSYS_VER}" | ||||||||||||||||||||||||||||||||
| # --symlink_prefix=/ avoids dropping bazel-* convenience symlinks | ||||||||||||||||||||||||||||||||
| # (root-owned when run under sudo) in the source tree; resolve the | ||||||||||||||||||||||||||||||||
| # tarball via the execution root instead of the symlinks. | ||||||||||||||||||||||||||||||||
| "${bazelisk}" build --symlink_prefix=/ //:yosys_tar | ||||||||||||||||||||||||||||||||
| local tarball | ||||||||||||||||||||||||||||||||
| tarball="$("${bazelisk}" info execution_root)/$("${bazelisk}" cquery --symlink_prefix=/ --output=files //:yosys_tar 2> /dev/null)" | ||||||||||||||||||||||||||||||||
| mkdir -p "${yosys_prefix}" | ||||||||||||||||||||||||||||||||
| tar -xzf "${tarball}" -C "${yosys_prefix}" | ||||||||||||||||||||||||||||||||
|
Comment on lines
+53
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If if ! command -v "${bazelisk}" &> /dev/null; then
echo "ERROR: bazelisk not found in PATH or at ${yosys_prefix}/bin/bazelisk" >&2
exit 1
fi
# --symlink_prefix=/ avoids dropping bazel-* convenience symlinks
# (root-owned when run under sudo) in the source tree; resolve the
# tarball via the execution root instead of the symlinks.
"${bazelisk}" build --symlink_prefix=/ //:yosys_tar
local tarball_relative
tarball_relative="$("${bazelisk}" cquery --symlink_prefix=/ --output=files //:yosys_tar 2> /dev/null)"
if [[ -z "${tarball_relative}" ]]; then
echo "ERROR: Failed to resolve yosys_tar path via bazelisk cquery" >&2
exit 1
fi
local tarball
tarball="$("${bazelisk}" info execution_root)/${tarball_relative}"
if [[ ! -f "${tarball}" ]]; then
echo "ERROR: Yosys tarball not found at ${tarball}" >&2
exit 1
fi
mkdir -p "${yosys_prefix}"
tar -xzf "${tarball}" -C "${yosys_prefix}" |
||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| _installPipCommon() { | ||||||||||||||||||||||||||||||||
|
|
@@ -350,10 +380,6 @@ Usage: $0 [-all|-base|-common] [-<ARGS>] | |||||||||||||||||||||||||||||||
| # sudo or with root access. | ||||||||||||||||||||||||||||||||
| $0 -ci | ||||||||||||||||||||||||||||||||
| # Installs CI tools | ||||||||||||||||||||||||||||||||
| $0 -yosys-ver=VERSION | ||||||||||||||||||||||||||||||||
| # Installs specified version of Yosys. | ||||||||||||||||||||||||||||||||
| # By default, the Yosys version is | ||||||||||||||||||||||||||||||||
| # obtained from tools/yosys/docs/source/conf.py | ||||||||||||||||||||||||||||||||
| $0 -constant-build-dir | ||||||||||||||||||||||||||||||||
| # Use constant build directory, instead of | ||||||||||||||||||||||||||||||||
| # random one. | ||||||||||||||||||||||||||||||||
|
|
@@ -363,7 +389,6 @@ EOF | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # default args | ||||||||||||||||||||||||||||||||
| OR_INSTALLER_ARGS="-eqy" | ||||||||||||||||||||||||||||||||
| YOSYS_VER="" | ||||||||||||||||||||||||||||||||
| # default prefix | ||||||||||||||||||||||||||||||||
| PREFIX="" | ||||||||||||||||||||||||||||||||
| # default option | ||||||||||||||||||||||||||||||||
|
|
@@ -407,9 +432,6 @@ while [ "$#" -gt 0 ]; do | |||||||||||||||||||||||||||||||
| -save-deps-prefixes=*) | ||||||||||||||||||||||||||||||||
| OR_INSTALLER_ARGS="${OR_INSTALLER_ARGS} $1" | ||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||
| -yosys-ver=*) | ||||||||||||||||||||||||||||||||
| YOSYS_VER=${1#*=} | ||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||
| -prefix=*) | ||||||||||||||||||||||||||||||||
| OR_INSTALLER_ARGS="${OR_INSTALLER_ARGS} $1" | ||||||||||||||||||||||||||||||||
| PREFIX=${1#*=} | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
bazelisk cqueryfails or returns an empty/invalid path,TARBALLwill resolve to an invalid path (e.g., just the execution root directory). The script will then proceed to delete the existingYOSYS_INSTALLdirectory and fail with a cryptic error fromtar. Adding defensive checks to verify thatbazeliskis available, the query succeeds, and the tarball exists before deleting the old installation prevents this failure mode.