From 317128f4957bff9774f1f7ebf3a47e26dc75b873 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Mon, 15 Jul 2024 11:53:01 +0100 Subject: [PATCH 1/8] [bazel] Update bazel to 7.3.1 Signed-off-by: James Wainwright --- .bazelrc | 3 +++ .bazelversion | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.bazelrc b/.bazelrc index 37001e8f54f08..2fefb4d876cfc 100644 --- a/.bazelrc +++ b/.bazelrc @@ -2,6 +2,9 @@ # Licensed under the Apache License, Version 2.0, see LICENSE for details. # SPDX-License-Identifier: Apache-2.0 +# Opt-out of bzlmod for now and continue to use `WORKSPACE`. +common --noenable_bzlmod + # https://docs.opentitan.org/doc/rm/c_cpp_coding_style/#cxx-version specifies build --action_env=BAZEL_CXXOPTS="-std=gnu++14" build --cxxopt='-std=gnu++14' diff --git a/.bazelversion b/.bazelversion index 024b066c0bb7a..643916c03f1f6 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -6.2.1 +7.3.1 From 75af5835bd1162676525c08ba9c8b385b703e735 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Mon, 12 Aug 2024 11:17:14 +0100 Subject: [PATCH 2/8] [bazel] Update how airgap downloads Bazel's own dependencies We were previously taking these from the Bazel repository at the version we were using. This has broken, but Bazel has a documented way of doing this now independent of version: https://bazel.build/run/build#repository_cache_with_bazel_7_or_later Signed-off-by: James Wainwright --- util/prep-bazel-airgapped-build.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/util/prep-bazel-airgapped-build.sh b/util/prep-bazel-airgapped-build.sh index f1b02543059e8..1462e17709929 100755 --- a/util/prep-bazel-airgapped-build.sh +++ b/util/prep-bazel-airgapped-build.sh @@ -114,16 +114,16 @@ if [[ ${AIRGAPPED_DIR_CONTENTS} == "ALL" || \ https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-linux-x86_64 \ --output bazel chmod +x bazel - git clone -b "${BAZEL_VERSION}" --depth 1 https://github.com/bazelbuild/bazel bazel-repo - cd bazel-repo - echo "Cloned bazel repo @ \"${BAZEL_VERSION}\" (commit $(git rev-parse HEAD))" - ../bazel build @additional_distfiles//:archives.tar - tar xvf bazel-bin/external/additional_distfiles/archives.tar \ - -C "../${BAZEL_DISTDIR}" \ - --strip-components=3 - cd .. - rm -rf bazel-repo - echo "Done." + + # Make Bazel sync its own dependencies to the repository cache: + # https://bazel.build/run/build#repository_cache_with_bazel_7_or_later + mkdir -p "${BAZEL_AIRGAPPED_DIR}/empty_workspace" + pushd "${BAZEL_AIRGAPPED_DIR}/empty_workspace" + touch MODULE.bazel + touch WORKSPACE + bazel sync --repository_cache="${BAZEL_AIRGAPPED_DIR}/${BAZEL_CACHEDIR}" + popd + rm -rf "${BAZEL_AIRGAPPED_DIR}/empty_workspace" fi ################################################################################ From f534cb70dda910cb3aa190f532abc91f353c8e98 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Fri, 23 Aug 2024 10:27:07 +0100 Subject: [PATCH 3/8] [bazel] Fix `fusesoc_build` conflicting prefix error Bazel 7 does not like a rule which outputs a directory _and_ something from that directory's contents. This commit removes the build directory from the outputs and exposes only those requested by `output_groups`. The paths should stay the same. Signed-off-by: James Wainwright --- rules/fusesoc.bzl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rules/fusesoc.bzl b/rules/fusesoc.bzl index 8ad8e88474a84..c1d60c9633a06 100644 --- a/rules/fusesoc.bzl +++ b/rules/fusesoc.bzl @@ -25,13 +25,13 @@ def _corefiles2rootarg(core): return core.dirname def _fusesoc_build_impl(ctx): - dirname = "build.{}".format(ctx.label.name) - out_dir = ctx.actions.declare_directory(dirname) + build_dir = "build.{}".format(ctx.label.name) + out_dir = "{}/{}/{}".format(ctx.bin_dir.path, ctx.label.package, build_dir) flags = [ctx.expand_location(f, ctx.attr.srcs) for f in ctx.attr.flags] - outputs = [out_dir] + outputs = [] groups = {} - cache_dir = "{}/fusesoc-cache".format(out_dir.path) + cache_dir = "{}/fusesoc-cache".format(out_dir) cfg_file_path = "build.{}.fusesoc_config.toml".format(ctx.label.name) cfg_file = ctx.actions.declare_file(cfg_file_path) cfg_str = "[main]\n cache_root = {}".format(cache_dir) @@ -41,7 +41,7 @@ def _fusesoc_build_impl(ctx): args.add(cfg_file.path, format = "--config=%s") for group, files in ctx.attr.output_groups.items(): - deps = [ctx.actions.declare_file("{}/{}".format(dirname, f)) for f in files] + deps = [ctx.actions.declare_file("{}/{}".format(build_dir, f)) for f in files] outputs.extend(deps) groups[group] = depset(deps) @@ -69,7 +69,7 @@ def _fusesoc_build_impl(ctx): "--setup", "--build", ]) - args.add(out_dir.path, format = "--build-root=%s") + args.add(out_dir, format = "--build-root=%s") args.add_all(ctx.attr.systems) args.add_all(flags) From 6826e0ab8096de32205c884a952c06605774b780 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Sun, 8 Sep 2024 14:38:48 +0100 Subject: [PATCH 4/8] [bazel] Allow `fusesoc_build` to output directories Signed-off-by: James Wainwright --- rules/fusesoc.bzl | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/rules/fusesoc.bzl b/rules/fusesoc.bzl index c1d60c9633a06..2d40d7c439699 100644 --- a/rules/fusesoc.bzl +++ b/rules/fusesoc.bzl @@ -41,7 +41,13 @@ def _fusesoc_build_impl(ctx): args.add(cfg_file.path, format = "--config=%s") for group, files in ctx.attr.output_groups.items(): - deps = [ctx.actions.declare_file("{}/{}".format(build_dir, f)) for f in files] + deps = [] + for file in files: + path = "{}/{}".format(build_dir, file) + if file.endswith("/"): + deps.append(ctx.actions.declare_directory(path)) + else: + deps.append(ctx.actions.declare_file(path)) outputs.extend(deps) groups[group] = depset(deps) @@ -106,7 +112,14 @@ fusesoc_build = rule( "flags": attr.string_list(doc = "Flags controlling the FuseSOC system build"), "output_groups": attr.string_list_dict( allow_empty = True, - doc = "Mapping of group name to lists of files in that named group", + doc = """ + Mappings from output group names to lists of paths contained in + that group. + + Paths to directories must have a trailing `/`. It is not + possible to output both a directory and a file from within that + directory. + """, ), "verilator_options": attr.label(), "make_options": attr.label(), From bd85187f53f124ac736f4bd1102350221a03021f Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Tue, 27 Aug 2024 09:26:51 +0100 Subject: [PATCH 5/8] [bazel] Export Vivado logs from fusesoc builds Signed-off-by: James Wainwright --- hw/bitstream/vivado/BUILD | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/bitstream/vivado/BUILD b/hw/bitstream/vivado/BUILD index 398fcd5e542da..05cbb01217928 100644 --- a/hw/bitstream/vivado/BUILD +++ b/hw/bitstream/vivado/BUILD @@ -54,6 +54,7 @@ fusesoc_build( "bitstream": ["synth-vivado/lowrisc_systems_chip_earlgrey_cw310_0.1.bit"], "rom_mmi": ["synth-vivado/rom.mmi"], "otp_mmi": ["synth-vivado/otp.mmi"], + "logs": ["synth-vivado/lowrisc_systems_chip_earlgrey_cw310_0.1.runs/"], }, systems = ["lowrisc:systems:chip_earlgrey_cw310"], tags = ["manual"], @@ -103,6 +104,7 @@ fusesoc_build( "bitstream": ["synth-vivado/lowrisc_systems_chip_earlgrey_cw310_hyperdebug_0.1.bit"], "rom_mmi": ["synth-vivado/rom.mmi"], "otp_mmi": ["synth-vivado/otp.mmi"], + "logs": ["synth-vivado/lowrisc_systems_chip_earlgrey_cw310_hyperdebug_0.1.runs/"], }, systems = ["lowrisc:systems:chip_earlgrey_cw310_hyperdebug"], tags = ["manual"], @@ -152,6 +154,7 @@ fusesoc_build( "bitstream": ["synth-vivado/lowrisc_systems_chip_earlgrey_cw340_0.1.bit"], "rom_mmi": ["synth-vivado/rom.mmi"], "otp_mmi": ["synth-vivado/otp.mmi"], + "logs": ["synth-vivado/lowrisc_systems_chip_earlgrey_cw340_0.1.runs/"], }, systems = ["lowrisc:systems:chip_earlgrey_cw340"], tags = ["manual"], From 64273af3d2c9a1856af04c76d537710c5a8aacd3 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Fri, 23 Aug 2024 16:35:45 +0100 Subject: [PATCH 6/8] [bazel] Update lowrisc license linter for Bazel 7 support This release includes a fix for Bazel 7 that we need. Signed-off-by: James Wainwright --- third_party/lint/repos.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/third_party/lint/repos.bzl b/third_party/lint/repos.bzl index ea956aeca97cf..c9ee86276b75d 100644 --- a/third_party/lint/repos.bzl +++ b/third_party/lint/repos.bzl @@ -22,7 +22,7 @@ def lint_repos(lowrisc_lint = None): http_archive_or_local( name = "lowrisc_lint", local = lowrisc_lint, - sha256 = "1303d2790b7d1a0a216558c01f8bc6255dfb840e9e60b523d988b3655a0ddab3", - strip_prefix = "misc-linters-20240820_01", - url = "https://github.com/lowRISC/misc-linters/archive/refs/tags/20240820_01.tar.gz", + sha256 = "365fe67d8168fee1a0fc3aea4bb80588bf721dc4fc83b40463b09eb50897cda3", + strip_prefix = "misc-linters-20240823_01", + url = "https://github.com/lowRISC/misc-linters/archive/refs/tags/20240823_01.tar.gz", ) From 6c694dfc3ac53b7e8927763aab73aaf68285fcf5 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Mon, 26 Aug 2024 14:58:31 +0100 Subject: [PATCH 7/8] [bazel] Apply `--host_features` as well as `--features` When we build our C files for `bindgen` to consume, we use the `host` configuration. The `--features` flag is no longer applied to `host` in Bazel 7, so we must add this extra flag. Signed-off-by: James Wainwright --- .bazelrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bazelrc b/.bazelrc index 2fefb4d876cfc..14cda5a03e7f1 100644 --- a/.bazelrc +++ b/.bazelrc @@ -17,10 +17,12 @@ build --strip='never' # Override default enablement of flags from @crt//common to control C compiler # warnings. build --features=-pedantic_warnings +build --host_features=-pedantic_warnings # Enable toolchain hardening features. # `guards` adds `unimp` guard instructions after unconditional jumps. build --features=guards +build --host_features=guards # Use --config=disable_hardening to disable hardening to measure the # impact of the hardened sequences on code size. From f9f257aa253df76138c3d927995a930309723c9b Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Mon, 26 Aug 2024 15:24:46 +0100 Subject: [PATCH 8/8] [bazel] Load `import_deps` for `rules_rust` Even though we're not using these, Bazel 7 hits errors if we try to run `bazel query deps($something)` on a Rust dependency. Fixed in `rules_rust>=0.38.0`. https://github.com/bazelbuild/rules_rust/issues/1166#issuecomment-1060888166 Signed-off-by: James Wainwright --- third_party/rust/deps.bzl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/third_party/rust/deps.bzl b/third_party/rust/deps.bzl index ea5dba2a2e891..0196684568159 100644 --- a/third_party/rust/deps.bzl +++ b/third_party/rust/deps.bzl @@ -5,6 +5,7 @@ load("@rules_rust//bindgen:repositories.bzl", "rust_bindgen_dependencies") load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains", "rust_repository_set") load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies") +load("@rules_rust//util/import:deps.bzl", "import_deps") def rust_deps(): rules_rust_dependencies() @@ -25,3 +26,9 @@ def rust_deps(): ) rust_analyzer_dependencies() + + # We're not using this feature, but have to load the deps in Bazel 7 due to + # https://github.com/bazelbuild/rules_rust/issues/1166#issuecomment-1060888166 + # + # This is no longer needed for `rules_rust>=0.38.0`. + import_deps()