Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question: proto importpath #1825

Closed
hawkingrei opened this issue Nov 20, 2018 · 4 comments
Closed

question: proto importpath #1825

hawkingrei opened this issue Nov 20, 2018 · 4 comments
Labels

Comments

@hawkingrei
Copy link
Contributor

Now we have a compilable project by using bazel.it's file layout looks like this.

~/go/src/go-common/app/a/1.proto
~/go/src/go-common/app/b/2.proto

it is very easy to make it runnable.but this proto‘s import must look like this.

~/go/src/go-common/app/a/1.proto:

import "app/b/2.proto";

but we know golang import has go-common prefix. my colleague hopes that golang import and proto import have same rule.so when I add go-common prefix at proto's import. it fails to build.

go-common/app/service/live/xuser/api/grpc/xuser.proto: File not found.
app/service/live/xuser/api/grpc/v1/guard.proto: Import "go-common/app/service/live/xuser/api/grpc/xuser.proto" was not found or had errors.

How to accompish this goal?

@jayconrod
Copy link
Contributor

Do you have option go_package statements in your proto files? For example, in 1.proto:

syntax = "proto3";

package app.a;

option go_package = "go-common/app/a";

In the go_proto_library rule for this proto, the importpath attribute should match the string in go_package. From another Go library, you would then import it as:

package foo

import "go-common/app/a"

@hawkingrei
Copy link
Contributor Author

Sorry, I do not clearly describe the problem.so i make a example. now it is compilable.it only have proto without any pb.go file.

guard.proto and vip.proto own a same import.

import "app/service/live/xuser/api/grpc/xuser.proto";

I hope that that import can own a prefix that looks like this.

import "go-common/app/service/live/xuser/api/grpc/xuser.proto";

I can add this go-common prefix to build successfully by using go-build and protoc without bazel. but I wish to complete by bazel.

@jayconrod
Copy link
Contributor

Unfortunately, I don't think it's possible. Kubernetes wants the same thing: their proto imports start with k8s.io/kubernetes, but there isn't a directory with that name in their repository. They haven't been able to switch to go_proto_library because of that. It's fundamentally a problem with proto_library, which is built into Bazel itself, so harder to change. The tracking issue for this is bazelbuild/bazel#3867.

proto_library does have a proto_source_root attribute, which lets you strip off part of the import path. Unfortunately, I don't think that's quite what you want.

@hawkingrei
Copy link
Contributor Author

it is solved by bazel 0.22.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants