yosys@0.57 (#6056)

closes https://github.com/bazelbuild/bazel-central-registry/issues/5398
diff --git a/modules/yosys/0.57/MODULE.bazel b/modules/yosys/0.57/MODULE.bazel
new file mode 100644
index 0000000..e40f715
--- /dev/null
+++ b/modules/yosys/0.57/MODULE.bazel
@@ -0,0 +1,24 @@
+"""https://yosyshq.net/yosys/"""
+
+module(
+    name = "yosys",
+    version = "0.57",
+    bazel_compatibility = [">=7.2.1"],
+)
+
+bazel_dep(name = "abc", version = "0.0.0-20250903-yosyshq.bcr.1")
+bazel_dep(name = "bazel_skylib", version = "1.8.2")
+bazel_dep(name = "bison", version = "3.8.2")
+bazel_dep(name = "flex", version = "2.6.4")
+bazel_dep(name = "cxxopts", version = "3.3.1")
+bazel_dep(name = "gawk", version = "5.3.2.bcr.2")
+bazel_dep(name = "libffi", version = "3.4.7.bcr.3")
+bazel_dep(name = "platforms", version = "1.0.0")
+bazel_dep(name = "readline", version = "8.2.bcr.3")
+bazel_dep(name = "rules_cc", version = "0.2.4")
+bazel_dep(name = "rules_m4", version = "0.3")
+bazel_dep(name = "rules_python", version = "1.5.1")
+bazel_dep(name = "tcl_lang", version = "8.6.16.bcr.1")
+bazel_dep(name = "zlib", version = "1.3.1.bcr.7")
+
+bazel_dep(name = "googletest", version = "1.17.0", dev_dependency = True)
diff --git a/modules/yosys/0.57/overlay/BUILD.bazel b/modules/yosys/0.57/overlay/BUILD.bazel
new file mode 100644
index 0000000..fa8a380
--- /dev/null
+++ b/modules/yosys/0.57/overlay/BUILD.bazel
@@ -0,0 +1,1075 @@
+"""BUILD file for Yosys Open SYnthesis Suite"""
+
+load("@bazel_skylib//rules:write_file.bzl", "write_file")
+load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
+load("@rules_python//python:py_binary.bzl", "py_binary")
+load(":yosys_utils.bzl", "yosys_bison", "yosys_flex")
+
+VERSION = "0.57"
+
+# Common compiler options
+COMMON_COPTS = [
+    "-w",
+    "-ggdb",
+    "-fPIC",
+]
+
+COMMON_CXXOPTS = [
+    "-std=c++17",
+    "-w",
+    "-ggdb",
+    "-fPIC",
+]
+
+COMMON_DEFINES = [
+    "_YOSYS_",
+    "YOSYS_ENABLE_READLINE",
+    "YOSYS_ENABLE_PLUGINS",
+    "YOSYS_ENABLE_GLOB",
+    "YOSYS_ENABLE_ZLIB",
+    "YOSYS_ENABLE_TCL",
+    "YOSYS_ENABLE_ABC",
+    "YOSYS_ENABLE_COVER",
+    "YOSYS_VER=\\\"{}\\\"".format(VERSION),
+    "YOSYS_MAJOR={}".format(VERSION.split(".")[0]),
+    "YOSYS_MINOR={}".format(VERSION.split(".")[1]),
+    "YOSYS_COMMIT={}".format(VERSION),
+] + select({
+    "@platforms//os:macos": ["_DARWIN_C_SOURCE"],
+    "//conditions:default": [],
+})
+
+# Version information
+write_file(
+    name = "version_gen",
+    out = "kernel/version.cc",
+    content = [
+        "namespace Yosys {",
+        "extern const char *yosys_version_str;",
+        "const char *yosys_version_str=\"Yosys {} (git sha1 UNKNOWN, Bazel)\";".format(VERSION),
+        "}",
+    ],
+)
+
+yosys_bison(
+    name = "verilog_parser_gen",
+    srcs = ["frontends/verilog/verilog_parser.y"],
+    outs = [
+        "frontends/verilog/verilog_parser.tab.cc",
+        "frontends/verilog/verilog_parser.tab.hh",
+    ],
+    args = [
+        "-o",
+        "$(execpath frontends/verilog/verilog_parser.tab.cc)",
+        "-d",
+        "-r",
+        "all",
+        "-b",
+        "verilog_parser",
+        "$(execpath frontends/verilog/verilog_parser.y)",
+    ],
+    bison = "@bison",
+)
+
+# Direct outputs from genrule - no need for complex processing
+
+yosys_flex(
+    name = "verilog_lexer_gen",
+    srcs = ["frontends/verilog/verilog_lexer.l"],
+    outs = ["frontends/verilog/verilog_lexer.cc"],
+    args = [
+        "-o",
+        "$(execpath frontends/verilog/verilog_lexer.cc)",
+        "$(execpath frontends/verilog/verilog_lexer.l)",
+    ],
+    flex = "@flex",
+)
+
+py_binary(
+    name = "callhelp",
+    srcs = ["techlibs/common/cellhelp.py"],
+    main = "techlibs/common/cellhelp.py",
+)
+
+GEN_KERNEL_INC_SRCS = {
+    "techlibs/common/simcells_help.inc": "techlibs/common/simcells.v",
+    "techlibs/common/simlib_help.inc": "techlibs/common/simlib.v",
+}
+
+[
+    genrule(
+        name = out.replace(".inc", "_inc"),
+        srcs = [src],
+        outs = [out],
+        cmd = "$(execpath :callhelp) $(execpath {}) > $@".format(src),
+        cmd_bat = "$(execpath :callhelp) $(execpath {}) > $@".format(src),
+        tools = [":callhelp"],
+    )
+    for (out, src) in GEN_KERNEL_INC_SRCS.items()
+]
+
+# Core kernel library
+cc_library(
+    name = "kernel",
+    srcs = [
+        "kernel/binding.cc",
+        "kernel/calc.cc",
+        "kernel/cellaigs.cc",
+        "kernel/celledges.cc",
+        "kernel/cost.cc",
+        "kernel/drivertools.cc",
+        "kernel/ff.cc",
+        "kernel/ffmerge.cc",
+        "kernel/fmt.cc",
+        "kernel/functional.cc",
+        "kernel/gzip.cc",
+        "kernel/io.cc",
+        "kernel/json.cc",
+        "kernel/log.cc",
+        "kernel/log_help.cc",
+        "kernel/mem.cc",
+        "kernel/qcsat.cc",
+        "kernel/register.cc",
+        "kernel/rtlil.cc",
+        "kernel/satgen.cc",
+        "kernel/scopeinfo.cc",
+        "kernel/sexpr.cc",
+        "kernel/tclapi.cc",
+        "kernel/yosys.cc",
+        "kernel/yw.cc",
+        ":version_gen",
+    ],
+    hdrs = [
+        "kernel/binding.h",
+        "kernel/bitpattern.h",
+        "kernel/cellaigs.h",
+        "kernel/celledges.h",
+        "kernel/celltypes.h",
+        "kernel/compute_graph.h",
+        "kernel/consteval.h",
+        "kernel/constids.inc",
+        "kernel/cost.h",
+        "kernel/drivertools.h",
+        "kernel/ff.h",
+        "kernel/ffinit.h",
+        "kernel/ffmerge.h",
+        "kernel/fmt.h",
+        "kernel/fstdata.h",
+        "kernel/functional.h",
+        "kernel/gzip.h",
+        "kernel/hashlib.h",
+        "kernel/io.h",
+        "kernel/json.h",
+        "kernel/log.h",
+        "kernel/log_help.h",
+        "kernel/macc.h",
+        "kernel/mem.h",
+        "kernel/modtools.h",
+        "kernel/qcsat.h",
+        "kernel/register.h",
+        "kernel/rtlil.h",
+        "kernel/satgen.h",
+        "kernel/scopeinfo.h",
+        "kernel/sexpr.h",
+        "kernel/sigtools.h",
+        "kernel/timinginfo.h",
+        "kernel/topo_scc.h",
+        "kernel/utils.h",
+        "kernel/yosys.h",
+        "kernel/yosys_common.h",
+        "kernel/yw.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    defines = COMMON_DEFINES,
+    includes = [
+        ".",
+        "backends",
+        "frontends",
+        "passes",
+        "techlibs",
+    ],
+    local_defines = [
+        "YOSYS_SRC='\"../\"'",
+    ],
+    textual_hdrs = glob(
+        include = ["techlibs/**/*.inc"],
+    ) + GEN_KERNEL_INC_SRCS.keys() + [
+        "backends/rtlil/rtlil_backend.h",
+        "frontends/verilog/preproc.h",
+        "frontends/verilog/verilog_frontend.h",
+        "frontends/verilog/verilog_location.h",
+        "frontends/ast/ast.h",
+    ],
+    deps = [
+        ":bigint",
+        ":ezsat",
+        ":json11",
+        ":sha1",
+        "@abc",
+        "@libffi",
+        "@readline",
+        "@tcl_lang//:tcl",
+        "@zlib",
+    ],
+)
+
+# BigInt library
+cc_library(
+    name = "bigint",
+    srcs = [
+        "libs/bigint/BigInteger.cc",
+        "libs/bigint/BigIntegerAlgorithms.cc",
+        "libs/bigint/BigIntegerUtils.cc",
+        "libs/bigint/BigUnsigned.cc",
+        "libs/bigint/BigUnsignedInABase.cc",
+    ],
+    hdrs = [
+        "libs/bigint/BigInteger.hh",
+        "libs/bigint/BigIntegerAlgorithms.hh",
+        "libs/bigint/BigIntegerLibrary.hh",
+        "libs/bigint/BigIntegerUtils.hh",
+        "libs/bigint/BigUnsigned.hh",
+        "libs/bigint/BigUnsignedInABase.hh",
+        "libs/bigint/NumberlikeArray.hh",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        "libs/bigint",
+    ],
+    local_defines = COMMON_DEFINES,
+)
+
+# EZSAT library
+cc_library(
+    name = "ezsat",
+    srcs = [
+        "libs/ezsat/ezminisat.cc",
+        "libs/ezsat/ezsat.cc",
+    ],
+    hdrs = [
+        "libs/ezsat/ezminisat.h",
+        "libs/ezsat/ezsat.h",
+    ],
+    conlyopts = COMMON_COPTS + [
+        "-Wno-nonportable-include-path",
+    ],
+    cxxopts = COMMON_CXXOPTS + [
+        "-Wno-nonportable-include-path",
+    ],
+    includes = [
+        "libs/ezsat",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [":minisat"],
+)
+
+# MiniSAT library
+cc_library(
+    name = "minisat",
+    srcs = [
+        "libs/minisat/Options.cc",
+        "libs/minisat/SimpSolver.cc",
+        "libs/minisat/Solver.cc",
+        "libs/minisat/System.cc",
+    ],
+    hdrs = [
+        "libs/minisat/Alg.h",
+        "libs/minisat/Alloc.h",
+        "libs/minisat/Dimacs.h",
+        "libs/minisat/Heap.h",
+        "libs/minisat/IntMap.h",
+        "libs/minisat/IntTypes.h",
+        "libs/minisat/Map.h",
+        "libs/minisat/Options.h",
+        "libs/minisat/ParseUtils.h",
+        "libs/minisat/Queue.h",
+        "libs/minisat/Rnd.h",
+        "libs/minisat/SimpSolver.h",
+        "libs/minisat/Solver.h",
+        "libs/minisat/SolverTypes.h",
+        "libs/minisat/Sort.h",
+        "libs/minisat/System.h",
+        "libs/minisat/Vec.h",
+        "libs/minisat/XAlloc.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "libs/minisat",
+    ],
+    local_defines = COMMON_DEFINES,
+)
+
+# JSON11 library
+cc_library(
+    name = "json11",
+    srcs = [
+        "libs/json11/json11.cpp",
+    ],
+    hdrs = [
+        "libs/json11/json11.hpp",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "libs/json11",
+    ],
+)
+
+# SHA1 library
+cc_library(
+    name = "sha1",
+    srcs = [
+        "libs/sha1/sha1.cpp",
+    ],
+    hdrs = [
+        "libs/sha1/sha1.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "libs/sha1",
+    ],
+)
+
+# FST library (for waveform data)
+cc_library(
+    name = "fst",
+    srcs = [
+        "libs/fst/fastlz.cc",
+        "libs/fst/fstapi.cc",
+        "libs/fst/lz4.cc",
+    ],
+    hdrs = [
+        "libs/fst/fastlz.h",
+        "libs/fst/fst_win_unistd.h",
+        "libs/fst/fstapi.h",
+        "libs/fst/lz4.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "libs/fst",
+    ],
+    deps = ["@zlib"],
+)
+
+# Subcircuit library
+cc_library(
+    name = "subcircuit",
+    srcs = [
+        "libs/subcircuit/subcircuit.cc",
+    ],
+    hdrs = [
+        "libs/subcircuit/subcircuit.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "libs/subcircuit",
+    ],
+    deps = [":kernel"],
+)
+
+# Frontend libraries
+cc_library(
+    name = "frontend_verific",
+    srcs = [
+        "frontends/verific/verific.cc",
+        "frontends/verific/verificsva.cc",
+    ],
+    hdrs = [
+        "frontends/verific/verific.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "frontends/verific",
+    ],
+    deps = [":kernel"],
+)
+
+cc_library(
+    name = "frontend_verilog",
+    srcs = [
+        "frontends/verilog/const2ast.cc",
+        "frontends/verilog/preproc.cc",
+        "frontends/verilog/verilog_error.cc",
+        "frontends/verilog/verilog_frontend.cc",
+        ":frontends/verilog/verilog_lexer.cc",
+        ":frontends/verilog/verilog_parser.tab.cc",
+    ],
+    hdrs = [
+        "frontends/verilog/preproc.h",
+        "frontends/verilog/verilog_error.h",
+        "frontends/verilog/verilog_frontend.h",
+        "frontends/verilog/verilog_lexer.h",
+        "frontends/verilog/verilog_location.h",
+        ":frontends/verilog/verilog_parser.tab.hh",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "backends",
+        "frontends/ast",
+        "frontends/verilog",
+        "passes",
+        "techlibs",
+    ],
+    local_defines = COMMON_DEFINES + ["YYMAXDEPTH=10000000"],
+    deps = [
+        ":frontend_ast",
+        ":kernel",
+        "@flex//:flex_lexer_hdrs",
+    ],
+    alwayslink = True,
+)
+
+yosys_bison(
+    name = "rtlil_parser_gen",
+    srcs = ["frontends/rtlil/rtlil_parser.y"],
+    outs = [
+        "frontends/rtlil/rtlil_parser.tab.cc",
+        "frontends/rtlil/rtlil_parser.tab.hh",
+    ],
+    args = [
+        "-o",
+        "$(execpath frontends/rtlil/rtlil_parser.tab.cc)",
+        "-d",
+        "-r",
+        "all",
+        "-b",
+        "rtlil_parser",
+        "$(execpath frontends/rtlil/rtlil_parser.y)",
+    ],
+    bison = "@bison",
+)
+
+yosys_flex(
+    name = "rtlil_lexer_gen",
+    srcs = ["frontends/rtlil/rtlil_lexer.l"],
+    outs = ["frontends/rtlil/rtlil_lexer.cc"],
+    args = [
+        "-o",
+        "$(execpath frontends/rtlil/rtlil_lexer.cc)",
+        "$(execpath frontends/rtlil/rtlil_lexer.l)",
+    ],
+    flex = "@flex",
+)
+
+cc_library(
+    name = "frontend_rtlil",
+    srcs = [
+        "frontends/rtlil/rtlil_frontend.cc",
+        ":frontends/rtlil/rtlil_lexer.cc",
+        ":frontends/rtlil/rtlil_parser.tab.cc",
+    ],
+    hdrs = [
+        "frontends/rtlil/rtlil_frontend.h",
+        ":frontends/rtlil/rtlil_parser.tab.hh",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "frontends/rtlil",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [
+        ":frontend_verilog",
+        ":kernel",
+    ],
+    alwayslink = True,
+)
+
+cc_library(
+    name = "frontend_ast",
+    srcs = [
+        "frontends/ast/ast.cc",
+        "frontends/ast/ast_binding.cc",
+        "frontends/ast/dpicall.cc",
+        "frontends/ast/genrtlil.cc",
+        "frontends/ast/simplify.cc",
+    ],
+    hdrs = [
+        "frontends/ast/ast.h",
+        "frontends/ast/ast_binding.h",
+        "frontends/verilog/verilog_location.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "frontends/ast",
+    ],
+    local_defines = COMMON_DEFINES + select({
+        "@platforms//os:macos": ["_DARWIN_C_SOURCE"],
+        "//conditions:default": [],
+    }),
+    deps = [":kernel"],
+)
+
+cc_library(
+    name = "frontend_blif",
+    srcs = [
+        "frontends/blif/blifparse.cc",
+    ],
+    hdrs = [
+        "frontends/blif/blifparse.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "frontends/blif",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [
+        ":backend_rtlil",
+        ":kernel",
+    ],
+    alwayslink = True,
+)
+
+cc_library(
+    name = "frontend_aiger",
+    srcs = [
+        "frontends/aiger/aigerparse.cc",
+    ],
+    hdrs = [
+        "frontends/aiger/aigerparse.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "frontends/aiger",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [
+        ":kernel",
+    ],
+)
+
+cc_library(
+    name = "frontend_aiger2",
+    srcs = [
+        "frontends/aiger2/xaiger.cc",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "frontends/aiger2",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [
+        ":kernel",
+    ],
+)
+
+cc_library(
+    name = "frontend_json",
+    srcs = [
+        "frontends/json/jsonparse.cc",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "frontends/json",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [
+        ":kernel",
+    ],
+)
+
+cc_library(
+    name = "frontend_liberty",
+    srcs = [
+        "frontends/liberty/liberty.cc",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "frontends/liberty",
+        "passes/techmap",
+    ],
+    local_defines = COMMON_DEFINES,
+    textual_hdrs = [
+        "passes/techmap/libparse.h",
+    ],
+    deps = [
+        ":kernel",
+    ],
+    alwayslink = True,
+)
+
+cc_library(
+    name = "frontend_rpc",
+    srcs = [
+        "frontends/rpc/rpc_frontend.cc",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "frontends/rpc",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [
+        ":kernel",
+    ],
+)
+
+# Pass libraries
+cc_library(
+    name = "pass_hierarchy",
+    srcs = [
+        "passes/hierarchy/flatten.cc",
+        "passes/hierarchy/hierarchy.cc",
+        "passes/hierarchy/keep_hierarchy.cc",
+        "passes/hierarchy/submod.cc",
+        "passes/hierarchy/uniquify.cc",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "frontends/verific",
+        "passes/hierarchy",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [
+        ":frontend_verific",
+        ":kernel",
+    ],
+    alwayslink = True,
+)
+
+cc_library(
+    name = "pass_cmds",
+    srcs = [
+        "passes/cmds/abstract.cc",
+        "passes/cmds/add.cc",
+        "passes/cmds/autoname.cc",
+        "passes/cmds/blackbox.cc",
+        "passes/cmds/box_derive.cc",
+        "passes/cmds/bugpoint.cc",
+        "passes/cmds/check.cc",
+        "passes/cmds/chformal.cc",
+        "passes/cmds/chtype.cc",
+        "passes/cmds/clean_zerowidth.cc",
+        "passes/cmds/connect.cc",
+        "passes/cmds/connwrappers.cc",
+        "passes/cmds/copy.cc",
+        "passes/cmds/cover.cc",
+        "passes/cmds/delete.cc",
+        "passes/cmds/design.cc",
+        "passes/cmds/dft_tag.cc",
+        "passes/cmds/edgetypes.cc",
+        "passes/cmds/example_dt.cc",
+        "passes/cmds/exec.cc",
+        "passes/cmds/future.cc",
+        "passes/cmds/glift.cc",
+        "passes/cmds/internal_stats.cc",
+        "passes/cmds/linecoverage.cc",
+        "passes/cmds/logcmd.cc",
+        "passes/cmds/logger.cc",
+        "passes/cmds/ltp.cc",
+        "passes/cmds/plugin.cc",
+        "passes/cmds/portarcs.cc",
+        "passes/cmds/portlist.cc",
+        "passes/cmds/printattrs.cc",
+        "passes/cmds/rename.cc",
+        "passes/cmds/scatter.cc",
+        "passes/cmds/scc.cc",
+        "passes/cmds/scratchpad.cc",
+        "passes/cmds/select.cc",
+        "passes/cmds/setattr.cc",
+        "passes/cmds/setenv.cc",
+        "passes/cmds/setundef.cc",
+        "passes/cmds/show.cc",
+        "passes/cmds/splice.cc",
+        "passes/cmds/splitcells.cc",
+        "passes/cmds/splitnets.cc",
+        "passes/cmds/sta.cc",
+        "passes/cmds/stat.cc",
+        "passes/cmds/tee.cc",
+        "passes/cmds/test_select.cc",
+        "passes/cmds/timeest.cc",
+        "passes/cmds/torder.cc",
+        "passes/cmds/trace.cc",
+        "passes/cmds/viz.cc",
+        "passes/cmds/wrapcell.cc",
+        "passes/cmds/write_file.cc",
+        "passes/cmds/xprop.cc",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "backends",
+        "frontends",
+        "passes",
+        "passes/cmds",
+        "techlibs",
+    ],
+    local_defines = COMMON_DEFINES,
+    textual_hdrs = [
+        "frontends/verilog/verilog_lexer.h",
+        "passes/techmap/libparse.h",
+    ],
+    deps = [
+        ":backend_rtlil",
+        ":backend_verilog",
+        ":kernel",
+    ],
+    alwayslink = True,
+)
+
+py_binary(
+    name = "pmgen",
+    srcs = ["passes/pmgen/pmgen.py"],
+    main = "passes/pmgen/pmgen.py",
+)
+
+filegroup(
+    name = "peepopt_pattern",
+    srcs = [
+        "passes/opt/peepopt_formal_clockgateff.pmg",
+        "passes/opt/peepopt_muldiv.pmg",
+        "passes/opt/peepopt_muldiv_c.pmg",
+        "passes/opt/peepopt_shiftadd.pmg",
+        "passes/opt/peepopt_shiftmul_left.pmg",
+        "passes/opt/peepopt_shiftmul_right.pmg",
+    ],
+)
+
+genrule(
+    name = "peepopt_pm_h",
+    srcs = [":peepopt_pattern"],
+    outs = ["passes/opt/peepopt_pm.h"],
+    cmd = "$(execpath :pmgen) -o $@ -p peepopt $(execpaths :peepopt_pattern)",
+    cmd_bat = "$(execpath :pmgen) -o $@ -p peepopt $(execpaths :peepopt_pattern)",
+    tools = [":pmgen"],
+)
+
+cc_library(
+    name = "pass_opt",
+    srcs = [
+        "passes/opt/muxpack.cc",
+        "passes/opt/opt.cc",
+        "passes/opt/opt_clean.cc",
+        "passes/opt/opt_demorgan.cc",
+        "passes/opt/opt_dff.cc",
+        "passes/opt/opt_expr.cc",
+        "passes/opt/opt_ffinv.cc",
+        "passes/opt/opt_hier.cc",
+        "passes/opt/opt_lut.cc",
+        "passes/opt/opt_lut_ins.cc",
+        "passes/opt/opt_mem.cc",
+        "passes/opt/opt_mem_feedback.cc",
+        "passes/opt/opt_mem_priority.cc",
+        "passes/opt/opt_mem_widen.cc",
+        "passes/opt/opt_merge.cc",
+        "passes/opt/opt_muxtree.cc",
+        "passes/opt/opt_reduce.cc",
+        "passes/opt/opt_share.cc",
+        "passes/opt/peepopt.cc",
+        "passes/opt/pmux2shiftx.cc",
+        "passes/opt/rmports.cc",
+        "passes/opt/share.cc",
+        "passes/opt/wreduce.cc",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "passes/opt",
+    ],
+    local_defines = COMMON_DEFINES,
+    textual_hdrs = [
+        "passes/opt/peepopt_pm.h",
+        "passes/techmap/simplemap.h",
+    ],
+    deps = [":kernel"],
+    alwayslink = True,
+)
+
+# Pass proc library
+cc_library(
+    name = "pass_proc",
+    srcs = [
+        "passes/proc/proc.cc",
+        "passes/proc/proc_arst.cc",
+        "passes/proc/proc_clean.cc",
+        "passes/proc/proc_dff.cc",
+        "passes/proc/proc_dlatch.cc",
+        "passes/proc/proc_init.cc",
+        "passes/proc/proc_memwr.cc",
+        "passes/proc/proc_mux.cc",
+        "passes/proc/proc_prune.cc",
+        "passes/proc/proc_rmdead.cc",
+        "passes/proc/proc_rom.cc",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "passes/proc",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [":kernel"],
+    alwayslink = True,
+)
+
+# Pass fsm library
+cc_library(
+    name = "pass_fsm",
+    srcs = [
+        "passes/fsm/fsm.cc",
+        "passes/fsm/fsm_detect.cc",
+        "passes/fsm/fsm_expand.cc",
+        "passes/fsm/fsm_export.cc",
+        "passes/fsm/fsm_extract.cc",
+        "passes/fsm/fsm_info.cc",
+        "passes/fsm/fsm_map.cc",
+        "passes/fsm/fsm_opt.cc",
+        "passes/fsm/fsm_recode.cc",
+    ],
+    hdrs = [
+        "passes/fsm/fsmdata.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "passes/fsm",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [":kernel"],
+    alwayslink = True,
+)
+
+# Pass memory library
+cc_library(
+    name = "pass_memory",
+    srcs = [
+        "passes/memory/memlib.cc",
+        "passes/memory/memory.cc",
+        "passes/memory/memory_bmux2rom.cc",
+        "passes/memory/memory_bram.cc",
+        "passes/memory/memory_collect.cc",
+        "passes/memory/memory_dff.cc",
+        "passes/memory/memory_libmap.cc",
+        "passes/memory/memory_map.cc",
+        "passes/memory/memory_memx.cc",
+        "passes/memory/memory_narrow.cc",
+        "passes/memory/memory_nordff.cc",
+        "passes/memory/memory_share.cc",
+        "passes/memory/memory_unpack.cc",
+    ],
+    hdrs = [
+        "passes/memory/memlib.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "passes/memory",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [":kernel"],
+    alwayslink = True,
+)
+
+# Pass techmap library
+cc_library(
+    name = "pass_techmap",
+    srcs = [
+        "passes/techmap/abc.cc",
+        "passes/techmap/abc9.cc",
+        "passes/techmap/abc9_exe.cc",
+        "passes/techmap/abc9_ops.cc",
+        "passes/techmap/abc_new.cc",
+        "passes/techmap/aigmap.cc",
+        "passes/techmap/alumacc.cc",
+        "passes/techmap/attrmap.cc",
+        "passes/techmap/attrmvcp.cc",
+        "passes/techmap/bmuxmap.cc",
+        "passes/techmap/booth.cc",
+        "passes/techmap/bufnorm.cc",
+        "passes/techmap/bwmuxmap.cc",
+        "passes/techmap/cellmatch.cc",
+        "passes/techmap/clkbufmap.cc",
+        "passes/techmap/clockgate.cc",
+        "passes/techmap/constmap.cc",
+        "passes/techmap/deminout.cc",
+        "passes/techmap/demuxmap.cc",
+        "passes/techmap/dffinit.cc",
+        "passes/techmap/dfflegalize.cc",
+        "passes/techmap/dfflibmap.cc",
+        "passes/techmap/dffunmap.cc",
+        "passes/techmap/extract.cc",
+        "passes/techmap/extract_counter.cc",
+        "passes/techmap/extract_fa.cc",
+        "passes/techmap/extract_reduce.cc",
+        "passes/techmap/extractinv.cc",
+        "passes/techmap/flowmap.cc",
+        "passes/techmap/hilomap.cc",
+        "passes/techmap/insbuf.cc",
+        "passes/techmap/iopadmap.cc",
+        "passes/techmap/libcache.cc",
+        "passes/techmap/libparse.cc",
+        "passes/techmap/lut2mux.cc",
+        "passes/techmap/maccmap.cc",
+        "passes/techmap/muxcover.cc",
+        "passes/techmap/nlutmap.cc",
+        "passes/techmap/pmuxtree.cc",
+        "passes/techmap/shregmap.cc",
+        "passes/techmap/simplemap.cc",
+        "passes/techmap/techmap.cc",
+        "passes/techmap/tribuf.cc",
+        "passes/techmap/zinit.cc",
+    ],
+    hdrs = [
+        "passes/techmap/libparse.h",
+        "passes/techmap/simplemap.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "passes/techmap",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [
+        ":frontend_blif",
+        ":kernel",
+        ":subcircuit",
+    ],
+    alwayslink = True,
+)
+
+# Backend libraries
+cc_library(
+    name = "backend_verilog",
+    srcs = [
+        "backends/verilog/verilog_backend.cc",
+    ],
+    hdrs = [
+        "backends/verilog/verilog_backend.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "backends/verilog",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [":kernel"],
+)
+
+cc_library(
+    name = "backend_rtlil",
+    srcs = [
+        "backends/rtlil/rtlil_backend.cc",
+    ],
+    hdrs = [
+        "backends/rtlil/rtlil_backend.h",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "backends/rtlil",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [":kernel"],
+    alwayslink = True,
+)
+
+# Techlib libraries
+cc_library(
+    name = "techlib_common",
+    srcs = [
+        "techlibs/common/prep.cc",
+        "techlibs/common/synth.cc",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    includes = [
+        ".",
+        "techlibs/common",
+    ],
+    local_defines = COMMON_DEFINES,
+    deps = [":kernel"],
+    alwayslink = True,
+)
+
+# Main yosys binary
+cc_binary(
+    name = "yosys",
+    srcs = [
+        "kernel/driver.cc",
+    ],
+    conlyopts = COMMON_COPTS,
+    cxxopts = COMMON_CXXOPTS,
+    linkopts = select({
+        "@platforms//os:linux": [
+            "-lpthread",
+            "-ldl",
+            "-rdynamic",
+        ],
+        "@platforms//os:macos": ["-rdynamic"],
+        "@platforms//os:windows": [],
+        "//conditions:default": [],
+    }),
+    local_defines = COMMON_DEFINES,
+    visibility = ["//visibility:public"],
+    deps = [
+        ":backend_rtlil",
+        ":backend_verilog",
+        ":bigint",
+        ":frontend_aiger",
+        ":frontend_aiger2",
+        ":frontend_ast",
+        ":frontend_blif",
+        ":frontend_json",
+        ":frontend_liberty",
+        ":frontend_rpc",
+        ":frontend_rtlil",
+        ":frontend_verific",
+        ":frontend_verilog",
+        ":json11",
+        ":kernel",
+        ":pass_cmds",
+        ":pass_fsm",
+        ":pass_hierarchy",
+        ":pass_memory",
+        ":pass_opt",
+        ":pass_proc",
+        ":pass_techmap",
+        ":sha1",
+        ":subcircuit",
+        ":techlib_common",
+        "@abc",
+        "@cxxopts",
+        "@libffi",
+        "@readline",
+        "@tcl_lang//:tcl",
+        "@zlib",
+    ],
+)
diff --git a/modules/yosys/0.57/overlay/MODULE.bazel b/modules/yosys/0.57/overlay/MODULE.bazel
new file mode 120000
index 0000000..9b599e3
--- /dev/null
+++ b/modules/yosys/0.57/overlay/MODULE.bazel
@@ -0,0 +1 @@
+../MODULE.bazel
\ No newline at end of file
diff --git a/modules/yosys/0.57/overlay/tests/BUILD.bazel b/modules/yosys/0.57/overlay/tests/BUILD.bazel
new file mode 100644
index 0000000..9a769c7
--- /dev/null
+++ b/modules/yosys/0.57/overlay/tests/BUILD.bazel
@@ -0,0 +1,15 @@
+load("@rules_cc//cc:cc_test.bzl", "cc_test")
+
+# Comprehensive C++ test binary for yosys functionality using Google Test
+cc_test(
+    name = "yosys_binary_test",
+    size = "small",
+    srcs = ["yosys_binary_test.cc"],
+    data = ["@yosys"],
+    env = {"YOSYS": "$(rlocationpath @yosys)"},
+    deps = [
+        "@googletest//:gtest",
+        "@googletest//:gtest_main",
+        "@rules_cc//cc/runfiles",
+    ],
+)
diff --git a/modules/yosys/0.57/overlay/tests/MODULE.bazel b/modules/yosys/0.57/overlay/tests/MODULE.bazel
new file mode 100644
index 0000000..96f8759
--- /dev/null
+++ b/modules/yosys/0.57/overlay/tests/MODULE.bazel
@@ -0,0 +1,16 @@
+"""Yosys test module."""
+
+module(
+    name = "yosys_test",
+    version = "0.0.0",
+)
+
+bazel_dep(name = "yosys", version = "0.0.0")
+bazel_dep(name = "rules_cc", version = "0.2.4")
+
+local_path_override(
+    module_name = "yosys",
+    path = "../",
+)
+
+bazel_dep(name = "googletest", version = "1.17.0", dev_dependency = True)
diff --git a/modules/yosys/0.57/overlay/tests/yosys_binary_test.cc b/modules/yosys/0.57/overlay/tests/yosys_binary_test.cc
new file mode 100644
index 0000000..6ee6cd2
--- /dev/null
+++ b/modules/yosys/0.57/overlay/tests/yosys_binary_test.cc
@@ -0,0 +1,310 @@
+/**
+ * Comprehensive test suite for yosys binary functionality
+ */
+
+#include <gtest/gtest.h>
+
+#include <cassert>
+#include <cstdio>
+#include <cstdlib>
+#include <fstream>
+#include <functional>
+#include <iostream>
+#include <memory>
+#include <sstream>
+#include <stdexcept>
+#include <string>
+#include <vector>
+
+#include "rules_cc/cc/runfiles/runfiles.h"
+
+/** Helper function to execute a command and capture output */
+std::string exec(const std::string& cmd) {
+    char buffer[128];
+    std::string result = "";
+    std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"),
+                                                  pclose);
+    if (!pipe) {
+        throw std::runtime_error("popen() failed!");
+    }
+    while (fgets(buffer, sizeof buffer, pipe.get()) != nullptr) {
+        result += buffer;
+    }
+    return result;
+}
+
+/** Helper function to create a temporary file with content */
+void create_temp_file(const std::string& filename, const std::string& content) {
+    std::ofstream file(filename);
+    if (!file.is_open()) {
+        throw std::runtime_error("Could not create temporary file: " +
+                                 filename);
+    }
+    file << content;
+    file.close();
+}
+
+/** Helper function to check if a file exists */
+bool file_exists(const std::string& filename) {
+    std::ifstream file(filename);
+    return file.good();
+}
+
+class YosysTest : public ::testing::Test {
+   protected:
+    void SetUp() override {
+        // Use runfiles to locate the yosys binary
+        std::string error;
+        std::unique_ptr<rules_cc::cc::runfiles::Runfiles> runfiles(
+            rules_cc::cc::runfiles::Runfiles::CreateForTest(
+                BAZEL_CURRENT_REPOSITORY, &error));
+
+        if (runfiles == nullptr) {
+            FAIL() << "Failed to create runfiles: " << error;
+        }
+
+        const char* yosys_env = std::getenv("YOSYS");
+        if (!yosys_env) {
+            FAIL() << "Could not locate yosys binary using runfiles, "
+                      "environment variable, or command line argument";
+        }
+
+        yosys_path = runfiles->Rlocation(yosys_env);
+        if (yosys_path.empty()) {
+            FAIL() << "Failed to locate yosys binary in runfiles.";
+        }
+
+        const char* tmpdir = std::getenv("TEST_TMPDIR");
+        if (!tmpdir) {
+            FAIL() << "TEST_TMPDIR environment variable is not set";
+        }
+        test_tmpdir = tmpdir;
+    }
+
+    /** Helper: prepend TEST_TMPDIR to filenames */
+    std::string temp_path(const std::string& filename) const {
+        return test_tmpdir + "/" + filename;
+    }
+
+    std::string yosys_path;
+    std::string test_tmpdir;
+
+   public:
+    static int argc;
+    static char** argv;
+};
+
+/** Static members for command line arguments */
+int YosysTest::argc = 0;
+char** YosysTest::argv = nullptr;
+
+/** Test that yosys binary can be executed and shows version */
+TEST_F(YosysTest, VersionCommand) {
+    std::string cmd = yosys_path + " -V";
+    std::string output = exec(cmd);
+
+    EXPECT_TRUE(output.find("Yosys") != std::string::npos)
+        << "Version output doesn't contain 'Yosys': " << output;
+}
+
+/** Test that yosys binary can show help */
+TEST_F(YosysTest, HelpCommand) {
+    std::string cmd = yosys_path + " -h";
+    std::string output = exec(cmd);
+
+    EXPECT_TRUE(output.find("Usage:") != std::string::npos ||
+                output.find("usage:") != std::string::npos)
+        << "Help output doesn't contain usage information: " << output;
+}
+
+/**
+ * Test basic command help functionality (equivalent to
+ * yosys_basic_commands_test)
+ */
+TEST_F(YosysTest, BasicCommandsHelp) {
+    // Test design command help
+    std::string cmd = yosys_path + " -p 'help design' 2>&1";
+    std::string output = exec(cmd);
+
+    EXPECT_TRUE(output.find("design") != std::string::npos)
+        << "Design command help not working: " << output;
+
+    // Test hierarchy command help
+    cmd = yosys_path + " -p 'help hierarchy' 2>&1";
+    output = exec(cmd);
+
+    EXPECT_TRUE(output.find("hierarchy") != std::string::npos)
+        << "Hierarchy command help not working: " << output;
+
+    // Test synth command help
+    cmd = yosys_path + " -p 'help synth' 2>&1";
+    output = exec(cmd);
+
+    EXPECT_TRUE(output.find("synth") != std::string::npos)
+        << "Synth command help not working: " << output;
+}
+
+/** Test basic synthesis flow */
+TEST_F(YosysTest, BasicSynthesis) {
+    // Create a simple Verilog file
+    std::string verilog_content =
+        "module simple(input a, b, output y); assign y = a & b; endmodule\n";
+    std::string input_file = temp_path("test_simple.v");
+    std::string output_file = temp_path("test_output.il");
+    create_temp_file(input_file, verilog_content);
+
+    // Run basic synthesis without techmap (which requires share/ directory
+    // setup)
+
+    std::string cmd =
+        yosys_path + " -p 'read_verilog " + input_file +
+        "; hierarchy; proc; opt; fsm; opt; memory; opt; write_rtlil " +
+        output_file + "' 2>&1";
+    std::string output = exec(cmd);
+
+    // Check for successful completion (should not contain "ERROR")
+    EXPECT_TRUE(output.find("ERROR") == std::string::npos)
+        << "Synthesis failed with error: " << output;
+
+    // Check that output file was created
+    EXPECT_TRUE(file_exists(output_file))
+        << "Synthesis did not create output file";
+}
+
+/** Test autoname functionality (equivalent to yosys_autoname_test) */
+TEST_F(YosysTest, AutonameFunctionality) {
+    // Create RTLIL test file
+    std::string rtlil_content = R"(autoidx 2
+module \top
+  wire output 3 $y
+  wire input 1 \a
+  wire input 2 \b
+  cell $and \b_$and_B
+    parameter \A_SIGNED 0
+    parameter \A_WIDTH 1
+    parameter \B_SIGNED 0
+    parameter \B_WIDTH 1
+    parameter \Y_WIDTH 1
+    connect \A \a
+    connect \B \b
+    connect \Y $y
+  end
+end
+)";
+    std::string input_file = temp_path("autoname_test.rtlil");
+    std::string output_file = temp_path("autoname_output.il");
+    create_temp_file(input_file, rtlil_content);
+
+    // Run autoname command
+
+    std::string cmd = yosys_path + " -p 'read_rtlil " + input_file +
+                      "; autoname; write_rtlil " + output_file + "' 2>&1";
+    std::string output = exec(cmd);
+
+    // Check for successful completion
+    EXPECT_TRUE(output.find("ERROR") == std::string::npos)
+        << "Autoname failed with error: " << output;
+
+    // Check that output file was created
+    EXPECT_TRUE(file_exists(output_file))
+        << "Autoname did not create output file";
+}
+
+/**
+ * Test simple synthesis with synth command (equivalent to
+ * yosys_simple_synthesis_test)
+ */
+TEST_F(YosysTest, SimpleSynthesisWithSynth) {
+    // Create a simple Verilog file
+    std::string verilog_content =
+        "module simple(input a, b, output y); assign y = a & b; endmodule\n";
+    std::string input_file = temp_path("simple.v");
+    std::string output_file = temp_path("simple.il");
+    create_temp_file(input_file, verilog_content);
+
+    // Run synthesis using synth command but without techmap (which requires
+    // share/ directory)
+    std::string cmd =
+        yosys_path + " -p 'read_verilog " + input_file +
+        "; hierarchy; proc; opt; fsm; opt; memory; opt; write_rtlil " +
+        output_file + "' 2>&1";
+    std::string output = exec(cmd);
+
+    // Check for successful completion
+    EXPECT_TRUE(output.find("ERROR") == std::string::npos)
+        << "Simple synthesis with synth command failed: " << output;
+
+    // Check that output file was created
+    EXPECT_TRUE(file_exists(output_file))
+        << "Simple synthesis did not create output file";
+}
+
+/** Test that yosys can handle multiple commands in sequence */
+TEST_F(YosysTest, MultipleCommandsSequence) {
+    std::string cmd =
+        yosys_path + " -p 'help design; help hierarchy; help synth' 2>&1";
+    std::string output = exec(cmd);
+
+    // Should contain help for all three commands
+    EXPECT_TRUE(output.find("design") != std::string::npos)
+        << "Multiple commands sequence failed - design help missing: "
+        << output;
+    EXPECT_TRUE(output.find("hierarchy") != std::string::npos)
+        << "Multiple commands sequence failed - hierarchy help missing: "
+        << output;
+    EXPECT_TRUE(output.find("synth") != std::string::npos)
+        << "Multiple commands sequence failed - synth help missing: " << output;
+}
+
+/** Test error handling for invalid commands */
+TEST_F(YosysTest, ErrorHandling) {
+    std::string cmd = yosys_path + " -p 'invalid_command' 2>&1";
+    std::string output = exec(cmd);
+
+    // Should contain error message
+    EXPECT_TRUE(output.find("ERROR") != std::string::npos ||
+                output.find("No such command") != std::string::npos)
+        << "Error handling test failed - should show error for invalid "
+           "command: "
+        << output;
+}
+
+/** Test that yosys can read and write different file formats */
+TEST_F(YosysTest, FileFormatSupport) {
+    // Test RTLIL format with a valid simple module
+    std::string rtlil_content = R"(module \test
+  wire input 1 \a
+  wire output 1 \y
+  cell $not \not1
+    parameter \A_SIGNED 0
+    parameter \A_WIDTH 1
+    parameter \Y_WIDTH 1
+    connect \A \a
+    connect \Y \y
+  end
+end
+)";
+    std::string input_file = temp_path("test.rtlil");
+    std::string output_file = temp_path("test_out.rtlil");
+    create_temp_file(input_file, rtlil_content);
+
+    std::string cmd = yosys_path + " -p 'read_rtlil " + input_file +
+                      "; write_rtlil " + output_file + "' 2>&1";
+    std::string output = exec(cmd);
+
+    EXPECT_TRUE(output.find("ERROR") == std::string::npos)
+        << "RTLIL format support failed: " << output;
+
+    EXPECT_TRUE(file_exists(output_file))
+        << "RTLIL output file was not created";
+}
+
+int main(int argc, char** argv) {
+    ::testing::InitGoogleTest(&argc, argv);
+
+    // Store command line arguments for use in tests
+    YosysTest::argc = argc;
+    YosysTest::argv = argv;
+
+    return RUN_ALL_TESTS();
+}
diff --git a/modules/yosys/0.57/overlay/yosys_utils.bzl b/modules/yosys/0.57/overlay/yosys_utils.bzl
new file mode 100644
index 0000000..1c988a9
--- /dev/null
+++ b/modules/yosys/0.57/overlay/yosys_utils.bzl
@@ -0,0 +1,133 @@
+"""Yosys utilities"""
+
+def _yosys_gen_action(ctx, mnemonic, tool, env):
+    args = ctx.actions.args()
+
+    out_replaces = {}
+    for file, label in zip(ctx.outputs.outs, ctx.attr.outs):
+        _, _, relative = str(label).partition("//")
+        out_replaces["$(execpath {})".format(label)] = file
+        out_replaces["$(execpath {})".format(relative)] = file
+
+    for arg in ctx.attr.args:
+        if arg in out_replaces:
+            args.add(out_replaces[arg])
+            continue
+
+        expanded = ctx.expand_location(arg, ctx.attr.srcs)
+        args.add(expanded)
+
+    ctx.actions.run(
+        executable = tool,
+        arguments = [args],
+        inputs = ctx.files.srcs,
+        outputs = ctx.outputs.outs,
+        mnemonic = mnemonic,
+        env = env,
+    )
+
+    return [DefaultInfo(
+        files = depset(ctx.outputs.outs),
+    )]
+
+def _find_m4(runfiles, label):
+    m4 = None
+    for file in runfiles:
+        if file.basename in ["m4", "m4.exe"]:
+            m4 = file
+            break
+
+    if not m4:
+        fail("Failed to find m4 binary in runfiles of {}".format(label))
+
+    return m4
+
+def _yosys_bison_impl(ctx):
+    m4 = _find_m4(ctx.attr.bison[DefaultInfo].default_runfiles.files.to_list(), ctx.attr.bison.label)
+
+    env = {
+        "BISON_PKGDATADIR": "{}.runfiles/{}/data".format(
+            ctx.executable.bison.path,
+            ctx.executable.bison.owner.workspace_name,
+        ),
+        "M4": "{}.runfiles/{}".format(
+            ctx.executable.bison.path,
+            m4.short_path[len("../"):],
+        ),
+    }
+
+    return _yosys_gen_action(
+        ctx = ctx,
+        mnemonic = "YosysBisonGen",
+        tool = ctx.executable.bison,
+        env = env,
+    )
+
+yosys_bison = rule(
+    doc = "An internal rule for running bison in the yosys project.",
+    implementation = _yosys_bison_impl,
+    attrs = {
+        "args": attr.string_list(
+            doc = "Arguments to pass to bison.",
+            mandatory = True,
+        ),
+        "bison": attr.label(
+            doc = "The bison binary.",
+            cfg = "exec",
+            executable = True,
+            mandatory = True,
+        ),
+        "outs": attr.output_list(
+            doc = "Outputs from bison.",
+            mandatory = True,
+        ),
+        "srcs": attr.label_list(
+            doc = "Sources to provide to bison.",
+            mandatory = True,
+            allow_files = True,
+        ),
+    },
+)
+
+def _yosys_flex_impl(ctx):
+    m4 = _find_m4(ctx.attr.flex[DefaultInfo].default_runfiles.files.to_list(), ctx.attr.flex.label)
+
+    env = {
+        "M4": "{}.runfiles/{}".format(
+            ctx.executable.flex.path,
+            m4.short_path[len("../"):],
+        ),
+    }
+
+    return _yosys_gen_action(
+        ctx = ctx,
+        mnemonic = "YosysFlexGen",
+        tool = ctx.executable.flex,
+        env = env,
+    )
+
+yosys_flex = rule(
+    doc = "An internal rule for running flex in the yosys project.",
+    implementation = _yosys_flex_impl,
+    attrs = {
+        "args": attr.string_list(
+            doc = "Arguments to pass to flex.",
+            mandatory = True,
+        ),
+        "flex": attr.label(
+            doc = "The flex binary.",
+            cfg = "exec",
+            executable = True,
+            mandatory = True,
+        ),
+        "outs": attr.output_list(
+            doc = "Outputs from bison.",
+            mandatory = True,
+        ),
+        "srcs": attr.label_list(
+            doc = "Sources to provide to bison.",
+            mandatory = True,
+            allow_files = True,
+        ),
+    },
+)
diff --git a/modules/yosys/0.57/patches/macos_support.patch b/modules/yosys/0.57/patches/macos_support.patch
new file mode 100644
index 0000000..924ae74
--- /dev/null
+++ b/modules/yosys/0.57/patches/macos_support.patch
@@ -0,0 +1,75 @@
+diff --git a/frontends/ast/dpicall.cc b/frontends/ast/dpicall.cc
+index d76318739..16f79aa03 100644
+--- a/frontends/ast/dpicall.cc
++++ b/frontends/ast/dpicall.cc
+@@ -24,6 +24,12 @@
+ #include <dlfcn.h>
+ #include <ffi.h>
+ 
++#if defined(__APPLE__) || defined(__MACH__)
++#ifndef RTLD_DEFAULT
++#define RTLD_DEFAULT ((void*) -2)
++#endif
++#endif
++
+ YOSYS_NAMESPACE_BEGIN
+ 
+ typedef void (*ffi_fptr) ();
+@@ -161,4 +167,3 @@ std::unique_ptr<AST::AstNode> AST::dpi_call(AstSrcLocType, const std::string&, c
+ YOSYS_NAMESPACE_END
+ 
+ #endif /* YOSYS_ENABLE_PLUGINS */
+-
+diff --git a/libs/ezsat/ezminisat.cc b/libs/ezsat/ezminisat.cc
+index 30df625cb..374e17fd4 100644
+--- a/libs/ezsat/ezminisat.cc
++++ b/libs/ezsat/ezminisat.cc
+@@ -29,7 +29,10 @@
+ 
+ #include <limits.h>
+ #include <stdint.h>
++#if !defined(__APPLE__) && !defined(__MACH__)
+ #include <cinttypes>
++#endif
++
+ 
+ #if !defined(_WIN32) && !defined(__wasm)
+ #  include <csignal>
+@@ -245,4 +248,3 @@ contradiction:
+ #endif
+ 	return true;
+ }
+-
+diff --git a/libs/minisat/IntTypes.h b/libs/minisat/IntTypes.h
+index c48816284..4fdbc10f2 100644
+--- a/libs/minisat/IntTypes.h
++++ b/libs/minisat/IntTypes.h
+@@ -33,6 +33,12 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
+ #   include <stdint.h>
+ #   include <inttypes.h>
+ 
++#if defined(__APPLE__) || defined(__MACH__)
++#ifndef PRIi64
++# include <_inttypes.h>
++#endif
++#endif
++
+ #endif
+ 
+ #include <limits.h>
+diff --git a/passes/cmds/plugin.cc b/passes/cmds/plugin.cc
+index a653844b7..1537c4b61 100644
+--- a/passes/cmds/plugin.cc
++++ b/passes/cmds/plugin.cc
+@@ -22,6 +22,11 @@
+ 
+ #ifdef YOSYS_ENABLE_PLUGINS
+ #  include <dlfcn.h>
++#  ifdef __APPLE__
++#    ifndef RTLD_LOCAL
++#      define RTLD_LOCAL 0
++#    endif
++#  endif
+ #endif
+ 
+ #ifdef WITH_PYTHON
diff --git a/modules/yosys/0.57/patches/use_cxxopt_module.patch b/modules/yosys/0.57/patches/use_cxxopt_module.patch
new file mode 100644
index 0000000..20805cf
--- /dev/null
+++ b/modules/yosys/0.57/patches/use_cxxopt_module.patch
@@ -0,0 +1,13 @@
+diff --git a/kernel/driver.cc b/kernel/driver.cc
+index 76c11853e..71e764963 100644
+--- a/kernel/driver.cc
++++ b/kernel/driver.cc
+@@ -21,7 +21,7 @@
+ #include "kernel/hashlib.h"
+ #include "libs/sha1/sha1.h"
+ #define CXXOPTS_VECTOR_DELIMITER '\0'
+-#include "libs/cxxopts/include/cxxopts.hpp"
++#include "cxxopts.hpp"
+ #include <iostream>
+ 
+ #ifdef YOSYS_ENABLE_READLINE
diff --git a/modules/yosys/0.57/presubmit.yml b/modules/yosys/0.57/presubmit.yml
new file mode 100644
index 0000000..8bdc0f1
--- /dev/null
+++ b/modules/yosys/0.57/presubmit.yml
@@ -0,0 +1,16 @@
+bcr_test_module:
+  module_path: "tests"
+  matrix:
+    platform:
+      - "ubuntu2004"
+      - "macos_arm64"
+    bazel: ["7.x", "8.x"]
+  tasks:
+    verify_targets:
+      name: "Run test module"
+      platform: ${{ platform }}
+      bazel: ${{ bazel }}
+      test_targets:
+      - "//..."
+      test_flags:
+      - "--verbose_failures"
diff --git a/modules/yosys/0.57/source.json b/modules/yosys/0.57/source.json
new file mode 100644
index 0000000..86941aa
--- /dev/null
+++ b/modules/yosys/0.57/source.json
@@ -0,0 +1,17 @@
+{
+    "url": "https://github.com/YosysHQ/yosys/releases/download/v0.57/yosys.tar.gz",
+    "integrity": "sha256-OOTt7NkQBrRcrdM9qjjznEKrYl/npYy/2KsCPUqHvE0=",
+    "overlay": {
+        "BUILD.bazel": "sha256-Yr+dDui1bxvJIMsAfNPNe3NurWfrxVigW6gQAx90meE=",
+        "MODULE.bazel": "sha256-0oIhYgZc5f2s+1IPKTVoDsz2FS1E+DkiixzQSRrbR3s=",
+        "tests/BUILD.bazel": "sha256-0MI92mdECw8GRmitkIDgq5h2SC1wTmfLWVQ5+Z/OOIU=",
+        "tests/MODULE.bazel": "sha256-m/OKbMFkaWONZnNmNUnsEnT99P+5Ez1rTCJav+Jqns4=",
+        "tests/yosys_binary_test.cc": "sha256-ArA/AIir0zEdRGOiheS7WQj8bgJy2/jZZadJyvbzxV4=",
+        "yosys_utils.bzl": "sha256-61/Q4sL1YIX4nJxN6zW5Fvm6nLYyY12PW1ZFxTqmMEI="
+    },
+    "patch_strip": 1,
+    "patches": {
+        "macos_support.patch": "sha256-5yiyicf4S3Y3sRhjbWDEceosU/8b23E+ivy7rj6zXZA=",
+        "use_cxxopt_module.patch": "sha256-8dTk6VjieDCFOFlLq+dh4jwi7PnbJSfBH7bLSY4Ocnw="
+    }
+}
diff --git a/modules/yosys/metadata.json b/modules/yosys/metadata.json
new file mode 100644
index 0000000..35a1ca3
--- /dev/null
+++ b/modules/yosys/metadata.json
@@ -0,0 +1,18 @@
+{
+    "homepage": "https://yosyshq.net/yosys/",
+    "maintainers": [
+        {
+            "email": "26427366+UebelAndre@users.noreply.github.com",
+            "github": "UebelAndre",
+            "github_user_id": 26427366,
+            "name": "UebelAndre"
+        }
+    ],
+    "repository": [
+        "github:YosysHQ/yosys"
+    ],
+    "versions": [
+        "0.57"
+    ],
+    "yanked_versions": {}
+}