Skip to content

RFC: install bazel-packaged yosys instead of compiling from scratch - #4325

Closed
oharboe wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
oharboe:yosys-bazel-tarball
Closed

oharboe wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
oharboe:yosys-bazel-tarball

Conversation

@oharboe

@oharboe oharboe commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

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.sh and bazel/install.sh. Instead, package the
hermetic bazel-built yosys (binary + yosys-abc + share tree +
slang.so plugin) as a relocatable PREFIX tarball, //:yosys_tar, and
have the installers build and extract that.

  • patches/bazel-orfs/0001-add-yosys-prefix-tar-packaging.patch — adds a
    yosys_prefix_tar() macro (rules_pkg pkg_tar) to bazel-orfs, vendored
    as a git_override patch. Offered upstream as
    Add 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_tar with the yosys-slang plugin
    (same label as orfs.default(yosys_plugins = ...)), so
    SYNTH_HDL_FRONTEND=slang keeps working.
  • etc/DependencyInstaller.sh — _installORDependencies now bootstraps
    bazelisk (which it installed anyway), builds + extracts //:yosys_tar
    into the prefix, and passes the installed version to the OpenROAD
    installer so its _install_yosys source build becomes a verified
    no-op. The -yosys-ver flag and the tools/yosys/docs/source/conf.py
    version scraping are gone.
  • bazel/install.sh — the hand-rolled yosys make and yosys-slang
    cmake builds are replaced by the same tarball; the
    bison/flex/gawk/cmake host-dependency checks disappear with them.
  • patches/bcr/sed-4.10-glibc-2.43.patch — the BCR sed module (via
    @yosys → abc → readline → ncurses) ships a gnulib that does not
    compile against glibc 2.43; single_version_override pins sed 4.10
    with two small gnulib fixes. The same patching zen, one level deeper:
    works today, dropped when gnulib/BCR catch up.

Why

  • Single source of truth. The yosys version is the @yosys pin in
    bazel-orfs MODULE.bazel (bumped via bazelisk 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.
  • Faster installs. Bazel caches the yosys build; re-running the
    installer is a cache hit instead of a re-clone and full rebuild.
  • Gradual, additive migration. This simplifies maintainers' lives
    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_tar is a lot easier to exercise than a code
    path buried inside DependencyInstaller.sh.
  • A sane patching story. With yosys consumed as a bazel module we
    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 .bazelrc fallback registry for yosys 0.64,
    pending yosys@0.64 bazelbuild/bazel-central-registry#8862, is this same pattern
    already in action.)
  • Toward dropping the yosys submodules. tools/yosys and
    tools/yosys-slang are no longer needed by these paths; removing
    them is deliberately left for a follow-up.

Tarball layout

bin/yosys
bin/yosys-abc
share/yosys/...
share/yosys/plugins/slang.so

Yosys resolves share as <bindir>/../share/yosys/ and abc as
<bindir>/yosys-abc, and the bazel build links readline/tcl/zlib/ffi/abc
statically — 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's srcs = ["bazel/install.sh"] label is invalid
    — bazel/BUILD makes bazel/ its own package, which silently broke
    every root-package target. Fixed with a cross-package label +
    exports_files.
  • rules_pycross's toolchain computation fails on Python 3.8 (registered
    transitively via or-tools → pybind11_abseil, dropped from
    rules_python 2.0.0's MINOR_MAPPING). The workaround already in
    tools/OpenROAD/MODULE.bazel is root-honored only, so it is repeated
    in the ORFS MODULE.bazel.

Known gaps / discussion points

  • The tarball does not ship the make install extras yosys-config,
    yosys-smtbmc, yosys-witness, yosys-filterlib. sby's smtbmc
    engines and out-of-tree plugin builds against the installed yosys
    would need them; extending the macro is a follow-up if required.
  • eqy/sby keep their existing source builds (pure-Python YosysHQ tools,
    no bazel modules yet); they build against the bazel-installed yosys.
  • The bazel path needs network access to BCR/registries; there is no
    -nocert equivalent plumbed through yet.
  • Deleting _install_yosys from the OpenROAD installer is a separate
    OpenROAD PR once nothing exercises it.

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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread bazel/install.sh
Comment on lines +67 to +71
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}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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}"

Comment on lines +53 to +63
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}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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}"

Comment on lines +45 to +47
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}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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}"

@oharboe

oharboe commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

@gadfort @vvbandeira @maliberty I had the idea that we could use bazel to build yosys + slang rather than DependencyInstaller.sh

@oharboe oharboe closed this Jul 2, 2026
@maliberty

Copy link
Copy Markdown
Member

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.

@oharboe

oharboe commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants