From b555ef98180e5fcf931c21d272eeb8107ee9db99 Mon Sep 17 00:00:00 2001 From: Will Keen Date: Mon, 29 Sep 2025 17:26:44 +0100 Subject: [PATCH 1/5] verilator/5.036.bcr.1 - add verilated_random.h and verilated_saif.h to srcs to pick up released functionality - patch such that hierarchical verilation invokes the verilator binary built by bazel @bazel-io skip_check unstable_url --- modules/verilator/5.036.bcr.1/MODULE.bazel | 16 + .../5.036.bcr.1/overlay/.bazelignore | 1 + .../verilator/5.036.bcr.1/overlay/BUILD.bazel | 369 ++++++++++++++++++ .../5.036.bcr.1/overlay/MODULE.bazel | 1 + .../5.036.bcr.1/overlay/private/BUILD.bazel | 31 ++ .../overlay/private/verilator_astgen.py | 69 ++++ .../overlay/private/verilator_bisonpre.py | 30 ++ .../private/verilator_build_template.py | 63 +++ .../overlay/private/verilator_flexfix.py | 65 +++ .../overlay/private/verilator_utils.bzl | 313 +++++++++++++++ .../overlay/private/verilator_version.py | 50 +++ .../patches/hierarchical_binary_name.patch | 11 + modules/verilator/5.036.bcr.1/presubmit.yml | 12 + modules/verilator/5.036.bcr.1/source.json | 21 + modules/verilator/metadata.json | 3 +- 15 files changed, 1054 insertions(+), 1 deletion(-) create mode 100644 modules/verilator/5.036.bcr.1/MODULE.bazel create mode 100644 modules/verilator/5.036.bcr.1/overlay/.bazelignore create mode 100644 modules/verilator/5.036.bcr.1/overlay/BUILD.bazel create mode 120000 modules/verilator/5.036.bcr.1/overlay/MODULE.bazel create mode 100644 modules/verilator/5.036.bcr.1/overlay/private/BUILD.bazel create mode 100644 modules/verilator/5.036.bcr.1/overlay/private/verilator_astgen.py create mode 100644 modules/verilator/5.036.bcr.1/overlay/private/verilator_bisonpre.py create mode 100644 modules/verilator/5.036.bcr.1/overlay/private/verilator_build_template.py create mode 100644 modules/verilator/5.036.bcr.1/overlay/private/verilator_flexfix.py create mode 100644 modules/verilator/5.036.bcr.1/overlay/private/verilator_utils.bzl create mode 100644 modules/verilator/5.036.bcr.1/overlay/private/verilator_version.py create mode 100644 modules/verilator/5.036.bcr.1/patches/hierarchical_binary_name.patch create mode 100644 modules/verilator/5.036.bcr.1/presubmit.yml create mode 100644 modules/verilator/5.036.bcr.1/source.json diff --git a/modules/verilator/5.036.bcr.1/MODULE.bazel b/modules/verilator/5.036.bcr.1/MODULE.bazel new file mode 100644 index 00000000000..254c4c69d86 --- /dev/null +++ b/modules/verilator/5.036.bcr.1/MODULE.bazel @@ -0,0 +1,16 @@ +"""https://verilator.org/""" + +module( + name = "verilator", + version = "5.036.bcr.1", + bazel_compatibility = [">=7.2.1"], +) + +bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "platforms", version = "0.0.11") +bazel_dep(name = "rules_bison", version = "0.4") +bazel_dep(name = "rules_cc", version = "0.1.1") +bazel_dep(name = "rules_flex", version = "0.4") +bazel_dep(name = "rules_m4", version = "0.3") +bazel_dep(name = "rules_python", version = "1.3.0") +bazel_dep(name = "zlib", version = "1.3.1.bcr.5") diff --git a/modules/verilator/5.036.bcr.1/overlay/.bazelignore b/modules/verilator/5.036.bcr.1/overlay/.bazelignore new file mode 100644 index 00000000000..550ecdd6ff4 --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/.bazelignore @@ -0,0 +1 @@ +ci diff --git a/modules/verilator/5.036.bcr.1/overlay/BUILD.bazel b/modules/verilator/5.036.bcr.1/overlay/BUILD.bazel new file mode 100644 index 00000000000..b2e5c7356ad --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/BUILD.bazel @@ -0,0 +1,369 @@ +load("@bazel_skylib//rules:write_file.bzl", "write_file") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") +load("@rules_flex//flex:flex.bzl", "flex") +load( + "//private:verilator_utils.bzl", + "verilator_astgen", + "verilator_bisonpre", + "verilator_build_template", + "verilator_flexfix", + "verilator_version", +) + +package(default_visibility = ["//visibility:private"]) + +licenses(["notice"]) + +exports_files([ + "Artistic", + "COPYING", + "COPYING.LESSER", +]) + +verilator_version( + name = "version", + changelog = "Changes", +) + +verilator_build_template( + name = "config_package", + out = "src/config_package.h", + substitutions = { + "#define PACKAGE_STRING \"\"": "#define PACKAGE_STRING \"Verilator v{VERILATOR_VERSION}\"", + }, + template = "src/config_package.h.in", + version = ":version", +) + +write_file( + name = "config_rev_template", + out = "src/config_rev.h.in", + content = """\ +static const char* const DTVERSION_rev = ""; + +""".splitlines(), + newline = "unix", +) + +verilator_build_template( + name = "config_rev", + out = "src/config_rev.h", + substitutions = { + "DTVERSION_rev = \"\"": "DTVERSION_rev = \"v{VERILATOR_VERSION}\"", + }, + template = "src/config_rev.h.in", + version = ":version", +) + +verilator_build_template( + name = "verilated_config", + out = "include/verilated_config.h", + substitutions = { + "@PACKAGE_NAME@": "Verilator", + "@PACKAGE_VERSION@": "{VERILATOR_VERSION}", + }, + template = "include/verilated_config.h.in", + version = ":version", +) + +verilator_astgen( + name = "verilator_astgen", + srcs = [ + "src/V3Ast.h", + "src/V3AstNodeDType.h", + "src/V3AstNodeExpr.h", + "src/V3AstNodeOther.h", + "src/V3DfgVertices.h", + "src/Verilator.cpp", + ], + outs = [ + "V3Ast__gen_forward_class_decls.h", + "V3Ast__gen_impl.h", + "V3Ast__gen_macros.h", + "V3Ast__gen_report.txt", + "V3Ast__gen_type_enum.h", + "V3Ast__gen_type_info.h", + "V3Ast__gen_type_tests.h", + "V3Ast__gen_visitor_decls.h", + "V3Ast__gen_visitor_defns.h", + "V3Ast__gen_yystype.h", + "V3Dfg__gen_ast_to_dfg.h", + "V3Dfg__gen_auto_classes.h", + "V3Dfg__gen_dfg_to_ast.h", + "V3Dfg__gen_forward_class_decls.h", + "V3Dfg__gen_macros.h", + "V3Dfg__gen_type_enum.h", + "V3Dfg__gen_type_tests.h", + "V3Dfg__gen_visitor_decls.h", + "V3Dfg__gen_visitor_defns.h", + ], + args = [ + "--astdef", + "V3AstNodeDType.h", + "--astdef", + "V3AstNodeExpr.h", + "--astdef", + "V3AstNodeOther.h", + "--dfgdef", + "V3DfgVertices.h", + "--classes", + ], + astgen = "src/astgen", +) + +verilator_astgen( + name = "verilator_astgen_const", + srcs = [ + "src/V3Ast.h", + "src/V3AstNodeDType.h", + "src/V3AstNodeExpr.h", + "src/V3AstNodeOther.h", + "src/V3Const.cpp", + "src/V3DfgVertices.h", + "src/Verilator.cpp", + ], + outs = [ + "V3Const__gen.cpp", + ], + args = [ + "--astdef", + "V3AstNodeDType.h", + "--astdef", + "V3AstNodeExpr.h", + "--astdef", + "V3AstNodeOther.h", + "--dfgdef", + "V3DfgVertices.h", + "V3Const.cpp", + ], + astgen = "src/astgen", +) + +flex( + name = "verilator_lex_flex", + src = "src/verilog.l", +) + +verilator_flexfix( + name = "verilator_lex_flexfix", + src = ":verilator_lex_flex", + out = "V3Lexer.yy.cpp", + args = ["V3Lexer"], + flexfix = "src/flexfix", +) + +flex( + name = "verilator_prelex_pregen", + src = "src/V3PreLex.l", +) + +verilator_flexfix( + name = "verilator_prelex_flexfix", + src = ":verilator_prelex_pregen", + out = "V3PreLex.yy.cpp", + args = ["V3PreLex"], + flexfix = "src/flexfix", +) + +verilator_bisonpre( + name = "verilator_bison", + bisonpre = "src/bisonpre", + out_hdr = "V3ParseBison.h", + out_src = "V3ParseBison.c", + yacc_src = "src/verilog.y", +) + +cc_library( + name = "verilatedos", + hdrs = [ + "include/verilatedos.h", + "include/verilatedos_c.h", + ], + strip_include_prefix = "include/", +) + +# TODO(kkiningh): Verilator also supports multithreading, should we enable it? +cc_library( + name = "verilator_libV3", + srcs = glob( + ["src/V3*.cpp"], + exclude = [ + "src/V3*_test.cpp", + "src/V3Const.cpp", + ], + ) + [ + ":V3Ast__gen_forward_class_decls.h", + ":V3Ast__gen_impl.h", + ":V3Ast__gen_macros.h", + ":V3Ast__gen_type_enum.h", + ":V3Ast__gen_type_info.h", + ":V3Ast__gen_type_tests.h", + ":V3Ast__gen_visitor_decls.h", + ":V3Ast__gen_visitor_defns.h", + ":V3Ast__gen_yystype.h", + ":V3Const__gen.cpp", + ":V3Dfg__gen_ast_to_dfg.h", + ":V3Dfg__gen_auto_classes.h", + ":V3Dfg__gen_dfg_to_ast.h", + ":V3Dfg__gen_forward_class_decls.h", + ":V3Dfg__gen_macros.h", + ":V3Dfg__gen_type_enum.h", + ":V3Dfg__gen_type_tests.h", + ":V3Dfg__gen_visitor_decls.h", + ":V3Dfg__gen_visitor_defns.h", + ":V3ParseBison.h", + ], + hdrs = glob(["src/V3*.h"]) + [ + "src/config_build.h", + "src/config_package.h", + "src/config_rev.h", + ], + copts = [ + # TODO: We should probably set this later + "-DDEFENV_SYSTEMC_INCLUDE=\\\"@invalid@\\\"", + "-DDEFENV_SYSTEMC_LIBDIR=\\\"@invalid@\\\"", + "-DDEFENV_VERILATOR_ROOT=\\\"@invalid@\\\"", + # TODO: Remove these once upstream fixes these warnings + "-Wno-unneeded-internal-declaration", + ], + defines = ["YYDEBUG"], + strip_include_prefix = "src/", + textual_hdrs = [ + # These are included directly by other C++ files + # See https://github.com/bazelbuild/bazel/issues/680 + ":V3Lexer.yy.cpp", + ":V3PreLex.yy.cpp", + ":V3ParseBison.c", + ], + deps = [ + ":verilatedos", + "@rules_flex//flex:current_flex_toolchain", + ], +) + +cc_library( + name = "vltstd", + hdrs = [ + "include/vltstd/sv_vpi_user.h", + "include/vltstd/svdpi.h", + "include/vltstd/vpi_user.h", + ], + strip_include_prefix = "include/vltstd", +) + +cc_library( + name = "verilator", + srcs = [ + "include/gtkwave/fastlz.h", + "include/gtkwave/fst_config.h", + "include/gtkwave/fstapi.h", + "include/gtkwave/lz4.h", + "include/verilated.cpp", + "include/verilated_fst_c.cpp", + "include/verilated_imp.h", + "include/verilated_random.cpp", + "include/verilated_saif_c.cpp", + "include/verilated_syms.h", + "include/verilated_threads.cpp", + "include/verilated_vcd_c.cpp", + "include/verilated_vpi.cpp", + ], + hdrs = [ + "include/verilated_config.h", + "include/verilated_dpi.h", + "include/verilated_fst_c.h", + "include/verilated_funcs.h", + "include/verilated_intrinsics.h", + "include/verilated_random.h", + "include/verilated_sc.h", + "include/verilated_sym_props.h", + "include/verilated_saif_c.h", + "include/verilated_threads.h", + "include/verilated_timing.h", + # Needed for verilated_vcd_c.cpp and verilated_fst_c.cpp + "include/verilated_trace_imp.h", + "include/verilated_trace.h", + "include/verilated_types.h", + "include/verilated_vcd_c.h", + "include/verilated_vpi.h", + "include/verilated.h", + ], + # TODO: Remove these once upstream fixes these warnings + copts = select({ + "@platforms//os:windows": [], + "//conditions:default": [ + "-Wno-unused-variable", + "-Wno-sign-compare", + "-Wno-unused-const-variable", + "-std=c++17", + "-ffp-contract=off", + ], + }), + includes = ["include"], + linkopts = select({ + "@platforms//os:windows": [], + "//conditions:default": [ + "-lpthread", + ], + }), + strip_include_prefix = "include/", + textual_hdrs = [ + "include/gtkwave/fastlz.c", + "include/gtkwave/fstapi.c", + "include/gtkwave/lz4.c", + ], + visibility = ["//visibility:public"], + deps = [ + ":verilatedos", + ":vltstd", + "@zlib", + ], +) + +# This alias is for supporting the legacy name but while allowing the +# `cc_library` target to be renamed to avoid a `liblibverilator.a` +# output name. +alias( + name = "libverilator", + actual = "verilator", + visibility = ["//visibility:public"], +) + +cc_library( + name = "svdpi", + hdrs = [ + "include/vltstd/svdpi.h", + ], + strip_include_prefix = "include/vltstd", + visibility = ["//visibility:public"], +) + +cc_binary( + name = "verilator_bin", + srcs = ["src/Verilator.cpp"], + copts = select({ + "@platforms//os:windows": [], + "//conditions:default": [ + "-std=c++17", + "-ffp-contract=off", + ], + }), + linkopts = select({ + "@platforms//os:linux": [ + "-lpthread", + "-latomic", + ], + "@platforms//os:macos": [ + "-lpthread", + ], + "//conditions:default": [], + }), + visibility = ["//visibility:public"], + deps = [":verilator_libV3"], +) + +alias( + name = "verilator_executable", + actual = ":verilator_bin", + visibility = ["//visibility:public"], +) diff --git a/modules/verilator/5.036.bcr.1/overlay/MODULE.bazel b/modules/verilator/5.036.bcr.1/overlay/MODULE.bazel new file mode 120000 index 00000000000..9b599e3ad9c --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/MODULE.bazel @@ -0,0 +1 @@ +../MODULE.bazel \ No newline at end of file diff --git a/modules/verilator/5.036.bcr.1/overlay/private/BUILD.bazel b/modules/verilator/5.036.bcr.1/overlay/private/BUILD.bazel new file mode 100644 index 00000000000..3996f8e135e --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/private/BUILD.bazel @@ -0,0 +1,31 @@ +load("@rules_python//python:defs.bzl", "py_binary") + +py_binary( + name = "verilator_astgen", + srcs = ["verilator_astgen.py"], + visibility = ["//:__pkg__"], +) + +py_binary( + name = "verilator_bisonpre", + srcs = ["verilator_bisonpre.py"], + visibility = ["//:__pkg__"], +) + +py_binary( + name = "verilator_build_template", + srcs = ["verilator_build_template.py"], + visibility = ["//:__pkg__"], +) + +py_binary( + name = "verilator_flexfix", + srcs = ["verilator_flexfix.py"], + visibility = ["//:__pkg__"], +) + +py_binary( + name = "verilator_version", + srcs = ["verilator_version.py"], + visibility = ["//:__pkg__"], +) diff --git a/modules/verilator/5.036.bcr.1/overlay/private/verilator_astgen.py b/modules/verilator/5.036.bcr.1/overlay/private/verilator_astgen.py new file mode 100644 index 00000000000..6ab0fdaa1dd --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/private/verilator_astgen.py @@ -0,0 +1,69 @@ +"""A process wrapper for running Verilator's astgen tool in a Bazel action.""" + +import argparse +import shutil +import subprocess +import sys +from pathlib import Path + + +def parse_args() -> argparse.Namespace: + """Parse command line arguments""" + parser = argparse.ArgumentParser() + + parser.add_argument( + "--src", + dest="srcs", + type=Path, + action="append", + required=True, + help="Sources that need to appear in include paths.", + ) + + parser.add_argument( + "--out", + dest="outputs", + type=Path, + action="append", + required=True, + help="The expected output files.", + ) + + parser.add_argument("--astgen", type=Path, required=True, help="The path to the astgen tool.") + + parser.add_argument( + "astgen_args", + nargs="*", + help="Remaining args to forward to astgen.", + ) + + return parser.parse_args() + + +def main() -> None: + """The main entrypoint""" + args = parse_args() + + includes = [] + for parent in set(path.parent for path in args.srcs): + includes.extend(["-I", str(parent)]) + + result = subprocess.run( + [sys.executable, str(args.astgen)] + includes + args.astgen_args, + check=False, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + encoding="utf-8", + ) + + if result.returncode: + print(result.args, file=sys.stderr) + print(result.stdout, file=sys.stderr) + sys.exit(result.returncode) + + for out in args.outputs: + shutil.copyfile(out.name, out) + + +if __name__ == "__main__": + main() diff --git a/modules/verilator/5.036.bcr.1/overlay/private/verilator_bisonpre.py b/modules/verilator/5.036.bcr.1/overlay/private/verilator_bisonpre.py new file mode 100644 index 00000000000..4399e9968f2 --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/private/verilator_bisonpre.py @@ -0,0 +1,30 @@ +"""A wrapper for bisonpre that reduces noise in console logs.""" + +import os +import subprocess +import sys + + +def main() -> None: + """The main entrypoint""" + + env = dict(os.environ) + if "RUNFILES_DIR" in env: + del env["RUNFILES_DIR"] + + result = subprocess.run( + [sys.executable] + sys.argv[1:], + env=env, + check=False, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + encoding="utf-8", + ) + # Only log if the process has failed. + if result.returncode: + print(result.stdout, file=sys.stderr) + sys.exit(result.returncode) + + +if __name__ == "__main__": + main() diff --git a/modules/verilator/5.036.bcr.1/overlay/private/verilator_build_template.py b/modules/verilator/5.036.bcr.1/overlay/private/verilator_build_template.py new file mode 100644 index 00000000000..5244801cd05 --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/private/verilator_build_template.py @@ -0,0 +1,63 @@ +"""A tool for generating Verilator source files required for compilation.""" + +import argparse +import json +from pathlib import Path +from typing import Dict + + +def _substitutions_arg(value: str) -> Dict[str, str]: + return json.loads(value) + + +def parse_args() -> argparse.Namespace: + """Parse command line arguments""" + parser = argparse.ArgumentParser() + + parser.add_argument( + "--version", + type=Path, + required=True, + help="A file containing the current Verilator version.", + ) + + parser.add_argument( + "--substitutions", + type=_substitutions_arg, + required=True, + help="Substitutions to apply to the template file.", + ) + + parser.add_argument( + "--template", + type=Path, + required=True, + help="The template file to be updated.", + ) + + parser.add_argument( + "--output", + type=Path, + required=True, + help="The expected output files.", + ) + + return parser.parse_args() + + +def main() -> None: + """The main entrypoint""" + args = parse_args() + + version = args.version.read_text(encoding="utf-8").strip() + + content = args.template.read_text(encoding="utf-8") + for key, value in args.substitutions.items(): + value = value.replace("{VERILATOR_VERSION}", version) + content = content.replace(key, value) + + args.output.write_text(content, encoding="utf-8") + + +if __name__ == "__main__": + main() diff --git a/modules/verilator/5.036.bcr.1/overlay/private/verilator_flexfix.py b/modules/verilator/5.036.bcr.1/overlay/private/verilator_flexfix.py new file mode 100644 index 00000000000..f24e789b457 --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/private/verilator_flexfix.py @@ -0,0 +1,65 @@ +"""A process wrapper for running Verilator's flexfix tool in a Bazel action.""" + +import argparse +import subprocess +import sys +from pathlib import Path + + +def parse_args() -> argparse.Namespace: + """Parse command line arguments""" + parser = argparse.ArgumentParser() + + parser.add_argument( + "--flexfix", + type=Path, + required=True, + help="The path to `flexfix`.", + ) + + parser.add_argument( + "--src", + type=Path, + required=True, + help="The input source file to pass to `flexfix`", + ) + + parser.add_argument( + "--output", + type=Path, + required=True, + help="The path to the output file the action must produce.", + ) + + parser.add_argument( + dest="flexfix_args", + nargs="*", + help="Additional args to be passed to `flexfix`.", + ) + + return parser.parse_args() + + +def main() -> None: + """The main entrypoint""" + args = parse_args() + + with args.src.open() as handle: + result = subprocess.run( + [sys.executable, args.flexfix] + args.flexfix_args, + stdin=handle, + check=False, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + encoding="utf-8", + ) + + if result.returncode: + print(result.stdout, file=sys.stderr) + sys.exit(result.returncode) + + args.output.write_text(result.stdout, encoding="utf-8") + + +if __name__ == "__main__": + main() diff --git a/modules/verilator/5.036.bcr.1/overlay/private/verilator_utils.bzl b/modules/verilator/5.036.bcr.1/overlay/private/verilator_utils.bzl new file mode 100644 index 00000000000..581ecc1cf1e --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/private/verilator_utils.bzl @@ -0,0 +1,313 @@ +"""Utility rules used to compile Verilator""" + +def _verilator_astgen_impl(ctx): + args = ctx.actions.args() + args.add("--astgen", ctx.file.astgen) + args.add_all(ctx.files.srcs, format_each = "--src=%s") + args.add_all(ctx.outputs.outs, format_each = "--out=%s") + args.add("--") + args.add_all(ctx.attr.args) + + ctx.actions.run( + executable = ctx.executable._process_wrapper, + mnemonic = "VerilatorASTgen", + arguments = [args], + inputs = ctx.files.srcs, + outputs = ctx.outputs.outs, + tools = [ctx.file.astgen], + ) + + return [DefaultInfo( + files = depset(ctx.outputs.outs), + )] + +verilator_astgen = rule( + doc = "Run Verilator's `astgen` tool and collect the requested outputs.", + implementation = _verilator_astgen_impl, + attrs = { + "args": attr.string_list( + doc = "The command line arugments for `astgen`.", + ), + "astgen": attr.label( + doc = "The path to the `astgen` tool.", + allow_single_file = True, + mandatory = True, + ), + "outs": attr.output_list( + doc = "The output sources generated by `astgen`.", + allow_empty = False, + mandatory = True, + ), + "srcs": attr.label_list( + doc = "Input sources for `astgen`.", + allow_files = True, + ), + "_process_wrapper": attr.label( + cfg = "exec", + executable = True, + default = Label("//private:verilator_astgen"), + ), + }, +) + +def _correct_bison_env_for_action(env, bison): + """Modify the Bison environment variables to work in an action that doesn't a have built bison runfiles directory. + + The `bison_toolchain.bison_env` parameter assumes that Bison will provided via an executable attribute + and thus have built runfiles available to it. This is not the case for this action and any other actions + trying to use bison as a tool via the toolchain. This function transforms existing environment variables + to support running Bison as desired. + + Args: + env (dict): The existing bison environment variables + bison (File): The Bison executable + + Returns: + Dict: Environment variables required for running Bison. + """ + bison_env = dict(env) + + # Convert the environment variables to non-runfiles forms + bison_runfiles_dir = "{}.runfiles/{}".format( + bison.path, + bison.owner.workspace_name, + ) + + bison_env["BISON_PKGDATADIR"] = bison_env["BISON_PKGDATADIR"].replace( + bison_runfiles_dir, + "external/{}".format(bison.owner.workspace_name), + ) + bison_env["M4"] = bison_env["M4"].replace( + bison_runfiles_dir, + "{}/external/{}".format(bison.root.path, bison.owner.workspace_name), + ) + + return bison_env + +def _verilator_bisonpre_impl(ctx): + bison_toolchain = ctx.toolchains["@rules_bison//bison:toolchain_type"].bison_toolchain + + args = ctx.actions.args() + args.add(ctx.file.bisonpre) + args.add("--yacc", bison_toolchain.bison_tool.executable) + args.add("-d") + args.add("-v") + args.add("-o", ctx.outputs.out_src) + args.add(ctx.file.yacc_src) + + outputs = [ + ctx.outputs.out_src, + ctx.outputs.out_hdr, + ] + + tools = depset([ctx.file.bisonpre], transitive = [bison_toolchain.all_files]) + + bison_env = _correct_bison_env_for_action( + env = bison_toolchain.bison_env, + bison = bison_toolchain.bison_tool.executable, + ) + + ctx.actions.run( + outputs = outputs, + inputs = [ctx.file.yacc_src], + tools = tools, + executable = ctx.executable._process_wrapper, + arguments = [args], + mnemonic = "VerilatorBisonPre", + use_default_shell_env = False, + env = bison_env, + ) + + return DefaultInfo( + files = depset(outputs), + runfiles = ctx.runfiles(files = outputs), + ) + +verilator_bisonpre = rule( + doc = "Run Verilator's `bisonpre` tool and collect the requested outputs.", + implementation = _verilator_bisonpre_impl, + attrs = { + "bisonpre": attr.label( + doc = "The path to the `bisonpre` tool.", + allow_single_file = True, + mandatory = True, + cfg = "exec", + ), + "out_hdr": attr.output( + mandatory = True, + doc = "Output files generated by the action.", + ), + "out_src": attr.output( + mandatory = True, + doc = "Output files generated by the action.", + ), + "yacc_src": attr.label( + doc = "The yacc file to run on.", + allow_single_file = True, + mandatory = True, + ), + "_process_wrapper": attr.label( + executable = True, + cfg = "exec", + default = Label("//private:verilator_bisonpre"), + ), + }, + toolchains = [ + "@rules_bison//bison:toolchain_type", + "@rules_m4//m4:toolchain_type", + ], +) + +def _find_flex_src(ctx): + cc_srcs = ctx.attr.src[OutputGroupInfo].cc_srcs.to_list() + if len(cc_srcs) != 1: + fail("Unexpected number of cc sources generated in `{}`: {}".format( + ctx.attr.src.label, + cc_srcs, + )) + + return cc_srcs[0] + +def _verilator_flexfix_impl(ctx): + src = _find_flex_src(ctx) + + args = ctx.actions.args() + args.add("--flexfix", ctx.file.flexfix) + args.add("--src", src) + args.add("--output", ctx.outputs.out) + args.add("--") + args.add_all(ctx.attr.args) + + ctx.actions.run( + executable = ctx.executable._process_wrapper, + mnemonic = "VerilatorFlexFix", + outputs = [ctx.outputs.out], + inputs = [src], + tools = [ctx.file.flexfix], + arguments = [args], + ) + + return [DefaultInfo( + files = depset([ctx.outputs.out]), + )] + +verilator_flexfix = rule( + doc = "Run Verilator's `flexfix` tool and collect the requested outputs.", + implementation = _verilator_flexfix_impl, + attrs = { + "args": attr.string_list( + doc = "The command line arugments for `flexfix`.", + ), + "flexfix": attr.label( + doc = "The path to the `flexfix` tool.", + cfg = "exec", + allow_single_file = True, + mandatory = True, + ), + "out": attr.output( + doc = "The output source generated by `flexfix`.", + mandatory = True, + ), + "src": attr.label( + doc = "The source file to pass to `flexfix`.", + mandatory = True, + allow_files = True, + ), + "_process_wrapper": attr.label( + cfg = "exec", + executable = True, + default = Label("//private:verilator_flexfix"), + ), + }, +) + +def _verilator_version_impl(ctx): + output = ctx.actions.declare_file(ctx.label.name + ".txt") + + args = ctx.actions.args() + args.add("--output", output) + args.add("--changelog", ctx.file.changelog) + + ctx.actions.run( + executable = ctx.executable._parser, + mnemonic = "VerilatorVersion", + outputs = [output], + inputs = [ctx.file.changelog], + arguments = [args], + ) + + return [DefaultInfo( + files = depset([output]), + )] + +verilator_version = rule( + doc = "A rule for parsing the current verilator version from the change log.", + implementation = _verilator_version_impl, + attrs = { + "changelog": attr.label( + doc = "The Verilator change log.", + allow_single_file = True, + mandatory = True, + ), + "_parser": attr.label( + executable = True, + cfg = "exec", + default = Label("//private:verilator_version"), + ), + }, +) + +def _verilator_build_template_impl(ctx): + output = ctx.outputs.out + + args = ctx.actions.args() + args.add("--output", output) + args.add("--version", ctx.file.version) + args.add("--substitutions", json.encode(ctx.attr.substitutions)) + args.add("--template", ctx.file.template) + + ctx.actions.run( + executable = ctx.executable._generator, + mnemonic = "VerilatorBuildTemplate", + outputs = [output], + inputs = [ctx.file.version, ctx.file.template], + arguments = [args], + ) + + return [DefaultInfo( + files = depset([output]), + )] + +verilator_build_template = rule( + doc = "A rule for expanding verilator template files required for compiling.", + implementation = _verilator_build_template_impl, + attrs = { + "out": attr.output( + doc = "The output file", + mandatory = True, + ), + "substitutions": attr.string_dict( + doc = "A mapping of substitutions to apply on the template file.", + mandatory = True, + ), + "template": attr.label( + doc = "The base template to apply substitutions to", + mandatory = True, + allow_single_file = True, + ), + "version": attr.label( + doc = ( + "A file containing the current version of Verilator. In substitution " + + "values, the `{VERILATOR_VERSION}` string will be replaced by the version " + + "in this file." + ), + allow_single_file = True, + mandatory = True, + ), + "_generator": attr.label( + executable = True, + cfg = "exec", + default = Label("//private:verilator_build_template"), + ), + }, +) diff --git a/modules/verilator/5.036.bcr.1/overlay/private/verilator_version.py b/modules/verilator/5.036.bcr.1/overlay/private/verilator_version.py new file mode 100644 index 00000000000..0e984460335 --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/private/verilator_version.py @@ -0,0 +1,50 @@ +"""A tool for parsing the current Verilator version from a Verilator change log.""" + +import argparse +import re +from pathlib import Path + + +def parse_args() -> argparse.Namespace: + """Parse command line arguments""" + parser = argparse.ArgumentParser() + + parser.add_argument( + "--changelog", + type=Path, + required=True, + help="The path to the verilator changelog.", + ) + + parser.add_argument( + "--output", + type=Path, + required=True, + help="The expected output files.", + ) + + return parser.parse_args() + + +def main() -> None: + """The main entrypoint""" + args = parse_args() + + version = None + for line in args.changelog.read_text(encoding="utf-8").splitlines(): + match = re.match( + r"^Verilator ([\d\.]+) \d\d\d\d-\d\d-\d\d", + line, + ) + if match: + version = match.group(1) + break + + if not version: + raise ValueError(f"Could not detect verilator version from changelog: {args.changelog}") + + args.output.write_text(version, encoding="utf-8") + + +if __name__ == "__main__": + main() diff --git a/modules/verilator/5.036.bcr.1/patches/hierarchical_binary_name.patch b/modules/verilator/5.036.bcr.1/patches/hierarchical_binary_name.patch new file mode 100644 index 00000000000..028807c9f62 --- /dev/null +++ b/modules/verilator/5.036.bcr.1/patches/hierarchical_binary_name.patch @@ -0,0 +1,11 @@ +--- a/src/V3EmitMk.cpp ++++ b/src/V3EmitMk.cpp +@@ -814,7 +814,7 @@ class EmitMkHierVerilation final { + of.puts("VM_HIER_RUN_DIR := " + cwd + "\n"); + of.puts("# Common options for hierarchical blocks\n"); + const string fullpath_bin = V3Os::filenameRealPath(v3Global.opt.buildDepBin()); +- const string verilator_wrapper = V3Os::filenameDir(fullpath_bin) + "/verilator"; ++ const string verilator_wrapper = V3Os::filenameDir(fullpath_bin) + "/verilator_bin"; + of.puts("VM_HIER_VERILATOR := " + verilator_wrapper + "\n"); + of.puts("VM_HIER_INPUT_FILES := \\\n"); + const V3StringList& vFiles = v3Global.opt.vFiles(); diff --git a/modules/verilator/5.036.bcr.1/presubmit.yml b/modules/verilator/5.036.bcr.1/presubmit.yml new file mode 100644 index 00000000000..882cf0ee496 --- /dev/null +++ b/modules/verilator/5.036.bcr.1/presubmit.yml @@ -0,0 +1,12 @@ +bcr_test_module: + module_path: "" + matrix: + platform: ["ubuntu2004", "ubuntu2004_arm64", "macos_arm64"] + bazel: ["7.x", "8.x"] + tasks: + verify_targets: + name: "Run test module" + platform: ${{ platform }} + bazel: ${{ bazel }} + build_targets: + - "//..." diff --git a/modules/verilator/5.036.bcr.1/source.json b/modules/verilator/5.036.bcr.1/source.json new file mode 100644 index 00000000000..245ce475cdb --- /dev/null +++ b/modules/verilator/5.036.bcr.1/source.json @@ -0,0 +1,21 @@ +{ + "url": "https://github.com/verilator/verilator/archive/refs/tags/v5.036.tar.gz", + "integrity": "sha256-QZmWSILVbPahnOgMail+vjsMNeqBEGzU9yI0JZQzfEc=", + "strip_prefix": "verilator-5.036", + "patch_strip": 1, + "overlay": { + ".bazelignore": "sha256-4Yz6+7DIt5CedRfM7s3dxN7HstNIP9KBMBXro1MaVu0=", + "BUILD.bazel": "sha256-X5ndeNeEM67en2cZ/BSnLmrPyS+aQ2C/1gRhoP6qRRw=", + "MODULE.bazel": "sha256-wJNW524laImuehijpMgRFbD6EgWSuzlPDGMLnz2PCqk=", + "private/BUILD.bazel": "sha256-um1vB3qYV9jNLMhTue172PCrJbZf/4Nc9gFiwpXqWYY=", + "private/verilator_astgen.py": "sha256-aBHwsUzSKEEEseMUDdXS2XTT8X0jHfAJw7Yu8qvKqPA=", + "private/verilator_bisonpre.py": "sha256-G92zsCtKeJSK2WtjbM47gwwKY19i5QolU6eKp6yUnr0=", + "private/verilator_build_template.py": "sha256-fmqPyHGZcYsgM4mpJX8mHDYMSMPQXBpCTLYZ/NFTv9o=", + "private/verilator_flexfix.py": "sha256-eMDxDSMiytb//P2Ej8KfCTwsblf+/WEsGa1gk2GkfK8=", + "private/verilator_utils.bzl": "sha256-0nDLkhOTQfvlyjg+B57KXhru4e2unIBOr87YcCbCzq8=", + "private/verilator_version.py": "sha256-GOQW7JAmkikFKdk7KzNQOiAt8Wk2WZvpC6V2UdLV36U=" + }, + "patches": { + "hierarchical_binary_name.patch": "sha256-kDgIFSCn1Gr6ssXr9vbcFR8ZUF10nq/oaq/JOihGynk=" + } +} diff --git a/modules/verilator/metadata.json b/modules/verilator/metadata.json index 5161e4209eb..0b5ab8033cd 100644 --- a/modules/verilator/metadata.json +++ b/modules/verilator/metadata.json @@ -13,7 +13,8 @@ ], "versions": [ "5.034", - "5.036" + "5.036", + "5.036.bcr.1" ], "yanked_versions": {} } From 78c0ed83be2ecb358cc9493e3e14d41260bec661 Mon Sep 17 00:00:00 2001 From: Will Keen Date: Fri, 3 Oct 2025 11:27:50 +0100 Subject: [PATCH 2/5] Add test for hierarchical verilation --- .../verilator/5.036.bcr.1/overlay/BUILD.bazel | 7 ++ .../5.036.bcr.1/overlay/private/test.sh | 9 +++ .../overlay/private/verilator_utils.bzl | 70 +++++++++++++++++++ .../5.036.bcr.1/overlay/tests/BUILD.bazel | 9 +++ .../5.036.bcr.1/overlay/tests/child.sv | 19 +++++ .../5.036.bcr.1/overlay/tests/parent.sv | 19 +++++ modules/verilator/5.036.bcr.1/presubmit.yml | 4 +- modules/verilator/5.036.bcr.1/source.json | 10 ++- 8 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 modules/verilator/5.036.bcr.1/overlay/private/test.sh create mode 100644 modules/verilator/5.036.bcr.1/overlay/tests/BUILD.bazel create mode 100644 modules/verilator/5.036.bcr.1/overlay/tests/child.sv create mode 100644 modules/verilator/5.036.bcr.1/overlay/tests/parent.sv diff --git a/modules/verilator/5.036.bcr.1/overlay/BUILD.bazel b/modules/verilator/5.036.bcr.1/overlay/BUILD.bazel index b2e5c7356ad..23cef517156 100644 --- a/modules/verilator/5.036.bcr.1/overlay/BUILD.bazel +++ b/modules/verilator/5.036.bcr.1/overlay/BUILD.bazel @@ -338,8 +338,15 @@ cc_library( visibility = ["//visibility:public"], ) +filegroup( + name = "verilator_include", + srcs = glob(["include/**"]), + visibility = ["//visibility:public"], +) + cc_binary( name = "verilator_bin", + data = [":verilator_include"], srcs = ["src/Verilator.cpp"], copts = select({ "@platforms//os:windows": [], diff --git a/modules/verilator/5.036.bcr.1/overlay/private/test.sh b/modules/verilator/5.036.bcr.1/overlay/private/test.sh new file mode 100644 index 00000000000..f61f17f5a20 --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/private/test.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euxo pipefail + +VERILATOR="$1" +VERILATOR_ARGS="$2" +TOP="$3" +OUTDIR="$TEST_TMPDIR/obj" + +"$VERILATOR" "$VERILATOR_ARGS" "$TOP" --Mdir="$OUTDIR" --build diff --git a/modules/verilator/5.036.bcr.1/overlay/private/verilator_utils.bzl b/modules/verilator/5.036.bcr.1/overlay/private/verilator_utils.bzl index 581ecc1cf1e..9b1596f9e63 100644 --- a/modules/verilator/5.036.bcr.1/overlay/private/verilator_utils.bzl +++ b/modules/verilator/5.036.bcr.1/overlay/private/verilator_utils.bzl @@ -311,3 +311,73 @@ verilator_build_template = rule( ), }, ) + +def _verilator_test_impl(ctx): + script = ctx.actions.declare_file(ctx.label.name + ".sh") + + # Get runfiles path to verilator binary + repo = ctx.executable.verilator.owner.workspace_name or ctx.workspace_name + verilator_rf = "{}/{}".format(repo, ctx.executable.verilator.short_path) + + # Build runfiles paths for sources + def _rf(ctx, f): + repo = f.owner.workspace_name or ctx.workspace_name + return "{}/{}".format(repo, f.short_path) + src_rfs = [_rf(ctx, f) for f in ctx.files.srcs] + src_args = " ".join(['"${TEST_SRCDIR}/%s"' % s for s in src_rfs]) + + # Unique include dirs based on sources (also runfiles paths) + def _rf_dir(ctx, f): + repo = f.owner.workspace_name or ctx.workspace_name + return repo if not f.dirname else "%s/%s" % (repo, f.dirname) + seen = {} + inc_dirs = [] + for f in ctx.files.srcs: + d = _rf_dir(ctx, f) + if d not in seen: + seen[d] = True + inc_dirs.append(d) + inc_flags = " ".join(['-I"${TEST_SRCDIR}/%s"' % d for d in inc_dirs]) + + # Arguments to verilator + args = " ".join([a for a in ctx.attr.verilator_args]) + + # Always specify top module + top = "--top-module {}".format(ctx.attr.top_module) + + content = "\n".join([ + "#!/usr/bin/env bash", + "set -euo pipefail", + # Get correct path to binary, set VERILATOR_ROOT accordingly + 'VERILATOR="${TEST_SRCDIR}/%s"' % verilator_rf, + 'export VERILATOR_ROOT="$(dirname "$VERILATOR")"', + # Setup working directory and output directory + 'WORKDIR="${TEST_TMPDIR}"', + 'mkdir -p "${WORKDIR}"', + 'cd "${WORKDIR}"', + 'OUTDIR=obj_dir', + 'mkdir "$OUTDIR"', + '"${VERILATOR}" --Mdir "${OUTDIR}" -I${OUTDIR} ' + args + " " + inc_flags + " " + src_args + " " + top, + ]) + + ctx.actions.write(output = script, content = content, is_executable = True) + + # Ensure the executable and its runfiles are present in the test’s runfiles. + runfiles = ctx.runfiles(files = ctx.files.srcs + [ctx.executable.verilator]) + runfiles = runfiles.merge(ctx.attr.verilator[DefaultInfo].default_runfiles) + + return DefaultInfo( + executable = script, + runfiles = runfiles + ) + +verilator_test = rule( + implementation = _verilator_test_impl, + test = True, + attrs = { + "verilator": attr.label(executable = True, cfg = "target", default = "//:verilator_bin"), + "srcs": attr.label_list(allow_files = [".sv", ".svh", ".v"]), + "top_module": attr.string(doc = "The top module name"), + "verilator_args": attr.string_list(), + }, +) diff --git a/modules/verilator/5.036.bcr.1/overlay/tests/BUILD.bazel b/modules/verilator/5.036.bcr.1/overlay/tests/BUILD.bazel new file mode 100644 index 00000000000..3587d2cfc91 --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/tests/BUILD.bazel @@ -0,0 +1,9 @@ +load("//private:verilator_utils.bzl", "verilator_test") + +verilator_test( + # Demonstrate hermetic build works with `--hierarchical` switch + name = "test_hierarchical", + srcs = ["child.sv", "parent.sv"], + top_module = "parent", + verilator_args = ["--cc", "--hierarchical"], +) diff --git a/modules/verilator/5.036.bcr.1/overlay/tests/child.sv b/modules/verilator/5.036.bcr.1/overlay/tests/child.sv new file mode 100644 index 00000000000..5b25ecf67d0 --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/tests/child.sv @@ -0,0 +1,19 @@ +module child ( + input logic clk, + input logic rst_n, + input logic in, + output logic out +); + /*verilator hier_block*/ + + logic in_reg; + + always_ff @(posedge clk or negedge rst_n) + if (!rst_n) + in_reg <= 1'b0; + else + in_reg <= in; + + assign out = in_reg; + +endmodule diff --git a/modules/verilator/5.036.bcr.1/overlay/tests/parent.sv b/modules/verilator/5.036.bcr.1/overlay/tests/parent.sv new file mode 100644 index 00000000000..d474a595955 --- /dev/null +++ b/modules/verilator/5.036.bcr.1/overlay/tests/parent.sv @@ -0,0 +1,19 @@ +module parent #( + parameter int NUM_CHILDREN = 8 +) ( + input logic clk, + input logic rst_n, + input logic [NUM_CHILDREN-1:0] in, + output logic [NUM_CHILDREN-1:0] out +); + + for (genvar i=0; i runfiles(Runfiles::Create(fullpath_bin)); ++ if (!runfiles) { ++ v3fatal("Cannot find runfiles directory for: " << fullpath_bin); ++ } ++ ++ const string verilator_bin = verilator_binary(*runfiles.get()); ++ const string verilator_wrapper = verilator_bin; of.puts("VM_HIER_VERILATOR := " + verilator_wrapper + "\n"); of.puts("VM_HIER_INPUT_FILES := \\\n"); const V3StringList& vFiles = v3Global.opt.vFiles(); diff --git a/modules/verilator/5.036.bcr.1/source.json b/modules/verilator/5.036.bcr.1/source.json index 073454b0d97..ef35e70177a 100644 --- a/modules/verilator/5.036.bcr.1/source.json +++ b/modules/verilator/5.036.bcr.1/source.json @@ -5,7 +5,7 @@ "patch_strip": 1, "overlay": { ".bazelignore": "sha256-4Yz6+7DIt5CedRfM7s3dxN7HstNIP9KBMBXro1MaVu0=", - "BUILD.bazel": "sha256-v7LJi+Ga63q2/oT7nKDAQJiSDbLqKScjbkQbnLoudUk=", + "BUILD.bazel": "sha256-OuHBKED/bBWsq5BiH2FQ8r0yukraL0tazzdspjrN4yI=", "MODULE.bazel": "sha256-wJNW524laImuehijpMgRFbD6EgWSuzlPDGMLnz2PCqk=", "private/BUILD.bazel": "sha256-um1vB3qYV9jNLMhTue172PCrJbZf/4Nc9gFiwpXqWYY=", "private/verilator_astgen.py": "sha256-aBHwsUzSKEEEseMUDdXS2XTT8X0jHfAJw7Yu8qvKqPA=", @@ -19,6 +19,6 @@ "tests/parent.sv": "sha256-H/JmQNBmvmG6aG1ha/bodi8wfK4zRKHAxjRg9TedXCk=" }, "patches": { - "hierarchical_binary_name.patch": "sha256-kDgIFSCn1Gr6ssXr9vbcFR8ZUF10nq/oaq/JOihGynk=" + "hierarchical_binary_name.patch": "sha256-ocLgtOwG1G4bJu5SBf/MuCKLGlZa/n4PmjxqmGod7z0=" } } From 1753990423d2fe4897336383acef583831aa34eb Mon Sep 17 00:00:00 2001 From: Kush Raval Date: Thu, 9 Oct 2025 16:27:24 +0100 Subject: [PATCH 5/5] Swap verilator_bin and verilator labels --- .../verilator/5.036.bcr.1/overlay/BUILD.bazel | 8 ++-- .../overlay/private/verilator_utils.bzl | 2 +- .../patches/hierarchical_binary_name.patch | 40 ------------------- modules/verilator/5.036.bcr.1/source.json | 7 +--- 4 files changed, 7 insertions(+), 50 deletions(-) delete mode 100644 modules/verilator/5.036.bcr.1/patches/hierarchical_binary_name.patch diff --git a/modules/verilator/5.036.bcr.1/overlay/BUILD.bazel b/modules/verilator/5.036.bcr.1/overlay/BUILD.bazel index 74c25ba4e5a..486b131a0da 100644 --- a/modules/verilator/5.036.bcr.1/overlay/BUILD.bazel +++ b/modules/verilator/5.036.bcr.1/overlay/BUILD.bazel @@ -253,7 +253,7 @@ cc_library( ) cc_library( - name = "verilator", + name = "verilator_lib", srcs = [ "include/gtkwave/fastlz.h", "include/gtkwave/fst_config.h", @@ -326,7 +326,7 @@ cc_library( # output name. alias( name = "libverilator", - actual = "verilator", + actual = "verilator_lib", visibility = ["//visibility:public"], ) @@ -346,7 +346,7 @@ filegroup( ) cc_binary( - name = "verilator_bin", + name = "verilator", data = [":verilator_include"], srcs = ["src/Verilator.cpp"], copts = select({ @@ -372,6 +372,6 @@ cc_binary( alias( name = "verilator_executable", - actual = ":verilator_bin", + actual = ":verilator", visibility = ["//visibility:public"], ) diff --git a/modules/verilator/5.036.bcr.1/overlay/private/verilator_utils.bzl b/modules/verilator/5.036.bcr.1/overlay/private/verilator_utils.bzl index 9b1596f9e63..5379daee8a9 100644 --- a/modules/verilator/5.036.bcr.1/overlay/private/verilator_utils.bzl +++ b/modules/verilator/5.036.bcr.1/overlay/private/verilator_utils.bzl @@ -375,7 +375,7 @@ verilator_test = rule( implementation = _verilator_test_impl, test = True, attrs = { - "verilator": attr.label(executable = True, cfg = "target", default = "//:verilator_bin"), + "verilator": attr.label(executable = True, cfg = "target", default = "//:verilator"), "srcs": attr.label_list(allow_files = [".sv", ".svh", ".v"]), "top_module": attr.string(doc = "The top module name"), "verilator_args": attr.string_list(), diff --git a/modules/verilator/5.036.bcr.1/patches/hierarchical_binary_name.patch b/modules/verilator/5.036.bcr.1/patches/hierarchical_binary_name.patch deleted file mode 100644 index 30301b5d1ac..00000000000 --- a/modules/verilator/5.036.bcr.1/patches/hierarchical_binary_name.patch +++ /dev/null @@ -1,40 +0,0 @@ ---- a/src/V3EmitMk.cpp -+++ b/src/V3EmitMk.cpp -@@ -22,6 +22,22 @@ - #include "V3HierBlock.h" - #include "V3Os.h" - -+#include "rules_cc/cc/runfiles/runfiles.h" -+ -+using rules_cc::cc::runfiles::Runfiles; -+std::string verilator_binary(const Runfiles &runfiles) { -+ std::string repo; -+#ifdef BAZEL_CURRENT_REPOSITORY -+ repo = BAZEL_CURRENT_REPOSITORY; -+#endif -+ if (repo.empty()) { -+ repo = "_main"; -+ } -+ -+ return runfiles.Rlocation(repo + "/verilator_bin"); -+} -+ -+ - VL_DEFINE_DEBUG_FUNCTIONS; - - // Groups adjacent files in a list, evenly distributing sum of scores -@@ -814,7 +830,13 @@ class EmitMkHierVerilation final { - of.puts("VM_HIER_RUN_DIR := " + cwd + "\n"); - of.puts("# Common options for hierarchical blocks\n"); - const string fullpath_bin = V3Os::filenameRealPath(v3Global.opt.buildDepBin()); -- const string verilator_wrapper = V3Os::filenameDir(fullpath_bin) + "/verilator"; -+ std::unique_ptr runfiles(Runfiles::Create(fullpath_bin)); -+ if (!runfiles) { -+ v3fatal("Cannot find runfiles directory for: " << fullpath_bin); -+ } -+ -+ const string verilator_bin = verilator_binary(*runfiles.get()); -+ const string verilator_wrapper = verilator_bin; - of.puts("VM_HIER_VERILATOR := " + verilator_wrapper + "\n"); - of.puts("VM_HIER_INPUT_FILES := \\\n"); - const V3StringList& vFiles = v3Global.opt.vFiles(); diff --git a/modules/verilator/5.036.bcr.1/source.json b/modules/verilator/5.036.bcr.1/source.json index ef35e70177a..0f74e8c4aff 100644 --- a/modules/verilator/5.036.bcr.1/source.json +++ b/modules/verilator/5.036.bcr.1/source.json @@ -5,20 +5,17 @@ "patch_strip": 1, "overlay": { ".bazelignore": "sha256-4Yz6+7DIt5CedRfM7s3dxN7HstNIP9KBMBXro1MaVu0=", - "BUILD.bazel": "sha256-OuHBKED/bBWsq5BiH2FQ8r0yukraL0tazzdspjrN4yI=", + "BUILD.bazel": "sha256-vZqYEaB3yg1d9UYqtLcU3rFGMOi5NVwFXeC4D4Dc7Ss=", "MODULE.bazel": "sha256-wJNW524laImuehijpMgRFbD6EgWSuzlPDGMLnz2PCqk=", "private/BUILD.bazel": "sha256-um1vB3qYV9jNLMhTue172PCrJbZf/4Nc9gFiwpXqWYY=", "private/verilator_astgen.py": "sha256-aBHwsUzSKEEEseMUDdXS2XTT8X0jHfAJw7Yu8qvKqPA=", "private/verilator_bisonpre.py": "sha256-G92zsCtKeJSK2WtjbM47gwwKY19i5QolU6eKp6yUnr0=", "private/verilator_build_template.py": "sha256-fmqPyHGZcYsgM4mpJX8mHDYMSMPQXBpCTLYZ/NFTv9o=", "private/verilator_flexfix.py": "sha256-eMDxDSMiytb//P2Ej8KfCTwsblf+/WEsGa1gk2GkfK8=", - "private/verilator_utils.bzl": "sha256-tyyeHj73V9ZsGfS1VbJcHyT2Wm4tsM2TFJ7xeoa+oXw=", + "private/verilator_utils.bzl": "sha256-bxkvlBiVjeu3GQAWuvfkZfvJNTi5DUgePhP9VWzzT90=", "private/verilator_version.py": "sha256-GOQW7JAmkikFKdk7KzNQOiAt8Wk2WZvpC6V2UdLV36U=", "tests/BUILD.bazel": "sha256-9++clrqKhaK1T+mkJReBRtHWm+OxAGx9U5VqDOZYZX4=", "tests/child.sv": "sha256-dFhxCaZZ75jbuI/sYVdqm4k5m/Xa4NKduCXkHITS7r4=", "tests/parent.sv": "sha256-H/JmQNBmvmG6aG1ha/bodi8wfK4zRKHAxjRg9TedXCk=" - }, - "patches": { - "hierarchical_binary_name.patch": "sha256-ocLgtOwG1G4bJu5SBf/MuCKLGlZa/n4PmjxqmGod7z0=" } }