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

Support --include_source_info in native proto_library #56

Closed
htuch opened this issue Oct 26, 2017 · 10 comments
Closed

Support --include_source_info in native proto_library #56

htuch opened this issue Oct 26, 2017 · 10 comments
Assignees
Labels
duplicate This issue or pull request already exists

Comments

@htuch
Copy link

htuch commented Oct 26, 2017

It's useful to be able to specify an optional inclusion of source_code_info in the proto descriptors generated by proto_library, for the purpose of documentation generation tools etc. I was working on an aspect that used the proto_library output descriptors, and this is stripped away. It's useful to strip by default, but it would be also good to have a param to native.proto_library that allows us to specify targets that provide the source code info.

@cgrushko
Copy link

cgrushko commented Nov 2, 2017

We can add a global flag to control the command line created by proto_library (or switch proto_library's descriptor creating code to use a real proto_lang_toolchain instead of hardcoding).

I emphasize it being global - allowing some proto_library to have it and some not has two problems:

  1. it complicates the rule, which makes it harder to maintain and harder to use. I see better alternatives (see below)
  2. once people start relying on this for their compilation, they're in a world of pain - in order to depend add a dependency from your proto to another team's proto, you need to add this hypothetical attribute to all of the other proto's transitive dependencies. We had bad experience with this internally.

Alternative - modify your aspect to create a command line to compile srcs with the flag you need.

Anyway - I'm no longer on the proto project, though I'm happy to give my 2 cents.

@cgrushko cgrushko assigned lberki and unassigned cgrushko Nov 2, 2017
@htuch
Copy link
Author

htuch commented Nov 2, 2017

As a workaround, we switched the aspect to compile from srcs, but that loses some of the advantages that proto_library output descriptor sets have, in particular around taming the import path complexity (which gets tricky with externals).

What if we made the proto_library by default produce descriptor sets and then provide a stripped_proto_library (or something to that effect) that can reduce then remove the unnecessary source code info for those parts of a project that need a reduced size descriptor set?

@abscondment
Copy link

I'm running into the need for this, too. We have a plugin that does some code generation directed by comment-based annotations; without the source info, all of the annotations are missing.

@cgrushko
Copy link

@abscondment the recommended approach is to use proto options - they show up in the descriptor set and are verified by the compiler at build time.

@abscondment
Copy link

@cgrushko Neat - thanks for the pointer!

@cgrushko
Copy link

heh, I was getting ready for push back :) I realize the migration to options will take time, but I think the outcome will be better :)

@ashi009
Copy link

ashi009 commented Dec 22, 2017

I think global option is not ideal, as when generating doc/swagger from proto files, SourceCodeInfo is critical, and it's likely that a single build requires both stripped and unstripped descriptor set.

I'd prefer to have proto_library generate two sets of descriptor set, one with all SourceCodeInfo stripped out, and one with them. Say, adding a proto.unstripped_transitive_descriptor_sets next to the proto.transitive_descriptor_sets.

Whoever needs SourceCodeInfo can use proto.unstripped_transitive_descriptor_sets to create their rule, and I think bazel is smart enough not to build those unstripped descriptors if no one depends on them.

@ashi009
Copy link

ashi009 commented May 26, 2018

Hey @cgrushko and @lberki, is there any update on this FR?

I just stumbled into this issue again, as I found that I can't use pb.go files in bazel-bin to host godoc server as all the comments are stripped out. For this use case the proto extension option won't work for all the existing protoc-gen plugins.

@ashi009
Copy link

ashi009 commented Feb 28, 2019

ATM gapic now provides proto_library_with_info rule for doing this:

load("@com_google_api_codegen//rules_gapic:gapic.bzl", "proto_library_with_info")

proto_library(
    name = "iam_admin_proto",
    srcs = ["iam.proto"],
    deps = [
        "//google/api:annotations_proto",
        "//google/iam/v1:iam_policy_proto",
        "//google/iam/v1:policy_proto",
        "@com_google_protobuf//:empty_proto",
        "@com_google_protobuf//:field_mask_proto",
        "@com_google_protobuf//:timestamp_proto",
    ],
)

proto_library_with_info(
    name = "iam_admin_proto_with_info",
    deps = [":iam_admin_proto"],
)

Still, it would be nice to have this shipped with bazel natively.

@aiuto aiuto transferred this issue from bazelbuild/bazel May 13, 2020
@Yannic
Copy link
Collaborator

Yannic commented May 13, 2020

Duplicating into bazelbuild/bazel#9337

TL;DR: Bazel introduced --experimental_proto_descriptor_sets_include_source_info which passes --include_source_info when compiling the descriptor set of proto_library targets. It may become the default in the future.

@Yannic Yannic closed this as completed May 13, 2020
@Yannic Yannic added the duplicate This issue or pull request already exists label May 13, 2020
rickystewart added a commit to rickystewart/cockroach that referenced this issue Aug 12, 2021
This flag [instructs Bazel](bazelbuild/rules_proto#56 (comment))
to set a [command-line flag](protocolbuffers/protobuf#7623 (comment))
when invoking `protoc` that causes the generated proto descriptor sets
to contain extra info:

```
  --include_source_info       When using --descriptor_set_out, do not strip
                              SourceCodeInfo from the FileDescriptorProto.
                              This results in vastly larger descriptors that
                              include information about the original
                              location of each decl in the source file as
                              well as surrounding comments.
```

Setting this solves two problems:

1. We need the descriptor sets to have comments for cockroachdb#65814.
2. Without this change, generated `.pb.go` files from the sandbox won't
   contain comments. This makes the files more difficult to read and
   dirties the files in your checkout if you copy those `.pb.go` files
   to your workspace.

Also delete an unnecessary `--symlink_prefix=_bazel/` from the `test`
configuration (it's inherited from the `build` configuration so it's
redundant).

Release note: None
craig bot pushed a commit to cockroachdb/cockroach that referenced this issue Aug 12, 2021
68102: storage/storageccl: Add an option to break export mid key r=pbardea,sumeerbhola a=aliher1911

Previously when exporting ranges with very large number of versions
export could hit the situation where single key export would exceed
maximum export byte limit. To resolve this, safety threshold has to
be raised which could cause nodes going out of memory.

To address this, this patch adds an ability to stop and resume on
the arbitrary key timestamp so that it could be stopped mid key and
resumed later.

Release note: None

Fixes #68231

68390: ui: rebuild the databases pages r=matthewtodd a=matthewtodd

Previously, the databases pages featured an older, outdated design. This
change aligns their UX with that of the other modern pages in the DB
console, statements, transactions, and sessions.

This is a first pass at the job. We will return to layer on more
features, including search, and more data, including node & region
information.

Addresses #65737.

Before | After
--- | ---
<img width="1372" alt="Screen Shot 2021-08-05 at 4 54 31 PM" src="https://user-images.githubusercontent.com/5261/128420405-7a096c2f-32a1-42d9-a8f0-186f699fb612.png"> | <img width="1372" alt="Screen Shot 2021-08-03 at 2 50 12 PM" src="https://user-images.githubusercontent.com/5261/128070069-28d0f461-69dd-47cb-a04b-bc6cd0126ca4.png">
<img width="1372" alt="Screen Shot 2021-08-05 at 4 54 57 PM" src="https://user-images.githubusercontent.com/5261/128420491-71d03570-1c0d-413b-ab40-09b45cf614ee.png"> | <img width="1372" alt="Screen Shot 2021-08-03 at 2 50 21 PM" src="https://user-images.githubusercontent.com/5261/128070090-bd62d125-a1b2-4c83-b0a5-33d0723849eb.png">
<img width="1372" alt="Screen Shot 2021-08-05 at 5 03 37 PM" src="https://user-images.githubusercontent.com/5261/128420959-338ea79b-abf0-4773-91bf-cecac64fec5f.png"> | (This overview of database grants no longer exists.)
(This rolled-up view of table grants did not previously exist.) | <img width="1372" alt="Screen Shot 2021-08-03 at 2 50 27 PM" src="https://user-images.githubusercontent.com/5261/128070100-1305c94f-c017-40a5-ba2d-f19fd61bdecf.png">
<img width="1372" alt="Screen Shot 2021-08-05 at 4 55 21 PM" src="https://user-images.githubusercontent.com/5261/128420596-2d9f04ad-718c-4dce-b045-b5647f718339.png"> | <img width="1372" alt="Screen Shot 2021-08-03 at 2 50 35 PM" src="https://user-images.githubusercontent.com/5261/128070103-831fd5c3-38da-4864-9d82-9091f3209606.png">
<img width="1372" alt="Screen Shot 2021-08-05 at 4 55 28 PM" src="https://user-images.githubusercontent.com/5261/128420658-4042c631-b283-4b0c-ac4a-3235bd3bcf39.png"> | <img width="1372" alt="Screen Shot 2021-08-03 at 2 50 41 PM" src="https://user-images.githubusercontent.com/5261/128070113-73528f2c-56bf-4fcf-a8d8-fcc3f100695f.png">

Release note (ui change): The databases pages in the DB console were
updated to bring them into alignment with our modern UX.

68619: storage: add file storing min version needed for backwards compatibility r=jbowens a=andyyang890

A new STORAGE_MIN_VERSION file containing the minimum version that the
storage engine needs to maintain backwards compatibility with will be
added to the directory for each storage engine. This will be used in
the encryption-at-rest registry migration.

Release note: None

68621: dev: implement `dev generate docs` r=rail a=rickystewart

Do some refactoring so that we don't have to repeat code in a bunch of
places. The implementation is pretty straightforward and just involves
building the docs then copying them over to the workspace.

Closes #68563.

Release note: None

68663: dev: hoist generated code out of sandbox into workspace r=rail a=rickystewart

(Only the most recent commit applies for this review.)

One might be expected that this command be implemented as
`dev generate protobuf` or `dev generate execgen` or similar, but that's
not really practical for a couple reasons:

1. Building all the protobuf in-tree isn't really possible on its own:
   see #58018 (comment).
2. For non-proto generated code, one can imagine that we do a bunch of
   `bazel query`s to list all the generated files in tree and to find
   which files are generated. Given that there are hundreds of generated
   files in tree, and a single `bazel query` can take ~1s, this is not
   tractable.

The implementation here is ad-hoc and a bit hacky. Basically we search
`bazel-bin` for files ending in `.go` and apply some heuristics to
figure out whether they should be copied and where those files should
go.

This is gated behind a feature flag for now because actually copying
these files into the workspace right now dirties a ton of files. (The
diffs are benign -- mostly comments.) We can flip this option to be on
by default when it's safe (probably after the `Makefile` is deleted).

Closes #68565.

Release note: None

68806: bazel: set `--include_source_info` when generating protobuf code r=rail a=rickystewart

This flag [instructs Bazel](bazelbuild/rules_proto#56 (comment))
to set a [command-line flag](protocolbuffers/protobuf#7623 (comment))
when invoking `protoc` that causes the generated proto descriptor sets
to contain extra info:

```
  --include_source_info       When using --descriptor_set_out, do not strip
                              SourceCodeInfo from the FileDescriptorProto.
                              This results in vastly larger descriptors that
                              include information about the original
                              location of each decl in the source file as
                              well as surrounding comments.
```

Setting this solves two problems:

1. We need the descriptor sets to have comments for #65814.
2. Without this change, generated `.pb.go` files from the sandbox won't
   contain comments. This makes the files more difficult to read and
   dirties the files in your checkout if you copy those `.pb.go` files
   to your workspace.

Also delete an unnecessary `--symlink_prefix=_bazel/` from the `test`
configuration (it's inherited from the `build` configuration so it's
redundant).

Release note: None

Co-authored-by: Oleg Afanasyev <oleg@cockroachlabs.com>
Co-authored-by: Matthew Todd <todd@cockroachlabs.com>
Co-authored-by: Andy Yang <ayang@cockroachlabs.com>
Co-authored-by: Ricky Stewart <ricky@cockroachlabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

6 participants