mirror of
https://github.com/grpc/grpc.git
synced 2026-01-24 10:53:30 +08:00
3.1 KiB
3.1 KiB
gRPC C++ Gemini Collaboration Guide
This document outlines conventions and best practices for AI-assisted development in the gRPC C++ codebase.
Preferred Tools & Libraries
- Prefer gRPC types before absl.
- Prefer std types when available, use absl types when not
- Prefer
std::optionaloverabsl::optional - gRPC uses C++17, so we can't use C++20 onwards types.
- The Python implementation cannot depend on the protobuf library, so any shared libraries must expose a C-style API that does not rely on C++ protobuf types.
Code Style & Conventions
#include <grpc/support/port_platform.h>is not required unless its macros are needed for compilation.- Only include headers that are actively used.
- Abseil headers are sorted before gRPC headers.
- For public api headers (in
include/grpc) we use<grpc/...>.- Example:
#include <grpc/grpc.h>
- Example:
- Prefer explicit types over
std::pairorstd::tuplefor return types. - Use
LOG(ERROR)fromabsl/log/log.hfor logging errors, never usestd::cerrorgpr_log. - The
fuzztest.hheader is located atfuzztest/fuzztest.h.
About gRPC
- gRPC uses its own macros for Bazel libraries, tests, etc. Each directory should have a
grpc_packagedeclaration. For libraries usegrpc_cc_library, for testsgrpc_cc_test. - Dependencies on non-gRPC libraries (like gtest or absl) are listed in the
external_depsattribute. - The
:grpcBUILD target is not allowed to depend on the C++ protobuf library, either directly or transitively. - Build files for implementation code are typically located in
src/core/BUILDandBUILD. Do not add newBUILDfiles under thesrc/tree without explicit instruction. - Tests are located in
test/coreandtest/cpp(corresponding to thesrcdirectories). These test directories contain their ownBUILDfiles. - Fuzz tests use
fuzztest_maininstead ofgtest_main. - When depending on a
grpc_proto_library, the name of thecc_librarytarget is the same as thenameof thegrpc_proto_libraryrule itself, not[name]_cc_protoas one might expect from standard Bazelcc_proto_libraryrules. The build system error messages can be misleading in this case. - The 'gtest' external_dep also includes 'gmock'.
- All
upbrelated build rules (grpc_upb_proto_library,grpc_upb_proto_reflection_library) for protos defined anywhere in the repository must be defined in the rootBUILDfile. They should not be placed in theBUILDfile of the subdirectory where the proto is located. - Core end-to-end tests are defined in
test/core/end2end/BUILDusing thegrpc_core_end2end_test_suitemacro. This macro generates multiplegrpc_cc_testtargets by combining a configuration file (likeend2end_http2_config.cc) with individual test implementation files located intest/core/end2end/tests/. The final test target name is created by appending_testto thenameattribute of the macro. For example,grpc_core_end2end_test_suite(name = "end2end_http2", ...)generates the test target//test/core/end2end:end2end_http2_test. - Unused named parameters is a compilation failure.