From 2edddd3a3c3219292e2180d3b29d134c311eaeeb Mon Sep 17 00:00:00 2001 From: Ryan Northey Date: Thu, 21 Mar 2024 11:52:25 +0000 Subject: [PATCH] ci/buildifier: Install and run with bazel Signed-off-by: Ryan Northey --- .bazelversion | 2 +- .github/workflows/format.yml | 13 +++---------- bazel/dependencies.bzl | 12 +++++++++++- bazel/repositories.bzl | 28 ++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/.bazelversion b/.bazelversion index 91ff5727..8a30e8f9 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -5.2.0 +5.4.0 diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index a09aa7a6..74b48758 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -66,17 +66,10 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: '^1.16' - - - name: Install dependencies - run: | - go install github.com/bazelbuild/buildtools/buildifier@latest - echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH" - - name: Format (buildifier) - run: find . -name "WORKSPACE" -o -name "*BUILD*" -o -name "*.bzl" | xargs -n1 buildifier -mode=check + run: | + BAZEL_FILES="$(find . -name "WORKSPACE" -o -name "*BUILD*" -o -name "*.bzl" | xargs -I{} echo ${PWD}/{})" + bazel run @com_github_bazelbuild_buildtools//buildifier -- --mode=check ${BAZEL_FILES} cargo_raze: name: check format with cargo-raze diff --git a/bazel/dependencies.bzl b/bazel/dependencies.bzl index 49db6d7b..4e6a3e29 100644 --- a/bazel/dependencies.bzl +++ b/bazel/dependencies.bzl @@ -12,8 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") load("@bazel-zig-cc//toolchain:defs.bzl", zig_register_toolchains = "register_toolchains") load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") +load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies") load("@proxy_wasm_cpp_host//bazel/cargo/wasmsign:crates.bzl", "wasmsign_fetch_remote_crates") load("@proxy_wasm_cpp_host//bazel/cargo/wasmtime:crates.bzl", "wasmtime_fetch_remote_crates") load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") @@ -21,10 +23,18 @@ load("@rules_fuzzing//fuzzing:init.bzl", "rules_fuzzing_init") load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies") load("@rules_python//python:pip.bzl", "pip_install") load("@rules_rust//rust:repositories.bzl", "rust_repositories", "rust_repository_set") +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains") -def proxy_wasm_cpp_host_dependencies(): +GO_VERSION = "1.20.3" + +# Set go_version=host to use host go +def proxy_wasm_cpp_host_dependencies(go_version = GO_VERSION): # Bazel extensions. + go_rules_dependencies() + go_register_toolchains(version = go_version) + gazelle_dependencies() + rules_foreign_cc_dependencies() rules_fuzzing_dependencies() diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 89b0900e..175d7ee0 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -19,6 +19,34 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") def proxy_wasm_cpp_host_repositories(): # Bazel extensions. + maybe( + http_archive, + name = "io_bazel_rules_go", + sha256 = "80a98277ad1311dacd837f9b16db62887702e9f1d1c4c9f796d0121a46c8e184", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.46.1/rules_go-v0.46.0.zip", + ], + ) + + maybe( + http_archive, + name = "bazel_gazelle", + sha256 = "32938bda16e6700063035479063d9d24c60eda8d79fd4739563f50d331cb3209", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.35.0/bazel-gazelle-v0.35.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.35.0/bazel-gazelle-v0.35.0.tar.gz", + ], + ) + + maybe( + http_archive, + name = "com_github_bazelbuild_buildtools", + urls = ["https://github.com/bazelbuild/buildtools/archive/v6.4.0.tar.gz"], + sha256 = "05c3c3602d25aeda1e9dbc91d3b66e624c1f9fdadf273e5480b489e744ca7269", + strip_prefix = "buildtools-6.4.0", + ) + maybe( http_archive, name = "bazel_skylib",