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

api: generate c++ grpc stubs #3857

Closed
wants to merge 11 commits into from

Conversation

bplotnick
Copy link
Contributor

Signed-off-by: Ben Plotnick [email protected]

Description: Generate c++ grpc stubs
This passes use_grpc_plugin to pgv_cc_proto_library, which enables c++ grpc stubs to be generated. There are some necessary binds that need to be done unfortunately. This would be easier if we could do load("@com_github_grpc_grpc//bazel:grpc_deps", "grpc_deps"), but you can't load within a macro. I'm not sure if there's a better way to do this.

Note that bazel targets depping the _cc targets will also have to add these binds. Generally, they can call grpc_deps() as I mentioned before. But perhaps this should go in api_dependencies instead so that users can use that?

Risk Level: Low
Testing: We've been using this internally for a little while now and it works.

Signed-off-by: Ben Plotnick <[email protected]>
@mattklein123
Copy link
Member

@bplotnick can you merge master? There were flake fixes that went in.

@bplotnick
Copy link
Contributor Author

So i forgot to run the api tests (doh) and i think this is going to need a bit more work. The problem is the one I alluded to in the description. Now @envoy_api directly depends on com_github_grpc_grpc. The idea I had of moving grpc into api_dependencies is not going to quite work because of the way we dep libssl and cares.

@htuch
Copy link
Member

htuch commented Jul 15, 2018

@bplotnick why can't you do the load in https://github.com/envoyproxy/envoy/blob/master/api/bazel/repositories.bzl (at the top) and then make use of the grpc_deps in api_dependencies()?

@bplotnick
Copy link
Contributor Author

@htuch, that seems to make the bazel.api tests pass, but i'm confused as to how this works. The com_github_grpc_grpc external dep shouldn't actually be present in the @envoy_api workspace, since it is added in the @envoy workspace. What would happen for direct users of data-plane-api? Would they need to manually add the com_github_grpc_grpc external dep into their workspace?

The reason I didn't go down this route is that i thought I would've had to add the external dep in the same macro as the load. When i tried doing this, I ran into the same problem detailed here: bazelbuild/bazel#1550

My current approach that i'm trying (about to commit) is to move the _com_github_grpc_grpc() macro into the api and then do conditional loading for cares and libssl like is done in grpc_deps, but not use that function directly because (as mentioned above) i can't.

Btw, I'm still pretty new to Bazel, so please feel free to correct me if my terminology or understanding is wrong. Also, i'm happy to discuss this on Slack if you prefer that 😄

@bplotnick
Copy link
Contributor Author

@htuch I had another go at this and managed to get it working with the strategy I laid out before (moving the grpc dependency stuff to api_dependencies).

I pulled cares out of prebuilt and now build it in bazel using the BUILD file that grpc provides. It was failing for -Wold-style-cast, so i put a bunch of pragmas in place where we use the preprocessor macros. It's pretty ugly (and made uglier by check_format dedenting the pragmas) and i'd like to do this a different way, but i'm not sure how yet.

I also bumped grpc to 0.13.1 to pick up a workaround for bazel build failures on mac for grpc (grpc/grpc#13856). It required me to add -DGRPC_BAZEL_BUILD copt.

Lemme know what you think.

// Only expecting a single question.
// Only expecting a single question.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this seems pretty ugly. Can we fix the gRPC c-ares BUILD to do something similar to what we did in https://github.com/envoyproxy/envoy/blob/master/ci/prebuilt/BUILD#L9? This handles the includes as system includes IIRC, which avoids Wold-style-cast.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure how to get these as -isystem. I thought that what the grpc cares BUILD does should have done the trick, but apparently not.


_com_github_grpc_grpc()

def _com_github_grpc_grpc():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, what you've done is push a bunch of deps down into api/bazel, since we can then have a single API related setup Skylark function. This, to me, seems totally reasonable. the downside is we lose some of the nice machinery for managing repository locations that @jmillikin-stripe setup there. Ideally we also port that back into api/bazel, but that might be too much unrelated work for this PR. @jmillikin-stripe do you have any opinions as Envoy Bazel owner?

@htuch htuch requested a review from jmillikin-stripe July 23, 2018 01:05
@jmillikin-stripe
Copy link
Contributor

the downside is we lose some of the nice machinery for managing repository locations that @jmillikin-stripe setup there.

Can't we just move or copy the repository_locations stuff into api/bazel/? It's not a lot of code and isn't especially complex. As long as the Envoy folks want to keep the external dependency URLs declarative, I think it makes sense for the API build to match.

@bplotnick
Copy link
Contributor Author

@jmillikin-stripe I don't want to expand the scope of this PR so i'll tackle copying the build logic to api/bazel in separate PR.

Do you happen to know a better solution for the -Wold-style-cast issues?

@jmillikin-stripe
Copy link
Contributor

Does Clang stop warning about old-style casts if you use #include <ares.h> and #include <ares_dns.h>?

@bplotnick
Copy link
Contributor Author

@jmillikin-stripe that seemed to do the trick, thanks!

@htuch
Copy link
Member

htuch commented Jul 25, 2018

Yeah, that works. It's a bit ugly; we have inconsistent treatment of headers in include style. Can you add a TODO to fix this? Also, please at least add a TODO for porting the repository_locations.bzl infrastructure to bazel/api. Thanks.

@stale
Copy link

stale bot commented Aug 1, 2018

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label Aug 1, 2018
@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label Aug 8, 2018
@bplotnick
Copy link
Contributor Author

@htuch I finally got back to this PR. I added one TODO for porting the repository_locations.bzl logic, and I went ahead and made the ares includes consistently be system includes.

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, looks like there is merge conflicts and need to reconcile with #4047.

@@ -1,3 +1,5 @@
#include <ares.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not a big fan of this; it's inconsistent with the way we treat all other external dependencies, and the user might easily believe its coming from the system vs. the gRPC external dependency. Is there no way we can improve this (@jmillikin-stripe)? If not, we should put comments at each of these include sites to explain what's going on and the nature of this exception..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it'd make sense to use #include <> style for all external dependencies? The presence of "local"-style includes of external deps is fairly strange for C++ code, and IMO is an unwanted abstraction leak from the build system into the code being built.

@@ -2,7 +2,6 @@
# target in //ci/prebuilt/BUILD to the underlying build recipe in
# ci/build_container/build_recipes.
TARGET_RECIPES = {
"ares": "cares",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actual = "@com_github_cares_cares//:ares",
)

if "com_github_cares_cares" not in native.existing_rules():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about the @jmillikin-stripe ask regarding setting up the repository_locations.bzl infrastructure in api/bazel as well as in bazel?

@@ -1,5 +1,6 @@
GOOGLEAPIS_SHA = "d642131a6e6582fc226caf9893cb7fe7885b3411" # May 23, 2018
GOGOPROTO_SHA = "1adfc126b41513cc696b209667c8656ea7aac67c" # v1.0.0
GRPC_SHA = "befc7220cadb963755de86763a04ab6f9dc14200" # v1.13.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lizan recently bumped to 1.14. This also adds nanopb as a dep, see #4047.

@stale
Copy link

stale bot commented Aug 15, 2018

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label Aug 15, 2018
@stale
Copy link

stale bot commented Aug 22, 2018

This pull request has been automatically closed because it has not had activity in the last 14 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot closed this Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale stalebot believes this issue/PR has not been touched recently
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants