Skip to content

Fix: Define GPR_ASSERT macro for compatibility #660

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nikurt
Copy link

@nikurt nikurt commented May 16, 2025

Added a fallback definition for GPR_ASSERT using <assert.h> to handle cases where it is not predefined. This ensures smoother compilation and avoids potential issues with missing assertions.

Fixes #659

Copy link

ti-chi-bot bot commented May 16, 2025

Welcome @nikurt! It looks like this is your first PR to tikv/grpc-rs 🎉

@nikurt nikurt changed the title Define GPR_ASSERT macro to ensure compatibility. Fix: Define GPR_ASSERT macro for compatibility May 16, 2025
@nikurt nikurt closed this May 16, 2025
@nikurt nikurt reopened this May 16, 2025
Added a fallback definition for GPR_ASSERT using <assert.h> to handle cases where it is not predefined. This ensures smoother compilation and avoids potential issues with missing assertions.

Signed-off-by: Nikolay Kurtov <[email protected]>
Signed-off-by: Nikolay Kurtov <[email protected]>
@@ -66,6 +66,11 @@
#define GPR_CALLTYPE
#endif

#ifndef GPR_ASSERT
#include <assert.h>
Copy link
Member

Choose a reason for hiding this comment

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

How about switching to absl check just like what upstream did?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, haven't thought of that.

Observations:

  • absl/log/absl_check.h has a static assert that the C++ variant is at least C++14
  • ABSL_CHECK depends on using string_view = std::string_view which is only available in C++17.

Attempted a prototype #661 which upgrades C++ to C++14, but can't make it compile.

A different prototype #662 upgrades C++ to C++17 and it compiles.

Here is what happens with a C++14 upgrade:

% cargo build
   Compiling grpcio-sys v0.13.0+1.56.2-patched (/home/nkurtov/code/grpc-rs/grpc-sys)
warning: [email protected]+1.56.2-patched: In file included from /usr/include/absl/log/internal/nullstream.h:37,
warning: [email protected]+1.56.2-patched:                  from /usr/include/absl/log/internal/check_op.h:40,
warning: [email protected]+1.56.2-patched:                  from /usr/include/absl/log/internal/check_impl.h:19,
warning: [email protected]+1.56.2-patched:                  from /usr/include/absl/log/absl_check.h:38,
warning: [email protected]+1.56.2-patched:                  from grpc_wrap.cc:71:
warning: [email protected]+1.56.2-patched: /usr/include/absl/strings/string_view.h:53:26: error: 'string_view' in namespace 'std' does not name a type
warning: [email protected]+1.56.2-patched:    53 | using string_view = std::string_view;
warning: [email protected]+1.56.2-patched:       |                          ^~~~~~~~~~~
warning: [email protected]+1.56.2-patched: /usr/include/absl/strings/string_view.h:53:21: note: 'std::string_view' is only available from C++17 onwards
warning: [email protected]+1.56.2-patched:    53 | using string_view = std::string_view;
warning: [email protected]+1.56.2-patched:       |                     ^~~

Copy link
Member

Choose a reason for hiding this comment

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

I see. Upgrading C++ standard will introduce breaking change, let's keep it this way for now.

@nikurt nikurt requested a review from BusyJay May 22, 2025 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compilation error: GPR_ASSERT not found
2 participants