Repository navigation
Conversation
Package the hermetic bazel-built yosys (binary, yosys-abc, share tree, yosys-slang plugin) as a relocatable PREFIX tarball, //:yosys_tar, via a bazel-orfs yosys_prefix_tar() macro vendored as a git_override patch (offered upstream separately). DependencyInstaller.sh bootstraps bazelisk, builds the tarball and extracts it into the prefix; the OpenROAD installer's git-clone-and-make yosys build becomes a verified no-op via the -yosys-ver version handshake. bazel/install.sh drops its hand-rolled yosys make + yosys-slang cmake builds for the same tarball. Single source of truth: the @YOSYS pin in bazel-orfs MODULE.bazel (bump via 'bazelisk run @bazel-orfs//:bump'). Same hermetic binary on every OS, no version scraping from the tools/yosys submodule, faster re-installs because bazel caches the build. Also fixes two latent issues any root-package target would hit: //:install_for_bazel's invalid cross-package label (bazel/ is its own package) and the rules_pycross Python 3.8 toolchain failure (root-only workaround mirrored from tools/OpenROAD/MODULE.bazel). Carries a small gnulib patch for the BCR sed module on glibc 2.43. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
There was a problem hiding this comment.
Code Review
This pull request refactors the installation process to use a hermetic, bazel-packaged Yosys tarball (//:yosys_tar) instead of building Yosys and its plugins from submodules. This simplifies dependencies and speeds up installation in both bazel/install.sh and etc/DependencyInstaller.sh. The feedback recommends adding defensive checks to ensure bazelisk is available, the query for the tarball path succeeds, and the newly installed Yosys binary is executable and returns a valid version, preventing cryptic failures during installation.
| bazelisk build //:yosys_tar | ||
| TARBALL="$(bazelisk info execution_root)/$(bazelisk cquery --output=files //:yosys_tar 2>/dev/null)" | ||
| rm -rf "${YOSYS_INSTALL}" | ||
| mkdir -p "${YOSYS_INSTALL}" | ||
| tar -xzf "${TARBALL}" -C "${YOSYS_INSTALL}" |
There was a problem hiding this comment.
If bazelisk cquery fails or returns an empty/invalid path, TARBALL will resolve to an invalid path (e.g., just the execution root directory). The script will then proceed to delete the existing YOSYS_INSTALL directory and fail with a cryptic error from tar. Adding defensive checks to verify that bazelisk is available, the query succeeds, and the tarball exists before deleting the old installation prevents this failure mode.
| bazelisk build //:yosys_tar | |
| TARBALL="$(bazelisk info execution_root)/$(bazelisk cquery --output=files //:yosys_tar 2>/dev/null)" | |
| rm -rf "${YOSYS_INSTALL}" | |
| mkdir -p "${YOSYS_INSTALL}" | |
| tar -xzf "${TARBALL}" -C "${YOSYS_INSTALL}" | |
| if ! command -v bazelisk &> /dev/null; then | |
| echo "ERROR: bazelisk not found in PATH" >&2 | |
| exit 1 | |
| fi | |
| bazelisk build //:yosys_tar | |
| TARBALL_RELATIVE="$(bazelisk cquery --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 | |
| TARBALL="$(bazelisk info execution_root)/${TARBALL_RELATIVE}" | |
| if [[ ! -f "${TARBALL}" ]]; then | |
| echo "ERROR: Yosys tarball not found at ${TARBALL}" >&2 | |
| exit 1 | |
| fi | |
| rm -rf "${YOSYS_INSTALL}" | |
| mkdir -p "${YOSYS_INSTALL}" | |
| tar -xzf "${TARBALL}" -C "${YOSYS_INSTALL}" |
| 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}" |
There was a problem hiding this comment.
If bazelisk cquery fails or returns an empty path, tarball will resolve to the execution root directory itself, causing tar to fail. Adding defensive checks to verify that bazelisk is available, the query succeeds, and the tarball exists before running tar ensures robust error handling.
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}"| 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}" |
There was a problem hiding this comment.
If the newly installed Yosys binary is missing, not executable, or fails to run, yosys_version will be empty, causing the script to pass -yosys-ver="v" to the OpenROAD installer. Adding defensive checks to verify that the binary exists and successfully returns a version ensures the script fails early with a clear error message.
| 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}" | |
| local yosys_bin="${PREFIX:-/usr/local}/bin/yosys" | |
| if [[ ! -x "${yosys_bin}" ]]; then | |
| echo "ERROR: Yosys binary not found or not executable at ${yosys_bin}" >&2 | |
| exit 1 | |
| fi | |
| local yosys_version | |
| yosys_version=$("${yosys_bin}" --version | awk '{print $2}') | |
| if [[ -z "${yosys_version}" ]]; then | |
| echo "ERROR: Failed to detect Yosys version from ${yosys_bin}" >&2 | |
| exit 1 | |
| fi | |
| ./tools/OpenROAD/etc/DependencyInstaller.sh ${OR_INSTALLER_ARGS} -yosys-ver="v${yosys_version}" |
|
@gadfort @vvbandeira @maliberty I had the idea that we could use bazel to build yosys + slang rather than DependencyInstaller.sh |
|
There is another use case where we compile yosys with Verific for closed use. We would also have to figure out how to handle that and avoid caching Verific. Interesting but not high priority to me. |
|
As usual: there needs to be some immediate problem where the choice is to invest into a dying infrastructure or make the investment to switch... |
Concept PR for comments — not intended to merge as-is.
What
Stop compiling yosys from scratch with ad-hoc git-clone-and-make code in
DependencyInstaller.shandbazel/install.sh. Instead, package thehermetic bazel-built yosys (binary +
yosys-abc+ share tree +slang.soplugin) as a relocatable PREFIX tarball,//:yosys_tar, andhave the installers build and extract that.
patches/bazel-orfs/0001-add-yosys-prefix-tar-packaging.patch— adds ayosys_prefix_tar()macro (rules_pkgpkg_tar) to bazel-orfs, vendoredas a
git_overridepatch. Offered upstream asAdd yosys_prefix_tar packaging macro and :yosys_tar target bazel-orfs#752; this PR works
identically whether that lands, stalls, or is closed — when it lands we
drop the patch and bump
BAZEL_ORFS_COMMIT.BUILD.bazel— instantiates//:yosys_tarwith the yosys-slang plugin(same label as
orfs.default(yosys_plugins = ...)), soSYNTH_HDL_FRONTEND=slangkeeps working.etc/DependencyInstaller.sh—_installORDependenciesnow bootstrapsbazelisk (which it installed anyway), builds + extracts
//:yosys_tarinto the prefix, and passes the installed version to the OpenROAD
installer so its
_install_yosyssource build becomes a verifiedno-op. The
-yosys-verflag and thetools/yosys/docs/source/conf.pyversion scraping are gone.
bazel/install.sh— the hand-rolled yosysmakeand yosys-slangcmakebuilds are replaced by the same tarball; thebison/flex/gawk/cmake host-dependency checks disappear with them.
patches/bcr/sed-4.10-glibc-2.43.patch— the BCRsedmodule (via@yosys → abc → readline → ncurses) ships a gnulib that does notcompile against glibc 2.43;
single_version_overridepins sed 4.10with two small gnulib fixes. The same patching zen, one level deeper:
works today, dropped when gnulib/BCR catch up.
Why
@yosyspin inbazel-orfs
MODULE.bazel(bumped viabazelisk run @bazel-orfs//:bump),identical for the bazel flow and the classic make flow. No more
version scraping, no more OS-specific compile paths in
DependencyInstaller.sh— the same hermetic binary on every OS,including macOS.
installer is a cache hit instead of a re-clone and full rebuild.
before the switch to bazel is complete: the old bash scripts shrink
instead of growing, and each piece is testable in isolation —
bazelisk build //:yosys_taris a lot easier to exercise than a codepath buried inside
DependencyInstaller.sh.can carry patches for yosys (or any other tool) while waiting for
upstream fixes to land — backports from the next release, macOS
fixes, etc. — with Claude handling the mechanical patch maintenance.
The zen of it: every patch is offered upstream as a GitHub PR, and
the vendored copy keeps working regardless of the upstream PR's fate.
The amount of patching stays roughly constant over time and will
never be zero — ORFS/OpenROAD's bleeding edge will always be on the
bleeding edge. (The
.bazelrcfallback registry for yosys 0.64,pending yosys@0.64 bazelbuild/bazel-central-registry#8862, is this same pattern
already in action.)
tools/yosysandtools/yosys-slangare no longer needed by these paths; removingthem is deliberately left for a follow-up.
Tarball layout
Yosys resolves share as
<bindir>/../share/yosys/and abc as<bindir>/yosys-abc, and the bazel build links readline/tcl/zlib/ffi/abcstatically — the tarball extracts into any prefix unmodified.
Latent master issues this surfaced (fixed here)
Nothing built root-package or pkg_tar targets from the ORFS root before,
so two pre-existing breakages were invisible:
//:install_for_bazel'ssrcs = ["bazel/install.sh"]label is invalid—
bazel/BUILDmakesbazel/its own package, which silently brokeevery root-package target. Fixed with a cross-package label +
exports_files.transitively via or-tools → pybind11_abseil, dropped from
rules_python 2.0.0's
MINOR_MAPPING). The workaround already intools/OpenROAD/MODULE.bazelis root-honored only, so it is repeatedin the ORFS
MODULE.bazel.Known gaps / discussion points
make installextrasyosys-config,yosys-smtbmc,yosys-witness,yosys-filterlib. sby's smtbmcengines and out-of-tree plugin builds against the installed yosys
would need them; extending the macro is a follow-up if required.
no bazel modules yet); they build against the bazel-installed yosys.
-nocertequivalent plumbed through yet._install_yosysfrom the OpenROAD installer is a separateOpenROAD PR once nothing exercises it.