英文:
Error with Go proto imports when using bazel-gazelle
问题
我有一个仓库,其中我使用了gazelle和proto build规则。我的仓库结构如下:
WORKSPACE
\ proto
- user.proto
- user_service.proto
- BUILD
这是我在proto文件夹中的BUILD
文件:
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_proto_grpc//go:defs.bzl", "go_proto_library")
package(default_visibility = ["//visibility:public"])
proto_library(
name = "user_proto",
srcs = ["user.proto"],
deps = [
"@com_google_protobuf//:timestamp_proto",
],
)
proto_library(
name = "user_service_proto",
srcs = ["user_service.proto"],
deps = [
":user_proto",
"@com_google_protobuf//:empty_proto",
],
)
go_proto_library(
name = "user_go_proto",
importpath = "github.com/abcd/user/proto",
protos = [":user_proto"],
)
go_proto_library(
name = "user_service_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/abcd/userservice/proto",
protos = [
":user_proto",
":user_service_proto",
],
)
这是我的user.proto
文件:
syntax = "proto3";
import "google/protobuf/timestamp.proto";
package some_package;
option go_package = "github.com/abcd/user/proto";
message User {
...
}
这是我的user_service.proto
文件:
syntax = "proto3";
import "proto/user.proto";
import "google/protobuf/empty.proto";
package some_package;
option go_package = "github.com/abcd/userservice/proto";
service UserService {
...
}
然后我运行bazel build proto:all
,期望go库能够成功构建,但实际上它们没有成功构建。
相反,我收到了一个错误,指出:
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
compilepkg: missing strict dependencies:
/private/var/tmp/_bazel_mohammednadeem/2fc3c21998c67019e72a996be754820f/sandbox/darwin-sandbox/581/execroot/__main__/bazel-out/darwin-fastbuild/bin/proto/user_service_go_proto_pb/github.com/abcd/userservice/proto/proto/user_service.pb.go: import of "github.com/abcd/user/proto"
No dependencies were provided.
Check that imports in Go sources match importpath attributes in deps.
我不太确定发生了什么。我的导入路径看起来是正确的,并且我在proto文件中设置了正确的option go_package
。
英文:
I have a repository where I'm using gazelle and proto build rules. My repository is structured like this:
WORKSPACE
\ proto
- user.proto
- user_service.proto
- BUILD
This is the BUILD
file I have inside my proto folder:
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_proto_grpc//go:defs.bzl", "go_proto_library")
package(default_visibility = ["//visibility:public"])
proto_library(
name = "user_proto",
srcs = ["user.proto"],
deps = [
"@com_google_protobuf//:timestamp_proto",
],
)
proto_library(
name = "user_service_proto",
srcs = ["user_service.proto"],
deps = [
":user_proto",
"@com_google_protobuf//:empty_proto",
],
)
go_proto_library(
name = "user_go_proto",
importpath = "github.com/abcd/user/proto",
protos = [":user_proto"],
)
go_proto_library(
name = "user_service_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/abcd/userservice/proto",
protos = [
":user_proto",
":user_service_proto",
],
)
This is my user.proto
file:
syntax = "proto3";
import "google/protobuf/timestamp.proto";
package some_package;
option go_package = "github.com/abcd/user/proto";
message User {
...
}
And this is my user_service.proto
file:
syntax = "proto3";
import "proto/user.proto";
import "google/protobuf/empty.proto";
package some_package;
option go_package = "github.com/abcd/userservice/proto";
service UserService {
...
}
I then run bazel build proto:all
and expect the go libraries to build successfully, but they do not.
Instead, I get an error stating that:
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
compilepkg: missing strict dependencies:
/private/var/tmp/_bazel_mohammednadeem/2fc3c21998c67019e72a996be754820f/sandbox/darwin-sandbox/581/execroot/__main__/bazel-out/darwin-fastbuild/bin/proto/user_service_go_proto_pb/github.com/abcd/userservice/proto/proto/user_service.pb.go: import of "github.com/abcd/user/proto"
No dependencies were provided.
Check that imports in Go sources match importpath attributes in deps.
I'm not really sure what's going on here. My importpaths look correct and I have the correct option go_package
set in the proto file.
答案1
得分: 1
问题是我需要在user_service_go_proto
目标中添加以下内容:
deps = [" :user_go_proto "]
英文:
The issue was that I needed
deps = [":user_go_proto"]
in the user_service_go_proto
target.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论