-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Please add proto_library attrs to adjust its "virtual path" #3867
Comments
I second this request: I've been using |
@cgrushko for further triaging. |
I passed the
|
(1) Done. Without the proposed new attribute, all proto imports use the "relative" path of the .proto file within the original repository -- this has a high chance of name conflicts. (2) My gut instinct is "no", because external dependency names are not required to be globally stable or consistent. It also ties the .proto file content very tightly with Bazel, which is undesirable for projects that need to support multiple build systems. |
I think this might also be relevant for multi-module maven projects that are being converted in place.
I know the above works because of details of how the protos are stuffed into jars and whatnot, but it is all default stuff. I would love an easy solution to non-invasively building this tree with bazel just by dropping in BUILD files. This ticket looks about right, but I would be glad to be corrected. Here is what I imagine it would look like: In proto_library(
name = "a_proto",
srcs = ["src/main/proto/a.proto"],
strip_import_prefix = "src/main/proto",
) In proto_library(
name = "whatsit_proto",
srcs = ["src/main/proto/b.proto"],
strip_import_prefix = "src/main/proto",
deps = ["//module-a:a_proto"],
) What do you think? Have I missed something really easy here? |
Hi there; just to chime in - this issue is preventing us vendoring proto libraries which depend on other proto libraries in go projects - see bazel-contrib/rules_go#900. A good example is the go Kubernetes Client library. Is there any chance someone might work on this any time soon, or should I take a stab? |
I just got hit by this in bazel-contrib/bazel-gazelle#162 and have worked around it by forking k8s.io/api and k8s.io/apimachinery to my own account and deleting all of the proto files within them! Trying to add client-go to my repo has been a source of a lot of pain over the last week while I tried to get other bazel-related blockers fixed for this one goal of getting client-go to build. I keep having to delete files from forks in order to move forward. (e.g. my workaround for kubernetes/publishing-bot#49 before it was done in the repo's that publishing-bot controls) |
Any chance this could be implemented soon? This blocks Kubernetes and a number of related projects from using |
Is there a timeline for this? This feature would save us a lot of pain as well. |
Bump, please fix soon. Lots of people are running into this in the Go community. Currently, I'm advising people to check in generated .pb.go files and avoid using |
Friendly ping! This issue seems to be affecting a number of projects. |
Pinging @lberki since hopefully he knows about proto rules. |
I have a rough attempt at this feature in #5536 |
Update: I'm almost done with tidying up the implementation of |
Update: please take a look at the rough draft I have here: https://github.com/lberki/bazel/ The syntax is discernible from the test case -- it essentially adds a We are cutting 0.21 sometime early next week, so please test it so that I know if I got something wrong! The code is still very rough and untested and contains some hacks, but the functionality should be fully there. |
Just tested that branch, seems to be working in a few quick tests. @jayconrod will want to do tests with Gazelle to verify it can handle the Kubernetes case. I found the syntax |
@jmillikin-stripe , I entirely agree that this isn't very intuitive. However, |
Oh wow, you're right -- sorry! Must have some old cobwebs still sticking around. |
/cc @haberman |
Update: some concerns were raised that |
If a less powerful version of those two is merged, I'm going to open a new issue asking for the full-power version. Bazel should be useful for building code that depends on third-party dependencies, even if those dependencies are not compliant with Protobuf best practices regarding import paths. Specifically: the custom Starlark go_proto_library I wrote to get this feature supports both, and I use all combinations of [add, strip, strip+add] to build some of our more complex tools, so the requested power is the minimum required to switch to the builtin proto_library rule. |
Update: the full version of this change (stripping + adding prefixes) was merged in the change above and should be in 0.22 . Build a Bazel at HEAD To give it a spin ahead of time! |
import prefix and strip import prefix needed to be set because of: bazelbuild/bazel#3867 resolve directives are to work around bugs/limitations in gazelle and were manually crafted from looking at package names in the proto files. resolve directives require specifying both a source-lang and import-lang despite it being the same because of another bug/limitation within gazelle Generate protos with: gazelle update -repo_root `pwd` && \ find . -type f -name "BUILD.bazel" -print0 | xargs -0 sed -i '' -e 's#//github.com/yext/cloudprober/#//#g'
import prefix and strip import prefix needed to be set because of: bazelbuild/bazel#3867 resolve directives are to work around bugs/limitations in gazelle and were manually crafted from looking at package names in the proto files. resolve directives require specifying both a source-lang and import-lang despite it being the same because of another bug/limitation within gazelle Generate protos with: gazelle update -repo_root `pwd` && \ find . -type f -name "BUILD.bazel" -print0 | xargs -0 sed -i '' -e 's#//github.com/yext/cloudprober/#//#g'
The readme currently references this issue despite it apparently being fixed already. |
* bazelbuild/bazel#3867 is fixed, so instructions for vendored proto files need to be updated. * proto_library is now provided by rules_proto, not built-in.
bazelbuild/bazel#3867 is fixed, so instructions for vendored proto files need to be updated.
bazelbuild/bazel#3867 is fixed, so instructions for vendored proto files need to be updated.
bazelbuild/bazel#3867 is fixed, so instructions for vendored proto files need to be updated.
When a .proto file contains
import "foo/bar/baz.proto"
, that path doesn't actually have to exist as-is on the filesystem. It can be mapped to any arbitrary path by protoc by using an equals sign in--proto_path
:protoc --proto_path=foo/bar/baz.proto=some/other/path.proto
.Please add attributes to
proto_library()
to adjust the virtual path used to locate its source proto, similar to howcc_library()
allows changing the include path. Good attributes would be:import_prefix
to add a prefix to the virtual path.strip_import_prefix
to remove a prefix from the virtual path.The main use case is cross-repo includes, where we want to use nice short names in the filesystem but URL-prefixed names in the import paths:
The text was updated successfully, but these errors were encountered: