如何修复compilepkg:构建Bazel项目时缺少对golang.org/x/sys/unix的严格依赖?

问题描述 投票:0回答:1

我正在尝试在我的电脑上运行此存储库的本地版本。我使用的是 Debian 12,并安装了 Bazel v6.4.0 和 Go v1.21.5。我对 Go 不太熟悉,对 Bazel 更不熟悉。

当我运行设置说明中建议的命令来构建项目时,即

bazel //...
,我收到以下错误:

DEBUG: /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/bazel_gazelle/internal/go_repository.bzl:184:18: org_golang_google_grpc: gazelle: finding module path for import golang.org/x/sys/unix: exit status 1: go: finding module for package golang.org/x/sys/unix
go: found golang.org/x/sys/unix in golang.org/x/sys v0.15.0
found packages unix (affinity_linux.go) and main (mkasm.go) in /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/bazel_gazelle_go_repository_cache/pkg/mod/golang.org/x/[email protected]/unix
gazelle: finding module path for import golang.org/x/sys/unix: exit status 1: go: finding module for package golang.org/x/sys/unix
go: found golang.org/x/sys/unix in golang.org/x/sys v0.15.0
found packages unix (affinity_linux.go) and main (mkasm.go) in /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/bazel_gazelle_go_repository_cache/pkg/mod/golang.org/x/[email protected]/unix
gazelle: finding module path for import golang.org/x/sys/unix: exit status 1: go: finding module for package golang.org/x/sys/unix
go: found golang.org/x/sys/unix in golang.org/x/sys v0.15.0
found packages unix (affinity_linux.go) and main (mkasm.go) in /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/bazel_gazelle_go_repository_cache/pkg/mod/golang.org/x/[email protected]/unix
gazelle: finding module path for import golang.org/x/sys/unix: exit status 1: go: finding module for package golang.org/x/sys/unix
go: found golang.org/x/sys/unix in golang.org/x/sys v0.15.0
found packages unix (affinity_linux.go) and main (mkasm.go) in /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/bazel_gazelle_go_repository_cache/pkg/mod/golang.org/x/[email protected]/unix
gazelle: finding module path for import golang.org/x/sys/unix: exit status 1: go: finding module for package golang.org/x/sys/unix
go: found golang.org/x/sys/unix in golang.org/x/sys v0.15.0
found packages unix (affinity_linux.go) and main (mkasm.go) in /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/bazel_gazelle_go_repository_cache/pkg/mod/golang.org/x/[email protected]/unix
gazelle: finding module path for import golang.org/x/sys/unix: exit status 1: go: finding module for package golang.org/x/sys/unix
go: found golang.org/x/sys/unix in golang.org/x/sys v0.15.0
found packages unix (affinity_linux.go) and main (mkasm.go) in /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/bazel_gazelle_go_repository_cache/pkg/mod/golang.org/x/[email protected]/unix
gazelle: finding module path for import golang.org/x/sys/unix: exit status 1: go: finding module for package golang.org/x/sys/unix
go: found golang.org/x/sys/unix in golang.org/x/sys v0.15.0
found packages unix (affinity_linux.go) and main (mkasm.go) in /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/bazel_gazelle_go_repository_cache/pkg/mod/golang.org/x/[email protected]/unix
gazelle: finding module path for import golang.org/x/sys/unix: exit status 1: go: finding module for package golang.org/x/sys/unix
go: found golang.org/x/sys/unix in golang.org/x/sys v0.15.0
found packages unix (affinity_linux.go) and main (mkasm.go) in /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/bazel_gazelle_go_repository_cache/pkg/mod/golang.org/x/[email protected]/unix
gazelle: finding module path for import golang.org/x/sys/unix: exit status 1: go: finding module for package golang.org/x/sys/unix
go: found golang.org/x/sys/unix in golang.org/x/sys v0.15.0
found packages unix (affinity_linux.go) and main (mkasm.go) in /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/bazel_gazelle_go_repository_cache/pkg/mod/golang.org/x/[email protected]/unix
gazelle: finding module path for import golang.org/x/sys/unix: exit status 1: go: finding module for package golang.org/x/sys/unix
go: found golang.org/x/sys/unix in golang.org/x/sys v0.15.0
found packages unix (affinity_linux.go) and main (mkasm.go) in /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/bazel_gazelle_go_repository_cache/pkg/mod/golang.org/x/[email protected]/unix
gazelle: finding module path for import golang.org/x/sys/unix: exit status 1: go: finding module for package golang.org/x/sys/unix
go: found golang.org/x/sys/unix in golang.org/x/sys v0.15.0
found packages unix (affinity_linux.go) and main (mkasm.go) in /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/bazel_gazelle_go_repository_cache/pkg/mod/golang.org/x/[email protected]/unix
gazelle: finding module path for import golang.org/x/sys/unix: exit status 1: go: finding module for package golang.org/x/sys/unix
go: found golang.org/x/sys/unix in golang.org/x/sys v0.15.0
found packages unix (affinity_linux.go) and main (mkasm.go) in /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/bazel_gazelle_go_repository_cache/pkg/mod/golang.org/x/[email protected]/unix
INFO: Analyzed 131 targets (171 packages loaded, 1946 targets configured).
INFO: Found 131 targets...
ERROR: /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/external/com_github_sirupsen_logrus/BUILD.bazel:3:11: GoCompilePkg external/com_github_sirupsen_logrus/go_default_library.a failed: (Exit 1): builder failed: error executing command (from target @com_github_sirupsen_logrus//:go_default_library) bazel-out/k8-opt-exec-2B5CBBC6-ST-625e526ca8a8/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64 -src external/com_github_sirupsen_logrus/alt_exit.go -src ... (remaining 45 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
compilepkg: missing strict dependencies:
        /home/henry/.cache/bazel/_bazel_henry/cefbbfcdd1c1bdf63e873be5150774b3/sandbox/linux-sandbox/183/execroot/__main__/external/com_github_sirupsen_logrus/terminal_check_unix.go: import of "golang.org/x/sys/unix"
No dependencies were provided.
Check that imports in Go sources match importpath attributes in deps.
INFO: Elapsed time: 12.435s, Critical Path: 0.96s
INFO: 31 processes: 12 internal, 19 linux-sandbox.
FAILED: Build did NOT complete successfully

我尝试将以下内容添加到 WORKSPACE 文件中,但会导致相同的错误

go_repository(
    name = "org_golang_x_sys",
    importpath = "github.com/golang/sys",
    commit = "13b15b780d9013988b1fb0e79e30b2528a877638",
)
使用通常的 Go 导入过程,

导入

golang.org/x/sys/unix
在我系统的其他地方工作得很好,所以我认为这与 Bazel 配置有关。 Bazel 专家可以帮我解决这个问题吗?

go build bazel
1个回答
0
投票

事实证明我是对的,但没有正确地将存储库添加到

WORKSPACE
文件中。

运行

bazel run //:gazelle -- update-repos golang.org/x/[email protected]
将以下行添加到我的
WORKSPACE
文件中,并且构建成功。

go_repository(
    name = "org_golang_x_sys",
    importpath = "golang.org/x/sys",
    sum = "h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=",
    version = "v0.13.0",
)
© www.soinside.com 2019 - 2024. All rights reserved.