Bazel, Protobuf, gRPC, and Python example?

256 views
Skip to first unread message

hai...@grakn.ai

unread,
Oct 2, 2018, 9:52:37 AM10/2/18
to bazel-discuss
Hi everyone,

I've been struggling to get a comprehensive guide on how to use Bazel, Protobuf, gRPC, and Python together. There's also no official guide from the Bazel/GRPC docs.

Does anyone know any good examples on how to use all tools together? like a github repo?

Thank you!

Evan Jones

unread,
Oct 2, 2018, 10:45:20 AM10/2/18
to bazel-discuss
I think the "Python" part of this is going to cause you some pain. In particular, I was not really able to get the built-in Python rules to work with third-party PyPI dependencies the last I tried. I ended up writing my own set of Python rules. They "work" and it appears some other brave people are actually using them, but they definitely are not perfect.

The example project includes loading the grpc library and making a gRPC call, but it doesn't include rules to compile the protobufs; if you are interested I'm happy to share my rules for that also (which use the pre-compiled third-party Python tools, rather than compiling protoc from scratch)

Naresh R

unread,
Oct 8, 2018, 4:53:03 AM10/8/18
to bazel-discuss
Hey!

I had worked on gRPC + Python + Bazel this summer, so I might be able to shed some light on this. Building gRPC Python has been a request for about 2 years now. As of now, you _should be_ able to import gRPC as an external Bazel repository and use the 'grpcio' target for your purposes, but it's bound to be buggy as all tests have not been added/passed yet. There is no ETA, but please do track the above issue for milestones when we get there. As of now, apart from possible "gRPC Python with Bazel" bugs, there's surely a lot of work needed on the "Python with Bazel" end that need to be ironed out for this to work in all environements and setups.

In short, you CAN use the target given above (and please do report any issues you see or oh, come back with contributions!). Refer the official Bazel for Python wiki for quick examples on how to use the main Python rules and the experimental rules_python for pip imports.

Best,
Naresh

Sabir Ullah

unread,
Oct 22, 2018, 12:23:44 AM10/22/18
to bazel-discuss
HI it seems pleasure to see you . currently i am working on Tensorflow detection Api . i want to build .So files using this command: bazel build -c opt //tensorflow/contrib/android:libtensorflow_inference.so --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=armeabi-v7a 
but i am faced bazel build problem like this
ERROR: C:/users/sabir-pc/_bazel_sabir-pc/zp6kp3ov/external/com_google_absl/absl/strings/BUILD.bazel:32:1: C++ compilation of rule '@com_google_absl//absl/strings:strings' failed (Exit 1)
In file included from external/com_google_absl/absl/strings/internal/charconv_parse.cc:15:
In file included from external/com_google_absl\absl/strings/internal/charconv_parse.h:20:
external/com_google_absl\absl/strings/charconv.h:26:6: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions]
enum class chars_format {
     ^
external/com_google_absl\absl/strings/charconv.h:77:55: warning: use of enumeration in a nested name specifier is a C++11 extension [-Wc++11-extensions]
                                   chars_format fmt = chars_format::general);
                                                      ^
external/com_google_absl\absl/strings/charconv.h:81:55: warning: use of enumeration in a nested name specifier is a C++11 extension [-Wc++11-extensions]
                                   chars_format fmt = chars_format::general);
                                                      ^
external/com_google_absl\absl/strings/charconv.h:85:8: error: unknown type name 'constexpr'
inline constexpr chars_format operator&(chars_format lhs, chars_format rhs) {
       ^
external/com_google_absl\absl/strings/charconv.h:85:1: warning: inline variables are a C++17 extension [-Wc++17-extensions]
inline constexpr chars_format operator&(chars_format lhs, chars_format rhs) {
^
external/com_google_absl\absl/strings/charconv.h:85:30: error: expected ';' after top level declarator
inline constexpr chars_format operator&(chars_format lhs, chars_format rhs) {
                             ^
                             ;
In file included from external/com_google_absl/absl/strings/internal/charconv_parse.cc:15:
external/com_google_absl\absl/strings/internal/charconv_parse.h:26:6: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions]
enum class FloatType { kNumber, kInfinity, kNan };
     ^
external/com_google_absl\absl/strings/internal/charconv_parse.h:44:21: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
  uint64_t mantissa = 0;
                    ^
external/com_google_absl\absl/strings/internal/charconv_parse.h:50:16: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
  int exponent = 0;
               ^
external/com_google_absl\absl/strings/internal/charconv_parse.h:54:24: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
  int literal_exponent = 0;
                       ^
external/com_google_absl\absl/strings/internal/charconv_parse.h:57:18: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
  FloatType type = FloatType::kNumber;
                 ^
external/com_google_absl\absl/strings/internal/charconv_parse.h:67:30: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
  const char* subrange_begin = nullptr;
                             ^
external/com_google_absl\absl/strings/internal/charconv_parse.h:68:28: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
  const char* subrange_end = nullptr;
                           ^
external/com_google_absl\absl/strings/internal/charconv_parse.h:72:19: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
  const char* end = nullptr;
                  ^
external/com_google_absl\absl/strings/internal/charconv_parse.h:57:20: warning: use of enumeration in a nested name specifier is a C++11 extension [-Wc++11-extensions]
  FloatType type = FloatType::kNumber;
                   ^
In file included from external/com_google_absl/absl/strings/internal/charconv_parse.cc:22:
In file included from external/com_google_absl\absl/strings/internal/memutil.h:68:
In file included from external/com_google_absl\absl/base/port.h:23:
In file included from external/com_google_absl\absl/base/config.h:66:
external/com_google_absl\absl/base/policy_checks.h:77:2: error: "C++ versions less than C++11 are not supported."
#error "C++ versions less than C++11 are not supported."
 ^
In file included from external/com_google_absl/absl/strings/internal/charconv_parse.cc:22:
In file included from external/com_google_absl\absl/strings/internal/memutil.h:69:
In file included from external/com_google_absl\absl/strings/ascii.h:59:
In file included from external/com_google_absl\absl/strings/string_view.h:51:
external/com_google_absl\absl/base/internal/throw_delegate.h:39:2: error: expected expression
[[noreturn]] void ThrowStdLogicError(const std::string& what_arg);
 ^
external/com_google_absl\absl/base/internal/throw_delegate.h:39:14: error: expected unqualified-id
[[noreturn]] void ThrowStdLogicError(const std::string& what_arg);
             ^
external/com_google_absl\absl/base/internal/throw_delegate.h:40:2: error: expected expression
[[noreturn]] void ThrowStdLogicError(const char* what_arg);
 ^
external/com_google_absl\absl/base/internal/throw_delegate.h:40:14: error: expected unqualified-id
[[noreturn]] void ThrowStdLogicError(const char* what_arg);
             ^
external/com_google_absl\absl/base/internal/throw_delegate.h:41:2: error: expected expression
[[noreturn]] void ThrowStdInvalidArgument(const std::string& what_arg);
 ^
external/com_google_absl\absl/base/internal/throw_delegate.h:41:14: error: expected unqualified-id
[[noreturn]] void ThrowStdInvalidArgument(const std::string& what_arg);
             ^
external/com_google_absl\absl/base/internal/throw_delegate.h:42:2: error: expected expression
[[noreturn]] void ThrowStdInvalidArgument(const char* what_arg);
 ^
external/com_google_absl\absl/base/internal/throw_delegate.h:42:14: error: expected unqualified-id
[[noreturn]] void ThrowStdInvalidArgument(const char* what_arg);
             ^
external/com_google_absl\absl/base/internal/throw_delegate.h:43:2: error: expected expression
[[noreturn]] void ThrowStdDomainError(const std::string& what_arg);
 ^
external/com_google_absl\absl/base/internal/throw_delegate.h:43:14: error: expected unqualified-id
[[noreturn]] void ThrowStdDomainError(const std::string& what_arg);
             ^
external/com_google_absl\absl/base/internal/throw_delegate.h:44:2: error: expected expression
[[noreturn]] void ThrowStdDomainError(const char* what_arg);
 ^
external/com_google_absl\absl/base/internal/throw_delegate.h:44:14: error: expected unqualified-id
[[noreturn]] void ThrowStdDomainError(const char* what_arg);
             ^
external/com_google_absl\absl/base/internal/throw_delegate.h:45:2: error: expected expression
[[noreturn]] void ThrowStdLengthError(const std::string& what_arg);
 ^
external/com_google_absl\absl/base/internal/throw_delegate.h:45:14: error: expected unqualified-id
[[noreturn]] void ThrowStdLengthError(const std::string& what_arg);
             ^
external/com_google_absl\absl/base/internal/throw_delegate.h:46:2: error: expected expression
[[noreturn]] void ThrowStdLengthError(const char* what_arg);
 ^
external/com_google_absl\absl/base/internal/throw_delegate.h:46:14: error: expected unqualified-id
[[noreturn]] void ThrowStdLengthError(const char* what_arg);
             ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
13 warnings and 20 errors generated.
Target //tensorflow/contrib/android:libtensorflow_inference.so failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 261.977s, Critical Path: 19.43s
INFO: 212 processes: 212 local.
FAILED: Build did NOT complete successfully
So if u have a good knowledge pleas guide us

Sabir Ullah

unread,
Oct 22, 2018, 12:24:20 AM10/22/18
to bazel-discuss

Sabir Ullah

unread,
Oct 22, 2018, 12:24:49 AM10/22/18
to bazel-...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/31b0a60d-c769-4d83-87ba-f5795f76e17e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages