load("@bazel_skylib//lib:selects.bzl", "selects") load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") load("@bazel_skylib//rules:write_file.bzl", "write_file") load("@flex//:flex.bzl", "flex") load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") 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.LESSER", "COPYING", "include/verilated_std.sv", "include/verilated.mk.in", "include/verilated.v", "MODULE.bazel", ] + glob(["bin/*"]), ) bool_flag( name = "timing", build_setting_default = False, ) config_setting( name = "with_timing", flag_values = {":timing": "True"}, ) selects.config_setting_group( name = "use_cxx20", match_any = [ ":with_timing", ], ) 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}", "@VERILATOR_VERSION_INTEGER@": "5046000", }, 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/V3AstNodeStmt.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_clone_cases.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", "--astdef", "V3AstNodeStmt.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/V3AstNodeStmt.h", "src/V3Const.cpp", "src/V3DfgVertices.h", "src/Verilator.cpp", ], outs = [ "V3Const__gen.cpp", ], args = [ "--astdef", "V3AstNodeDType.h", "--astdef", "V3AstNodeExpr.h", "--astdef", "V3AstNodeOther.h", "--astdef", "V3AstNodeStmt.h", "--dfgdef", "V3DfgVertices.h", "V3Const.cpp", ], astgen = "src/astgen", ) flex( name = "verilator_lex_flex", srcs = ["src/verilog.l"], outs = ["verilog.yy.c"], args = [ "-o", "$(execpath verilog.yy.c)", "$(execpath 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", srcs = ["src/V3PreLex.l"], outs = ["V3PreLex.yy.c"], args = [ "-o", "$(execpath V3PreLex.yy.c)", "$(execpath 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/verilated_cov_key.h", "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_clone_cases.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 = select({ "@rules_cc//cc/compiler:msvc-cl": [ "/std:c++20", "/bigobj", "/w", "-DDEFENV_SYSTEMC_INCLUDE=\\\"@invalid@\\\"", "-DDEFENV_SYSTEMC_LIBDIR=\\\"@invalid@\\\"", "-DDEFENV_VERILATOR_ROOT=\\\"@invalid@\\\"", ], "//conditions:default": [ "-w", "-DDEFENV_SYSTEMC_INCLUDE=\\\"@invalid@\\\"", "-DDEFENV_SYSTEMC_LIBDIR=\\\"@invalid@\\\"", "-DDEFENV_VERILATOR_ROOT=\\\"@invalid@\\\"", ], }), defines = ["YYDEBUG"] + select({ "@platforms//os:windows": ["YY_NO_UNISTD_H"], "//conditions:default": [], }), linkopts = select({ "@rules_cc//cc/compiler:msvc-cl": ["/STACK:10000000"], "//conditions:default": [], }), 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", "@flex//:headers", ], ) 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 = "verilated", srcs = [ "include/gtkwave/fastlz.h", "include/gtkwave/fst_config.h", "include/gtkwave/fst_win_unistd.h", "include/gtkwave/fstapi.h", "include/gtkwave/lz4.h", "include/verilated.cpp", "include/verilated_cov.cpp", "include/verilated_dpi.cpp", "include/verilated_imp.h", "include/verilated_probdist.cpp", "include/verilated_profiler.cpp", "include/verilated_random.cpp", "include/verilated_saif_c.cpp", "include/verilated_save.cpp", "include/verilated_syms.h", "include/verilated_threads.cpp", "include/verilated_vcd_c.cpp", "include/verilated_vpi.cpp", ] + select({ "@platforms//os:windows": [], "//conditions:default": ["include/verilated_fst_c.cpp"], }) + select({ ":with_timing": ["include/verilated_timing.cpp"], "//conditions:default": [], }), hdrs = [ "include/verilated_config.h", "include/verilated_cov.h", "include/verilated_dpi.h", "include/verilated_fst_c.h", "include/verilated_fst_sc.h", "include/verilated_funcs.h", "include/verilated_intrinsics.h", "include/verilated_profiler.h", "include/verilated_random.h", "include/verilated_saif_c.h", "include/verilated_saif_sc.h", "include/verilated_save.h", "include/verilated_sc.h", "include/verilated_sc_trace.h", "include/verilated_sym_props.h", "include/verilated_threads.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_vcd_sc.h", "include/verilated_vpi.h", "include/verilated.h", ] + select({ ":with_timing": ["include/verilated_timing.h"], "//conditions:default": [], }), copts = select({ "@rules_cc//cc/compiler:msvc-cl": [ "/std:c++17", "/w", ], "//conditions:default": [ "-w", "-std=c++17", "-ffp-contract=off", ], }) + select({ # TODO: Without negative selects there is no way to describe # a condtiion for `use_cxx20 + msvc-cl` and another for # `use_cxx20 + (!msvc-cl)` ":use_cxx20": ["-std=c++20"], "//conditions:default": [], }), 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", ], ) cc_library( name = "svdpi", hdrs = [ "include/vltstd/svdpi.h", ], strip_include_prefix = "include/vltstd", visibility = ["//visibility:public"], ) filegroup( name = "verilator_includes", srcs = glob(["include/**"]) + [ ":verilated_config", ], visibility = ["//visibility:public"], ) cc_binary( name = "verilator", srcs = ["src/Verilator.cpp"], copts = select({ "@rules_cc//cc/compiler:msvc-cl": [ "/std:c++20", "/bigobj", "/w", ], "//conditions:default": [ "-w", "-std=c++17", "-ffp-contract=off", ], }), data = [":verilator_includes"], linkopts = select({ "@platforms//os:linux": [ "-lpthread", "-latomic", ], "@platforms//os:macos": [ "-lpthread", ], "@platforms//os:windows": [], "//conditions:default": [], }) + select({ "@rules_cc//cc/compiler:msvc-cl": [ "/STACK:10000000", "bcrypt.lib", "psapi.lib", ], "//conditions:default": [], }), visibility = ["//visibility:public"], deps = [":verilator_libV3"], ) # Mirrors upstream native build: Coverage mode builds dedicated # `verilator_coverage_bin_dbg` sources, separate from core Verilator objects. # `VlcMain.cpp` pulls in several implementation files directly (see textual_hdrs), # so this stays separate from `verilator_libV3` to avoid duplicate symbol linkage. cc_library( name = "verilator_coverage_bin_dbg_lib", srcs = ["src/VlcMain.cpp"], hdrs = glob([ "src/V3*.h", "src/Vlc*.h", ]) + [ "src/config_build.h", "src/config_package.h", "src/config_rev.h", ], copts = select({ "@rules_cc//cc/compiler:msvc-cl": [ "/std:c++20", "/bigobj", "/w", ], "//conditions:default": [ "-w", "-std=c++17", "-ffp-contract=off", ], }), defines = ["YYDEBUG"], includes = ["src"], textual_hdrs = [ # `VlcMain.cpp` intentionally includes these implementation files. "src/V3Error.cpp", "src/V3OptionParser.cpp", "src/V3Os.cpp", "src/V3String.cpp", "src/VlcTop.cpp", ], deps = [":verilatedos"], ) cc_binary( name = "verilator_coverage_bin_dbg", linkopts = select({ "@platforms//os:linux": [ "-lpthread", "-latomic", ], "@platforms//os:macos": [ "-lpthread", ], "@platforms//os:windows": [], "//conditions:default": [], }) + select({ "@rules_cc//cc/compiler:msvc-cl": [ "/STACK:10000000", "bcrypt.lib", "psapi.lib", ], "//conditions:default": [], }), visibility = ["//visibility:public"], deps = [":verilator_coverage_bin_dbg_lib"], ) # Legacy Aliases alias( name = "libverilator", actual = ":verilated", visibility = ["//visibility:public"], ) alias( name = "verilator_bin", actual = ":verilator", visibility = ["//visibility:public"], ) alias( name = "verilator_executable", actual = ":verilator", visibility = ["//visibility:public"], ) alias( name = "verilator_coverage_bin", actual = ":verilator_coverage_bin_dbg", visibility = ["//visibility:public"], ) alias( name = "verilator_coverage_executable", actual = ":verilator_coverage_bin_dbg", visibility = ["//visibility:public"], )