From 2aa08b4287649bcff8eb1029a5fe25e527b2de1e Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Tue, 5 Nov 2024 15:59:34 +0100 Subject: [PATCH] [bazel] Rework HW files targets This commit switches the HW targets (verilator, bitstream) to use the target create by `opentitan_top`. This allows to remove many of the hacky `all_files` targets used everywhere. This commit does keep a few and even creates some, but tries to adhere to the following convention: only use `glob()` or `all_files` for sub-directories that contain no bazel targets and should be passed "as-is" to fusesoc. Signed-off-by: Amaury Pouly --- BUILD.bazel | 2 + hw/BUILD | 21 +---------- hw/bitstream/vivado/BUILD | 6 +-- hw/{ip/tlul/data => dv}/BUILD | 4 +- hw/ip/BUILD | 39 -------------------- hw/ip/prim/BUILD | 6 --- hw/ip/tlul/BUILD | 7 ---- hw/ip_templates/BUILD | 10 ----- hw/ip_templates/pwrmgr/BUILD | 10 ----- hw/ip_templates/rstmgr/BUILD | 10 ----- hw/{ip_templates/clkmgr => lint}/BUILD | 4 +- hw/top_earlgrey/BUILD | 15 +++----- hw/top_earlgrey/dv/BUILD | 5 +++ hw/top_earlgrey/dv/verilator/BUILD | 10 ----- hw/top_earlgrey/ip/BUILD | 23 ------------ hw/top_earlgrey/ip/xbar/BUILD | 6 --- hw/top_earlgrey/ip/xbar_main/BUILD | 7 ---- hw/top_earlgrey/ip/xbar_main/data/BUILD | 10 ----- hw/top_earlgrey/ip/xbar_peri/BUILD | 7 ---- hw/top_earlgrey/ip/xbar_peri/data/BUILD | 10 ----- hw/top_earlgrey/sw/BUILD | 10 ----- hw/top_earlgrey/sw/autogen/BUILD | 5 --- hw/top_earlgrey/sw/autogen/chip/BUILD | 7 +--- hw/{ip_templates/flash_ctrl => vendor}/BUILD | 4 +- 24 files changed, 27 insertions(+), 211 deletions(-) rename hw/{ip/tlul/data => dv}/BUILD (86%) delete mode 100644 hw/ip_templates/pwrmgr/BUILD delete mode 100644 hw/ip_templates/rstmgr/BUILD rename hw/{ip_templates/clkmgr => lint}/BUILD (86%) delete mode 100644 hw/top_earlgrey/dv/verilator/BUILD delete mode 100644 hw/top_earlgrey/ip/BUILD delete mode 100644 hw/top_earlgrey/ip/xbar_main/data/BUILD delete mode 100644 hw/top_earlgrey/ip/xbar_peri/data/BUILD delete mode 100644 hw/top_earlgrey/sw/BUILD rename hw/{ip_templates/flash_ctrl => vendor}/BUILD (86%) diff --git a/BUILD.bazel b/BUILD.bazel index c51a52b8ea3d9d..174655443eea34 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -14,8 +14,10 @@ filegroup( name = "cores", srcs = [ "check_tool_requirements.core", + "tool_requirements.py", "topgen.core", "topgen-reg-only.core", + "//util:check_tool_requirements.py", ], ) diff --git a/hw/BUILD b/hw/BUILD index c6b06081767c7f..e605673a208a74 100644 --- a/hw/BUILD +++ b/hw/BUILD @@ -35,7 +35,7 @@ string_list_flag( fusesoc_build( name = "verilator_real", srcs = [ - ":all_files", + "//hw/top", ], cores = [ "//:cores", @@ -101,25 +101,6 @@ genrule( visibility = ["//visibility:public"], ) -# TODO(lowRISC/opentitan#7972): Globbing all of the //hw/... hierarchy together -# is a bit of a hack. Longer term, we need proper rules for expressing the -# relationships between verilog components. -filegroup( - name = "all_files", - srcs = glob( - ["**"], - # TODO(lowRISC/opentitan#15882): make Verilator work with foundry repo present. - exclude = ["foundry/**"], - ) + [ - "//:tool_requirements.py", - "//hw/ip:all_files", - "//hw/ip_templates:all_files", - "//hw/top_earlgrey:all_files", - "//util:check_tool_requirements.py", - ], - visibility = ["//visibility:public"], -) - pkg_files( name = "package", srcs = ["verilator_bin"], diff --git a/hw/bitstream/vivado/BUILD b/hw/bitstream/vivado/BUILD index 05cbb012179281..d519d54f267c9f 100644 --- a/hw/bitstream/vivado/BUILD +++ b/hw/bitstream/vivado/BUILD @@ -40,7 +40,7 @@ fusesoc_build( name = "fpga_cw310", testonly = True, srcs = [ - "//hw:all_files", + "//hw/top", _CW310_TESTROM, _OTP_RMA, ], @@ -90,7 +90,7 @@ fusesoc_build( name = "fpga_cw310_hyperdebug", testonly = True, srcs = [ - "//hw:all_files", + "//hw/top", _CW310_TESTROM, _OTP_RMA, ], @@ -140,7 +140,7 @@ fusesoc_build( name = "fpga_cw340", testonly = True, srcs = [ - "//hw:all_files", + "//hw/top", _CW340_TESTROM, _OTP_RMA, ], diff --git a/hw/ip/tlul/data/BUILD b/hw/dv/BUILD similarity index 86% rename from hw/ip/tlul/data/BUILD rename to hw/dv/BUILD index dda56de039e27f..6d6a4b344f9818 100644 --- a/hw/ip/tlul/data/BUILD +++ b/hw/dv/BUILD @@ -6,5 +6,7 @@ package(default_visibility = ["//visibility:public"]) filegroup( name = "all_files", - srcs = glob(["**"]), + srcs = glob( + ["**"], + ), ) diff --git a/hw/ip/BUILD b/hw/ip/BUILD index 3a0daf50eaedf9..c85882e64fe2c0 100644 --- a/hw/ip/BUILD +++ b/hw/ip/BUILD @@ -3,42 +3,3 @@ # SPDX-License-Identifier: Apache-2.0 package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "all_files", - srcs = glob(["**"]) + [ - "//hw/ip/adc_ctrl", - "//hw/ip/aes", - "//hw/ip/aon_timer", - "//hw/ip/csrng", - "//hw/ip/edn", - "//hw/ip/entropy_src", - "//hw/ip/gpio", - "//hw/ip/hmac", - "//hw/ip/i2c", - "//hw/ip/keymgr", - "//hw/ip/kmac", - "//hw/ip/lc_ctrl", - "//hw/ip/otbn:all_files", - "//hw/ip/otp_ctrl", - "//hw/ip/pattgen", - "//hw/ip/pinmux:all_files", - "//hw/ip/prim", - "//hw/ip/prim_generic:all_files", - "//hw/ip/prim_xilinx:all_files", - "//hw/ip/prim_xilinx_ultrascale:all_files", - "//hw/ip/pwm", - "//hw/ip/rom_ctrl", - "//hw/ip/rv_core_ibex", - "//hw/ip/rv_dm", - "//hw/ip/rv_timer", - "//hw/ip/spi_device", - "//hw/ip/spi_host", - "//hw/ip/sram_ctrl", - "//hw/ip/sysrst_ctrl", - "//hw/ip/tlul", - "//hw/ip/trial1:all_files", - "//hw/ip/uart", - "//hw/ip/usbdev", - ], -) diff --git a/hw/ip/prim/BUILD b/hw/ip/prim/BUILD index f476939864aa11..47ab80ba16399c 100644 --- a/hw/ip/prim/BUILD +++ b/hw/ip/prim/BUILD @@ -6,12 +6,6 @@ load("//rules/opentitan:hw.bzl", "opentitan_ip") package(default_visibility = ["//visibility:public"]) -filegroup( - name = "all_files", - srcs = glob(["**"]) + [ - ], -) - opentitan_ip( name = "prim", rtl = glob(["**"]) + [ diff --git a/hw/ip/tlul/BUILD b/hw/ip/tlul/BUILD index 1d92669a79a924..71a3dcaba8cece 100644 --- a/hw/ip/tlul/BUILD +++ b/hw/ip/tlul/BUILD @@ -6,13 +6,6 @@ load("//rules/opentitan:hw.bzl", "opentitan_ip") package(default_visibility = ["//visibility:public"]) -filegroup( - name = "all_files", - srcs = glob(["**"]) + [ - "//hw/ip/tlul/data:all_files", - ], -) - opentitan_ip( name = "tlul", rtl = glob(["**"]), diff --git a/hw/ip_templates/BUILD b/hw/ip_templates/BUILD index 1cafa1a94c32f6..c85882e64fe2c0 100644 --- a/hw/ip_templates/BUILD +++ b/hw/ip_templates/BUILD @@ -3,13 +3,3 @@ # SPDX-License-Identifier: Apache-2.0 package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "all_files", - srcs = glob(["**"]) + [ - "//hw/ip_templates/clkmgr:all_files", - "//hw/ip_templates/flash_ctrl:all_files", - "//hw/ip_templates/pwrmgr:all_files", - "//hw/ip_templates/rstmgr:all_files", - ], -) diff --git a/hw/ip_templates/pwrmgr/BUILD b/hw/ip_templates/pwrmgr/BUILD deleted file mode 100644 index dda56de039e27f..00000000000000 --- a/hw/ip_templates/pwrmgr/BUILD +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright lowRISC contributors (OpenTitan project). -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 - -package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "all_files", - srcs = glob(["**"]), -) diff --git a/hw/ip_templates/rstmgr/BUILD b/hw/ip_templates/rstmgr/BUILD deleted file mode 100644 index dda56de039e27f..00000000000000 --- a/hw/ip_templates/rstmgr/BUILD +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright lowRISC contributors (OpenTitan project). -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 - -package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "all_files", - srcs = glob(["**"]), -) diff --git a/hw/ip_templates/clkmgr/BUILD b/hw/lint/BUILD similarity index 86% rename from hw/ip_templates/clkmgr/BUILD rename to hw/lint/BUILD index dda56de039e27f..6d6a4b344f9818 100644 --- a/hw/ip_templates/clkmgr/BUILD +++ b/hw/lint/BUILD @@ -6,5 +6,7 @@ package(default_visibility = ["//visibility:public"]) filegroup( name = "all_files", - srcs = glob(["**"]), + srcs = glob( + ["**"], + ), ) diff --git a/hw/top_earlgrey/BUILD b/hw/top_earlgrey/BUILD index bb71724d5da1e2..0884a33f164c04 100644 --- a/hw/top_earlgrey/BUILD +++ b/hw/top_earlgrey/BUILD @@ -68,16 +68,13 @@ opentitan_top( "//hw/top_earlgrey/ip_autogen/flash_ctrl", "//hw/top_earlgrey/ip_autogen/rv_plic", ], - rtl = glob(["**"]), -) - -filegroup( - name = "all_files", - srcs = glob(["**"]) + [ + rtl = glob(["**"]) + [ + "//:cores", # FIXME move those files somewhere else? + "//hw/dv:all_files", + "//hw/lint:all_files", + "//hw/top_earlgrey/dv:all_files", + "//hw/vendor:all_files", "//hw/top_earlgrey/data:all_files", - "//hw/top_earlgrey/dv/verilator:all_files", - "//hw/top_earlgrey/ip:all_files", - "//hw/top_earlgrey/sw:all_files", ], ) diff --git a/hw/top_earlgrey/dv/BUILD b/hw/top_earlgrey/dv/BUILD index 6e257eb73d0746..04bdb973a60d9a 100644 --- a/hw/top_earlgrey/dv/BUILD +++ b/hw/top_earlgrey/dv/BUILD @@ -4,6 +4,11 @@ package(default_visibility = ["//visibility:public"]) +filegroup( + name = "all_files", + srcs = glob(["**"]), +) + filegroup( name = "config", srcs = [ diff --git a/hw/top_earlgrey/dv/verilator/BUILD b/hw/top_earlgrey/dv/verilator/BUILD deleted file mode 100644 index dda56de039e27f..00000000000000 --- a/hw/top_earlgrey/dv/verilator/BUILD +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright lowRISC contributors (OpenTitan project). -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 - -package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "all_files", - srcs = glob(["**"]), -) diff --git a/hw/top_earlgrey/ip/BUILD b/hw/top_earlgrey/ip/BUILD deleted file mode 100644 index bea1a44eb988b1..00000000000000 --- a/hw/top_earlgrey/ip/BUILD +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright lowRISC contributors (OpenTitan project). -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 - -package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "all_files", - srcs = glob(["**"]) + [ - "//hw/top_earlgrey/ip/ast", - "//hw/top_earlgrey/ip/pinmux", - "//hw/top_earlgrey/ip/sensor_ctrl", - "//hw/top_earlgrey/ip/xbar", - "//hw/top_earlgrey/ip/xbar_main", - "//hw/top_earlgrey/ip/xbar_peri", - "//hw/top_earlgrey/ip_autogen/alert_handler", - "//hw/top_earlgrey/ip_autogen/clkmgr", - "//hw/top_earlgrey/ip_autogen/flash_ctrl", - "//hw/top_earlgrey/ip_autogen/pwrmgr", - "//hw/top_earlgrey/ip_autogen/rstmgr", - "//hw/top_earlgrey/ip_autogen/rv_plic", - ], -) diff --git a/hw/top_earlgrey/ip/xbar/BUILD b/hw/top_earlgrey/ip/xbar/BUILD index 0587e1999555c5..b6f82da4d23bd9 100644 --- a/hw/top_earlgrey/ip/xbar/BUILD +++ b/hw/top_earlgrey/ip/xbar/BUILD @@ -6,12 +6,6 @@ load("//rules/opentitan:hw.bzl", "opentitan_ip") package(default_visibility = ["//visibility:public"]) -filegroup( - name = "all_files", - srcs = glob(["**"]) + [ - ], -) - opentitan_ip( name = "xbar", rtl = glob(["**"]), diff --git a/hw/top_earlgrey/ip/xbar_main/BUILD b/hw/top_earlgrey/ip/xbar_main/BUILD index d71e09b575fd88..64a016ad7d033a 100644 --- a/hw/top_earlgrey/ip/xbar_main/BUILD +++ b/hw/top_earlgrey/ip/xbar_main/BUILD @@ -6,13 +6,6 @@ load("//rules/opentitan:hw.bzl", "opentitan_ip") package(default_visibility = ["//visibility:public"]) -filegroup( - name = "all_files", - srcs = glob(["**"]) + [ - "//hw/top_earlgrey/ip/xbar_main/data:all_files", - ], -) - opentitan_ip( name = "xbar_main", rtl = glob(["**"]), diff --git a/hw/top_earlgrey/ip/xbar_main/data/BUILD b/hw/top_earlgrey/ip/xbar_main/data/BUILD deleted file mode 100644 index dda56de039e27f..00000000000000 --- a/hw/top_earlgrey/ip/xbar_main/data/BUILD +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright lowRISC contributors (OpenTitan project). -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 - -package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "all_files", - srcs = glob(["**"]), -) diff --git a/hw/top_earlgrey/ip/xbar_peri/BUILD b/hw/top_earlgrey/ip/xbar_peri/BUILD index 83d1eef9502816..cbd587a3ab514c 100644 --- a/hw/top_earlgrey/ip/xbar_peri/BUILD +++ b/hw/top_earlgrey/ip/xbar_peri/BUILD @@ -6,13 +6,6 @@ load("//rules/opentitan:hw.bzl", "opentitan_ip") package(default_visibility = ["//visibility:public"]) -filegroup( - name = "all_files", - srcs = glob(["**"]) + [ - "//hw/top_earlgrey/ip/xbar_peri/data:all_files", - ], -) - opentitan_ip( name = "xbar_peri", rtl = glob(["**"]), diff --git a/hw/top_earlgrey/ip/xbar_peri/data/BUILD b/hw/top_earlgrey/ip/xbar_peri/data/BUILD deleted file mode 100644 index dda56de039e27f..00000000000000 --- a/hw/top_earlgrey/ip/xbar_peri/data/BUILD +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright lowRISC contributors (OpenTitan project). -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 - -package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "all_files", - srcs = glob(["**"]), -) diff --git a/hw/top_earlgrey/sw/BUILD b/hw/top_earlgrey/sw/BUILD deleted file mode 100644 index dda56de039e27f..00000000000000 --- a/hw/top_earlgrey/sw/BUILD +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright lowRISC contributors (OpenTitan project). -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 - -package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "all_files", - srcs = glob(["**"]), -) diff --git a/hw/top_earlgrey/sw/autogen/BUILD b/hw/top_earlgrey/sw/autogen/BUILD index a76754cdd5433b..c9e36ac1a252ef 100644 --- a/hw/top_earlgrey/sw/autogen/BUILD +++ b/hw/top_earlgrey/sw/autogen/BUILD @@ -21,8 +21,3 @@ ld_library( name = "top_earlgrey_memory", includes = ["top_earlgrey_memory.ld"], ) - -filegroup( - name = "all_files", - srcs = glob(["**"]), -) diff --git a/hw/top_earlgrey/sw/autogen/chip/BUILD b/hw/top_earlgrey/sw/autogen/chip/BUILD index 7d7dc00bdc900e..7ffb54747df1f2 100644 --- a/hw/top_earlgrey/sw/autogen/chip/BUILD +++ b/hw/top_earlgrey/sw/autogen/chip/BUILD @@ -6,13 +6,8 @@ load("@rules_rust//rust:defs.bzl", "rust_library") package(default_visibility = ["//visibility:public"]) -filegroup( - name = "all_files", - srcs = glob(["**"]), -) - rust_library( name = "top_earlgrey", - srcs = [":all_files"], + srcs = glob(["*.rs"]), crate_root = "mod.rs", ) diff --git a/hw/ip_templates/flash_ctrl/BUILD b/hw/vendor/BUILD similarity index 86% rename from hw/ip_templates/flash_ctrl/BUILD rename to hw/vendor/BUILD index dda56de039e27f..6d6a4b344f9818 100644 --- a/hw/ip_templates/flash_ctrl/BUILD +++ b/hw/vendor/BUILD @@ -6,5 +6,7 @@ package(default_visibility = ["//visibility:public"]) filegroup( name = "all_files", - srcs = glob(["**"]), + srcs = glob( + ["**"], + ), )