From 8d54ddf32be7a751314c88f4a027e317a84a214a Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Tue, 17 Dec 2024 13:29:52 +0000 Subject: [PATCH] [bazel] Move buildifier to bzlmod Switch from building buildifier ourselves to using the `buildifier_prebuilt` module. This also means we don't have to build it from source using a Go toolchain. Signed-off-by: James Wainwright --- MODULE.bazel | 1 + MODULE.bazel.lock | 152 +++++++++++++++++++++++++++++ WORKSPACE.bzlmod | 6 -- quality/BUILD.bazel | 2 +- third_party/go/BUILD | 3 - third_party/go/deps.bzl | 43 -------- third_party/go/repos.bzl | 17 ---- third_party/lint/repos.bzl | 7 -- util/prep-bazel-airgapped-build.sh | 1 - 9 files changed, 154 insertions(+), 78 deletions(-) delete mode 100644 third_party/go/BUILD delete mode 100644 third_party/go/deps.bzl delete mode 100644 third_party/go/repos.bzl diff --git a/MODULE.bazel b/MODULE.bazel index 0c5821291518e..ad46b6f943254 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -5,6 +5,7 @@ module(name = "lowrisc_opentitan") bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "buildifier_prebuilt", version = "6.4.0") include("//third_party/rust:rust.MODULE.bazel") diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index f285bc4a1cfe3..d53bd17d6b073 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -44,6 +44,8 @@ "https://bcr.bazel.build/modules/bazel_skylib/1.7.0/MODULE.bazel": "0db596f4563de7938de764cc8deeabec291f55e8ec15299718b93c4423e9796d", "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/MODULE.bazel": "3120d80c5861aa616222ec015332e5f8d3171e062e3e804a2a0253e1be26e59b", "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/source.json": "f121b43eeefc7c29efbd51b83d08631e2347297c95aac9764a701f2a6a2bb953", + "https://bcr.bazel.build/modules/buildifier_prebuilt/6.4.0/MODULE.bazel": "37389c6b5a40c59410b4226d3bb54b08637f393d66e2fa57925c6fcf68e64bf4", + "https://bcr.bazel.build/modules/buildifier_prebuilt/6.4.0/source.json": "83eb01b197ed0b392f797860c9da5ed1bf95f4d0ded994d694a3d44731275916", "https://bcr.bazel.build/modules/buildozer/7.1.2/MODULE.bazel": "2e8dd40ede9c454042645fd8d8d0cd1527966aa5c919de86661e62953cd73d84", "https://bcr.bazel.build/modules/buildozer/7.1.2/source.json": "c9028a501d2db85793a6996205c8de120944f50a0d570438fcae0457a5f9d1f8", "https://bcr.bazel.build/modules/gazelle/0.27.0/MODULE.bazel": "3446abd608295de6d90b4a8a118ed64a9ce11dcb3dda2dc3290a22056bd20996", @@ -532,6 +534,156 @@ ] } }, + "@@buildifier_prebuilt~//:defs.bzl%buildifier_prebuilt_deps_extension": { + "general": { + "bzlTransitiveDigest": "eXBP0KrRexbBjR0KdxpnbWtfahy0r48xfQb4hBQ4Mcc=", + "usagesDigest": "nThSTPRdiQbhDFl8FRM2nsKJftWMtPBQHrp/mdk716w=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "buildozer_darwin_amd64": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "urls": [ + "https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildozer-darwin-amd64" + ], + "downloaded_file_path": "buildozer", + "executable": true, + "sha256": "d29e347ecd6b5673d72cb1a8de05bf1b06178dd229ff5eb67fad5100c840cc8e" + } + }, + "buildifier_linux_amd64": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "urls": [ + "https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildifier-linux-amd64" + ], + "downloaded_file_path": "buildifier", + "executable": true, + "sha256": "be63db12899f48600bad94051123b1fd7b5251e7661b9168582ce52396132e92" + } + }, + "buildozer_darwin_arm64": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "urls": [ + "https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildozer-darwin-arm64" + ], + "downloaded_file_path": "buildozer", + "executable": true, + "sha256": "9b9e71bdbec5e7223871e913b65d12f6d8fa026684daf991f00e52ed36a6978d" + } + }, + "buildozer_linux_amd64": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "urls": [ + "https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildozer-linux-amd64" + ], + "downloaded_file_path": "buildozer", + "executable": true, + "sha256": "8dfd6345da4e9042daa738d7fdf34f699c5dfce4632f7207956fceedd8494119" + } + }, + "buildozer_windows_amd64": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "urls": [ + "https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildozer-windows-amd64.exe" + ], + "downloaded_file_path": "buildozer.exe", + "executable": true, + "sha256": "e7f05bf847f7c3689dd28926460ce6e1097ae97380ac8e6ae7147b7b706ba19b" + } + }, + "buildozer_linux_arm64": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "urls": [ + "https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildozer-linux-arm64" + ], + "downloaded_file_path": "buildozer", + "executable": true, + "sha256": "6559558fded658c8fa7432a9d011f7c4dcbac6b738feae73d2d5c352e5f605fa" + } + }, + "buildifier_windows_amd64": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "urls": [ + "https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildifier-windows-amd64.exe" + ], + "downloaded_file_path": "buildifier.exe", + "executable": true, + "sha256": "da8372f35e34b65fb6d997844d041013bb841e55f58b54d596d35e49680fe13c" + } + }, + "buildifier_prebuilt_toolchains": { + "bzlFile": "@@buildifier_prebuilt~//:defs.bzl", + "ruleClassName": "_buildifier_toolchain_setup", + "attributes": { + "assets_json": "[{\"arch\":\"amd64\",\"name\":\"buildifier\",\"platform\":\"darwin\",\"sha256\":\"eeb47b2de27f60efe549348b183fac24eae80f1479e8b06cac0799c486df5bed\",\"version\":\"v6.4.0\"},{\"arch\":\"arm64\",\"name\":\"buildifier\",\"platform\":\"darwin\",\"sha256\":\"fa07ba0d20165917ca4cc7609f9b19a8a4392898148b7babdf6bb2a7dd963f05\",\"version\":\"v6.4.0\"},{\"arch\":\"amd64\",\"name\":\"buildifier\",\"platform\":\"linux\",\"sha256\":\"be63db12899f48600bad94051123b1fd7b5251e7661b9168582ce52396132e92\",\"version\":\"v6.4.0\"},{\"arch\":\"arm64\",\"name\":\"buildifier\",\"platform\":\"linux\",\"sha256\":\"18540fc10f86190f87485eb86963e603e41fa022f88a2d1b0cf52ff252b5e1dd\",\"version\":\"v6.4.0\"},{\"arch\":\"amd64\",\"name\":\"buildifier\",\"platform\":\"windows\",\"sha256\":\"da8372f35e34b65fb6d997844d041013bb841e55f58b54d596d35e49680fe13c\",\"version\":\"v6.4.0\"},{\"arch\":\"amd64\",\"name\":\"buildozer\",\"platform\":\"darwin\",\"sha256\":\"d29e347ecd6b5673d72cb1a8de05bf1b06178dd229ff5eb67fad5100c840cc8e\",\"version\":\"v6.4.0\"},{\"arch\":\"arm64\",\"name\":\"buildozer\",\"platform\":\"darwin\",\"sha256\":\"9b9e71bdbec5e7223871e913b65d12f6d8fa026684daf991f00e52ed36a6978d\",\"version\":\"v6.4.0\"},{\"arch\":\"amd64\",\"name\":\"buildozer\",\"platform\":\"linux\",\"sha256\":\"8dfd6345da4e9042daa738d7fdf34f699c5dfce4632f7207956fceedd8494119\",\"version\":\"v6.4.0\"},{\"arch\":\"arm64\",\"name\":\"buildozer\",\"platform\":\"linux\",\"sha256\":\"6559558fded658c8fa7432a9d011f7c4dcbac6b738feae73d2d5c352e5f605fa\",\"version\":\"v6.4.0\"},{\"arch\":\"amd64\",\"name\":\"buildozer\",\"platform\":\"windows\",\"sha256\":\"e7f05bf847f7c3689dd28926460ce6e1097ae97380ac8e6ae7147b7b706ba19b\",\"version\":\"v6.4.0\"}]" + } + }, + "buildifier_darwin_amd64": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "urls": [ + "https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildifier-darwin-amd64" + ], + "downloaded_file_path": "buildifier", + "executable": true, + "sha256": "eeb47b2de27f60efe549348b183fac24eae80f1479e8b06cac0799c486df5bed" + } + }, + "buildifier_darwin_arm64": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "urls": [ + "https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildifier-darwin-arm64" + ], + "downloaded_file_path": "buildifier", + "executable": true, + "sha256": "fa07ba0d20165917ca4cc7609f9b19a8a4392898148b7babdf6bb2a7dd963f05" + } + }, + "buildifier_linux_arm64": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "urls": [ + "https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildifier-linux-arm64" + ], + "downloaded_file_path": "buildifier", + "executable": true, + "sha256": "18540fc10f86190f87485eb86963e603e41fa022f88a2d1b0cf52ff252b5e1dd" + } + } + }, + "recordedRepoMappingEntries": [ + [ + "buildifier_prebuilt~", + "bazel_skylib", + "bazel_skylib~" + ], + [ + "buildifier_prebuilt~", + "bazel_tools", + "bazel_tools" + ] + ] + } + }, "@@platforms//host:extension.bzl%host_platform": { "general": { "bzlTransitiveDigest": "xelQcPZH8+tmuOHVjL9vDxMnnQNMlwj0SlvgoqBkm4U=", diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod index 35064f8a3d173..0e9e3035dd506 100644 --- a/WORKSPACE.bzlmod +++ b/WORKSPACE.bzlmod @@ -29,12 +29,6 @@ crt_register_toolchains(riscv32 = True) load("//third_party/github:repos.bzl", "github_tools_repos") github_tools_repos() -# Go Toolchain (needed by the Buildifier linter) -load("//third_party/go:repos.bzl", "go_repos") -go_repos() -load("//third_party/go:deps.bzl", "go_deps") -go_deps() - # Various linters load("//third_party/lint:repos.bzl", "lint_repos") lint_repos() diff --git a/quality/BUILD.bazel b/quality/BUILD.bazel index c00ea62df8e82..f0966daaf5844 100644 --- a/quality/BUILD.bazel +++ b/quality/BUILD.bazel @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0, see LICENSE for details. # SPDX-License-Identifier: Apache-2.0 -load("@bazelbuild_buildtools//buildifier:def.bzl", "buildifier", "buildifier_test") +load("@buildifier_prebuilt//:rules.bzl", "buildifier", "buildifier_test") load("@lowrisc_misc_linters//rules:rules.bzl", "licence_test") load("//rules:quality.bzl", "clang_format_check", "clang_format_test", "clang_tidy_rv_test", "clang_tidy_test", "html_coverage_report", "rustfmt_fix", "rustfmt_test") diff --git a/third_party/go/BUILD b/third_party/go/BUILD deleted file mode 100644 index 3e8bb41965a28..0000000000000 --- a/third_party/go/BUILD +++ /dev/null @@ -1,3 +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 diff --git a/third_party/go/deps.bzl b/third_party/go/deps.bzl deleted file mode 100644 index d877f5201dc4f..0000000000000 --- a/third_party/go/deps.bzl +++ /dev/null @@ -1,43 +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 - -load( - "@io_bazel_rules_go//go:deps.bzl", - "go_download_sdk", - "go_rules_dependencies", -) -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") - -def go_deps(): - go_download_sdk( - name = "go_sdk", - version = "1.19.1", - sdks = { - # NOTE: In most cases the whole sdks attribute is not needed. We use - # it to avoid the dependency on the index file for the - # SHA-256 checksums, which is downloaded via a `ctx.download` action - # which does not seem to cache files in the repository cache like - # the `ctx.download_and_extract` action does. Therefore, we avoid - # relying on `rules_go` to download the version and get the expected - # filenames and checksums from https://go.dev/dl/ manually. - "linux_amd64": ( - "go1.19.1.linux-amd64.tar.gz", - "acc512fbab4f716a8f97a8b3fbaa9ddd39606a28be6c2515ef7c6c6311acffde", - ), - "linux_arm64": ( - "go1.19.1.linux-arm64.tar.gz", - "49960821948b9c6b14041430890eccee58c76b52e2dbaafce971c3c38d43df9f", - ), - "darwin_amd64": ( - "go1.19.1.darwin-amd64.tar.gz", - "b2828a2b05f0d2169afc74c11ed010775bf7cf0061822b275697b2f470495fb7", - ), - "darwin_arm64": ( - "go1.19.1.darwin-arm64.tar.gz", - "e46aecce83a9289be16ce4ba9b8478a5b89b8aa0230171d5c6adbc0c66640548", - ), - }, - ) - go_rules_dependencies() - gazelle_dependencies() diff --git a/third_party/go/repos.bzl b/third_party/go/repos.bzl deleted file mode 100644 index 8b31ae9baa2b3..0000000000000 --- a/third_party/go/repos.bzl +++ /dev/null @@ -1,17 +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 - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -def go_repos(): - http_archive( - name = "io_bazel_rules_go", - sha256 = "6dc2da7ab4cf5d7bfc7c949776b1b7c733f05e56edc4bcd9022bb249d2e2a996", - urls = ["https://github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip"], - ) - http_archive( - name = "bazel_gazelle", - sha256 = "727f3e4edd96ea20c29e8c2ca9e8d2af724d8c7778e7923a854b2c80952bc405", - urls = ["https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.30.0/bazel-gazelle-v0.30.0.tar.gz"], - ) diff --git a/third_party/lint/repos.bzl b/third_party/lint/repos.bzl index 14cbefd227b77..b1cfa66da8d3a 100644 --- a/third_party/lint/repos.bzl +++ b/third_party/lint/repos.bzl @@ -12,13 +12,6 @@ def lint_repos(lowrisc_misc_linters = None): path = "hw/ip/prim/util/vendor/google_verible_verilog_syntax_py", ) - http_archive( - name = "bazelbuild_buildtools", - sha256 = "05c3c3602d25aeda1e9dbc91d3b66e624c1f9fdadf273e5480b489e744ca7269", - strip_prefix = "buildtools-6.4.0", - url = "https://github.com/bazelbuild/buildtools/archive/refs/tags/v6.4.0.tar.gz", - ) - http_archive_or_local( name = "lowrisc_misc_linters", local = lowrisc_misc_linters, diff --git a/util/prep-bazel-airgapped-build.sh b/util/prep-bazel-airgapped-build.sh index 953fe080f1f14..ad495b5dea121 100755 --- a/util/prep-bazel-airgapped-build.sh +++ b/util/prep-bazel-airgapped-build.sh @@ -141,7 +141,6 @@ if [[ ${AIRGAPPED_DIR_CONTENTS} == "ALL" || \ ${BAZELISK} fetch \ --repository_cache=${BAZEL_AIRGAPPED_DIR}/${BAZEL_CACHEDIR} \ //... \ - @go_sdk//... \ @lowrisc_rv32imcb_files//... \ @local_config_platform//... \ @python3_toolchains//... \