Skip to content

Latest commit

 

History

History
54 lines (44 loc) · 1.96 KB

L102-cpp-version-macros.md

File metadata and controls

54 lines (44 loc) · 1.96 KB

L102: New gRPC C++ version macros

Abstract

New public macros telling the version of gRPC C++ will be added to enable libraries and applications using gRPC C++ to behave differently depending on the gRPC C++ version at compile-time.

Background

It's a widely used code pattern to behave differenly based on the version information available at compile-time. Following is an example

#ifdef GRPC_CPP_VERSION_MAJOR
#  if GRPC_CPP_VERSION_MAJOR == 1
#    if GRPC_CPP_VERSION_MINOR >= 60
       // Use a new feature available from gRPC C++ 1.60
#    else
       // Do some workaround for gRPC C++ 1.59 or older
#    endif
#  else
       // New major version!
#  endif
#else
// Do some workaround for old gRPC C++
#endif

This has been asked by users (e.g #25556) and other Google OSS libraries (e.g. Abseil, Protobuf, and Cloud C++) already provide version macros so it makes sense that gRPC has similar ones.

Proposal

Following macros will be added to the grpcpp.h header file.

  • GRPC_CPP_VERSION_MAJOR: Major version part (e.g. 1)
  • GRPC_CPP_VERSION_MINOR: Minor version part (e.g. 46)
  • GRPC_CPP_VERSION_PATCH: Patch version part (e.g. 1)
  • GRPC_CPP_VERSION_TAG: Tag version part (e.g. empty or rc0)
  • GRPC_CPP_VERSION_STRING: Whole version string (1.46.1-rc0)

This changed is going to be reflected via grpc/grpc#31033.