Search code examples
protocol-buffersgrpcbazel

Error with compiling protobuf while grpc c++ building


I`m trying to build gRPC C++ with bazel as in the guide https://github.com/grpc/grpc/blob/master/BUILDING.md but I have this error

PS D:\programming\cpp\grpc> bazel build --enable_bzlmod=false :all
Starting local Bazel server and connecting to it...
DEBUG: C:/users/oleg0/_bazel_oleg0/7mt2iksj/external/com_google_protobuf/bazel/system_python.bzl:230:14: WARNING: no system python available, builds against system python will fail
WARNING: C:/users/oleg0/_bazel_oleg0/7mt2iksj/external/google_cloud_cpp/google/cloud/BUILD.bazel:53:15: in config_setting rule @google_cloud_cpp//google/cloud:enable_opentelemetry_valid-transition: target '@google_cloud_cpp//google/cloud:enable_opentelemetry_valid-transition' depends on deprecated target '@google_cloud_cpp//:enable-experimental-opentelemetry': this flag is now GA, please use //:enable_opentelemetry instead.
WARNING: C:/users/oleg0/_bazel_oleg0/7mt2iksj/external/google_cloud_cpp/google/cloud/BUILD.bazel:62:15: in config_setting rule @google_cloud_cpp//google/cloud:disable_opentelemetry: target '@google_cloud_cpp//google/cloud:disable_opentelemetry' depends on deprecated target '@google_cloud_cpp//:enable-experimental-opentelemetry': this flag is now GA, please use //:enable_opentelemetry instead.
INFO: Analyzed 186 targets (214 packages loaded, 6683 targets configured).
INFO: Found 186 targets...
ERROR: C:/users/oleg0/_bazel_oleg0/7mt2iksj/external/com_google_protobuf/src/google/protobuf/compiler/rust/BUILD.bazel:50:11: Compiling src/google/protobuf/compiler/rust/accessors/unsupported_field.cc [for tool] failed: (Exit 2): cl.exe failed: error executing command (from target @com_google_protobuf//src/google/protobuf/compiler/rust:accessors) C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE ... (remaining 67 arguments skipped)
unsupported_field.cc
external/com_google_protobuf/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc(9): fatal error C1083: google/protobuf/compiler/rust/accessors/accessor_generator.h: No such file or directory,
ERROR: D:/programming/cpp/grpc/src/proto/grpc/reflection/v1alpha/BUILD:25:19 Compiling src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.cc failed: (Exit 2): cl.exe failed: error executing command (from target @com_google_protobuf//src/google/protobuf/compiler/rust:accessors) C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE ... (remaining 67 arguments skipped)
INFO: Elapsed time: 34.995s, Critical Path: 3.65s
INFO: 9 processes: 9 internal.
FAILED: Build did NOT complete successfully

bazel 6.4.0 grpc v1.62.1

What I did: Updated submodules git submodule update --init And

setx BAZEL_VC_FULL_VERSION 16.11.34
setx BAZEL_VC "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC"

Solution

  • I fixed it! But I used Cmake instead of Bazel https://habr.com/ru/companies/infopulse/articles/265805/

    • Go to the grpc\third_party\protobuf\cmake folder and create a build folder there, go to it.
    • Execute the command cmake -G "Visual Studio 16 2019" (or your version of VS)
    • Open the protobuf.sln file created in the previous step in Visual Studio and assemble (F7). At this stage, we receive valuable artifacts - the protoc.exe utility, which we will need to generate data serialization/deserialization code and lib files, which will be needed when linking gRPC.
    • Copy the grpc\third_party\protobuf\cmake\build\Debug folder to the grpc\third_party\protobuf\cmake folder. Once again, the Debug folder needs to be copied 1 level higher. This is some kind of inconsistency in the gRPC and Protobuf documentation. Protobuf says that everything needs to be built in the build folder, but the sources of gRPC projects do not know anything about this folder and look for Protobuf libraries directly in grpc\third_party\protobuf\cmake\Debug
    • Then go to grpc root, create folder cmake/build, go to, then build grpc with Cmake in grpc root folder cmake ../.. -G «Visual Studio 16 2019»
    • Find grpc.sln file and build it