Chris Frantz | 340e623 | 2021-08-25 15:56:28 -0700 | [diff] [blame] | 1 | # Copyright lowRISC contributors. |
| 2 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
Chris Frantz | 6da32ea | 2021-11-22 13:12:08 -0800 | [diff] [blame] | 4 | |
Chris Frantz | 00c717b | 2022-07-28 14:58:32 -0700 | [diff] [blame] | 5 | load("@rules_pkg//pkg:mappings.bzl", "pkg_files") |
Chris Frantz | 6da32ea | 2021-11-22 13:12:08 -0800 | [diff] [blame] | 6 | load("//rules:fusesoc.bzl", "fusesoc_build") |
| 7 | |
Miles Dai | 99f5044 | 2022-05-09 18:44:19 -0400 | [diff] [blame] | 8 | # This configuration exposes fusesoc's "verilator_options" option to the |
| 9 | # command line. This is intended to allow CI to specifically build a single |
Drew Macrae | acfd5d0 | 2022-10-31 22:39:44 -0400 | [diff] [blame] | 10 | # -threaded Verilated model to suit it's resource constraints. |
| 11 | # By default, the Verilated model should be built to |
Miles Dai | 99f5044 | 2022-05-09 18:44:19 -0400 | [diff] [blame] | 12 | # run with 4 threads. |
| 13 | load("@bazel_skylib//rules:common_settings.bzl", "string_list_flag") |
| 14 | |
| 15 | string_list_flag( |
| 16 | name = "verilator_options", |
| 17 | build_setting_default = [ |
| 18 | "--threads", |
| 19 | "4", |
| 20 | ], |
| 21 | ) |
| 22 | |
Drew Macrae | acfd5d0 | 2022-10-31 22:39:44 -0400 | [diff] [blame] | 23 | # This configuration exposes fusesoc's "make_options" to enable parallel |
| 24 | # compilation of the verilated model. Compilation takes about 30m of cpu time |
| 25 | # and 5m of time that isn't parallelized by this option, so this should reduce |
| 26 | # the total runtime to ~12m. |
| 27 | string_list_flag( |
| 28 | name = "make_options", |
| 29 | build_setting_default = [ |
| 30 | "-j", |
| 31 | "4", |
| 32 | ], |
| 33 | ) |
| 34 | |
Chris Frantz | 6da32ea | 2021-11-22 13:12:08 -0800 | [diff] [blame] | 35 | fusesoc_build( |
Miguel Young de la Sota | 634aceb | 2022-04-21 13:38:37 -0400 | [diff] [blame] | 36 | name = "verilator_real", |
Chris Frantz | 6da32ea | 2021-11-22 13:12:08 -0800 | [diff] [blame] | 37 | srcs = [ |
| 38 | ":all_files", |
| 39 | ], |
| 40 | cores = [ |
| 41 | "//:cores", |
| 42 | ], |
Chris Frantz | 96e0054 | 2021-12-15 13:21:15 -0800 | [diff] [blame] | 43 | data = ["//hw/ip/otbn:all_files"], |
Drew Macrae | acfd5d0 | 2022-10-31 22:39:44 -0400 | [diff] [blame] | 44 | make_options = ":make_options", |
Chris Frantz | 00c717b | 2022-07-28 14:58:32 -0700 | [diff] [blame] | 45 | output_groups = { |
| 46 | "binary": ["sim-verilator/Vchip_sim_tb"], |
| 47 | }, |
Chris Frantz | 6da32ea | 2021-11-22 13:12:08 -0800 | [diff] [blame] | 48 | systems = ["lowrisc:dv:chip_verilator_sim"], |
Dan McArdle | 9644452 | 2022-10-18 17:30:39 -0400 | [diff] [blame] | 49 | tags = [ |
| 50 | "manual", |
| 51 | "verilator", |
| 52 | ], |
Chris Frantz | 6da32ea | 2021-11-22 13:12:08 -0800 | [diff] [blame] | 53 | target = "sim", |
Miles Dai | 99f5044 | 2022-05-09 18:44:19 -0400 | [diff] [blame] | 54 | verilator_options = ":verilator_options", |
Chris Frantz | 6da32ea | 2021-11-22 13:12:08 -0800 | [diff] [blame] | 55 | ) |
| 56 | |
Chris Frantz | 00c717b | 2022-07-28 14:58:32 -0700 | [diff] [blame] | 57 | filegroup( |
| 58 | name = "verilator_bin", |
| 59 | srcs = [":verilator_real"], |
| 60 | output_group = "binary", |
| 61 | ) |
| 62 | |
Miguel Young de la Sota | 634aceb | 2022-04-21 13:38:37 -0400 | [diff] [blame] | 63 | # This is used in CI steps that do not want to run Verilator tests, and thus |
Drew Macrae | acfd5d0 | 2022-10-31 22:39:44 -0400 | [diff] [blame] | 64 | # do not want to build the Verilated model. This causes the //hw:verilator |
Drew Macrae | b549cf3 | 2022-10-12 15:47:02 -0400 | [diff] [blame] | 65 | # target to not emit any files, which will break any tests that rely on this; |
| 66 | # builds will succeed, tests will fail. |
Miguel Young de la Sota | 634aceb | 2022-04-21 13:38:37 -0400 | [diff] [blame] | 67 | config_setting( |
| 68 | name = "disable_verilator_build", |
| 69 | values = {"define": "DISABLE_VERILATOR_BUILD=true"}, |
| 70 | ) |
| 71 | |
| 72 | genrule( |
| 73 | name = "verilator_stub", |
Chris Frantz | 00c717b | 2022-07-28 14:58:32 -0700 | [diff] [blame] | 74 | outs = ["Vfake_sim_tb"], |
Miguel Young de la Sota | 634aceb | 2022-04-21 13:38:37 -0400 | [diff] [blame] | 75 | cmd = """ |
Chris Frantz | 00c717b | 2022-07-28 14:58:32 -0700 | [diff] [blame] | 76 | script=$@ |
Miguel Young de la Sota | 634aceb | 2022-04-21 13:38:37 -0400 | [diff] [blame] | 77 | echo '#!/bin/bash' > $$script |
| 78 | echo 'echo "ERROR: sim_verilator tests cannot be run when --define DISABLE_VERILATOR_BUILD=true is set!"' >> $$script |
| 79 | echo 'echo "This indicates an error in your Bazel invokation"' >> $$script |
| 80 | echo 'exit 1' >> $$script |
Chris Frantz | 00c717b | 2022-07-28 14:58:32 -0700 | [diff] [blame] | 81 | chmod +x $@ |
Miguel Young de la Sota | 634aceb | 2022-04-21 13:38:37 -0400 | [diff] [blame] | 82 | """, |
| 83 | ) |
| 84 | |
| 85 | alias( |
| 86 | name = "verilator", |
| 87 | actual = select({ |
Chris Frantz | 00c717b | 2022-07-28 14:58:32 -0700 | [diff] [blame] | 88 | ":disable_verilator_build": ":verilator_stub", |
| 89 | "//conditions:default": ":verilator_bin", |
Miguel Young de la Sota | 634aceb | 2022-04-21 13:38:37 -0400 | [diff] [blame] | 90 | }), |
Drew Macrae | 4c178cd | 2022-05-06 14:42:29 -0400 | [diff] [blame] | 91 | tags = ["verilator"], |
Miguel Young de la Sota | 634aceb | 2022-04-21 13:38:37 -0400 | [diff] [blame] | 92 | visibility = ["//visibility:public"], |
| 93 | ) |
| 94 | |
Eunchan Kim | 00ea4c7 | 2022-06-09 16:46:41 -0700 | [diff] [blame] | 95 | genrule( |
| 96 | name = "fusesoc_ignore", |
| 97 | outs = ["FUSESOC_IGNORE"], |
| 98 | cmd = """ |
| 99 | touch $@ |
| 100 | """, |
| 101 | visibility = ["//visibility:public"], |
| 102 | ) |
| 103 | |
Chris Frantz | 0b548fa | 2021-11-22 14:08:11 -0800 | [diff] [blame] | 104 | # TODO(lowRISC/opentitan#7972): Globbing all of the //hw/... hierarchy together |
| 105 | # is a bit of a hack. Longer term, we need proper rules for expressing the |
| 106 | # relationships between verilog components. |
Chris Frantz | 6da32ea | 2021-11-22 13:12:08 -0800 | [diff] [blame] | 107 | filegroup( |
| 108 | name = "all_files", |
Timothy Trippel | ba225de | 2022-11-01 11:32:01 -0700 | [diff] [blame] | 109 | srcs = glob( |
| 110 | ["**"], |
| 111 | # TODO(lowRISC/opentitan#15882): make Verilator work with foundry repo present. |
| 112 | exclude = ["foundry/**"], |
| 113 | ) + [ |
Chris Frantz | 6da32ea | 2021-11-22 13:12:08 -0800 | [diff] [blame] | 114 | "//hw/ip:all_files", |
| 115 | "//hw/top_earlgrey:all_files", |
| 116 | ], |
Miguel Young de la Sota | 634aceb | 2022-04-21 13:38:37 -0400 | [diff] [blame] | 117 | visibility = ["//visibility:public"], |
Chris Frantz | 6da32ea | 2021-11-22 13:12:08 -0800 | [diff] [blame] | 118 | ) |
Chris Frantz | 00c717b | 2022-07-28 14:58:32 -0700 | [diff] [blame] | 119 | |
| 120 | pkg_files( |
| 121 | name = "package", |
| 122 | srcs = ["verilator_bin"], |
| 123 | prefix = "earlgrey/verilator", |
| 124 | visibility = ["//visibility:public"], |
| 125 | ) |