C H*_*C H 2 go bazel
我正在用 bazel + Gagelle 构建一个非常简单的 go 项目。
package main
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "Hello")
})
router.Run(":8080")
}
我的工作区:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "io_bazel_rules_go",
sha256 = "207fad3e6689135c5d8713e5a17ba9d1290238f47b9ba545b63d9303406209c6",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.24.7/rules_go-v0.24.7.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/v0.24.7/rules_go-v0.24.7.tar.gz",
],
)
http_archive(
name = "bazel_gazelle",
sha256 = "b85f48fa105c4403326e9525ad2b2cc437babaa6e15a3fc0b1dbab0ab064bc7c",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz",
],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load("//:deps.bzl", "go_dependencies")
# gazelle:repository_macro deps.bzl%go_dependencies
go_dependencies()
go_rules_dependencies()
go_register_toolchains()
gazelle_dependencies()
我的建筑
load("@bazel_gazelle//:def.bzl", "gazelle")
# gazelle:prefix github.com/myprojectXYZ/go-bazel
gazelle(name = "gazelle")
当我用瞪羚生成文件时,出现以下错误:
bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=deps.bzl%go_dependencies
...
...
ERROR: /private/var/tmp/_bazel_ch/c341ee081eec158c6db2e8b32b60c79e/external/io_bazel_rules_go/go/tools/builders/BUILD.bazel:48:10: no such package '@org_golang_x_tools//go/analysis/internal/facts': BUILD file not found in directory 'go/analysis/internal/facts' of external repository @org_golang_x_tools. Add a BUILD file to a directory to mark it as a package. and referenced by '@io_bazel_rules_go//go/tools/builders:nogo_srcs'
ERROR: Analysis of target '//:gazelle' failed; build aborted: Analysis failed
任何的想法 ?