Build gRPC development environment under Windows (MinGW)

Compile gRPC through MinGW under Windows, and compile and test the officially provided Demo. This article records the whole process from setting up the gRPC development environment to compiling, and finally testing the sample program. The test results show that the configuration process is correct. At the same time, this article can provide netizens with an idea and reference for using MinGW to compile gRPC, and avoid detours.

What are RPCs?

RPC (Remote Procedure Call Protocol) remote procedure call protocol. A popular description is: the client calls an object that exists on a remote computer without knowing the details of the call, just like calling an object in a local application.

A more formal description is: a protocol for requesting services from a remote computer program over a network without requiring knowledge of the underlying network technology.


Commonly used RPC framework?

  • Thrift : thrift is a software framework for the development of scalable and cross-language services. It combines a powerful software stack and code generation engine to build on C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, and OCaml programming languages Seamlessly integrated and efficient service.

  • gRPC : Originally developed by Google, it is a language-neutral, platform-neutral, open source remote procedure call (RPC) system.

  • Dubbo : Dubbo is a distributed service framework and SOA governance solution. Its functions mainly include: high-performance NIO communication and multi-protocol integration, service dynamic addressing and routing, soft load balancing and fault tolerance, dependency analysis and degradation, etc. Dubbo is the core framework of Alibaba's internal SOA service-based governance solution. Dubbo has been used by many non-Alibaba companies since it was open sourced in 2011.

  • Spring Cloud : Spring Cloud consists of many sub-projects, such as Spring Cloud Config, Spring Cloud Netflix, Spring Cloud Consul, etc. It provides common tools for building distributed systems and microservices, such as configuration management, service discovery, circuit breakers, and intelligent routing , micro-agent, control bus, one-time token, global lock, master election, distributed session and cluster state, etc., satisfying all the solutions required for building microservices. Spring Cloud is based on Spring Boot, which makes development and deployment extremely simple.

1. Installation of development environment and other tools

1.1 Test environment

  • Operating system: Windows11 22H2
  • Terminal Tools: Powershell (included with Windows)
  • Other tools: Git (manually installed and needs to be added to the PATH environment variable, the installation process will not be explained below)

1.2 CMake installation

Since gRPC relies on CMake for code construction when compiling, CMake needs to be installed. The latest version of CMake is used here, the version is 3.25.0-rc2, and the installation steps are as follows:

1. CMake download

Two, CMake installation

Double-click the installation package, you need to check "Add CMake to system PATH for all users" during the installation process , other installation steps will not be repeated.

image

3. Verify the installation result

Open the terminal and enter cmake --versionto view the version number:

image

1.3 MinGW installation

The latest version of the w64devkit development kit is used here. The latest version is 1.16.1, which contains the following tools:

  • GCC 12.2.0
  • busybox-w32 FRP-4716
  • GDB 10.2
  • Mingw-w64 10.0.0
  • GNU Make 4.2
  • Vim 9.0
  • Universal Ctags 20200824
  • NASM 2.15.05
  • binutils 2.39
  • Cppcheck 2.8

The installation steps are as follows:

1. Download w64devkit

2. Add environment variables

After the download is complete, unzip the compressed package and add the bin directory in the folder to the PATH environment variable. This step will not be discussed

After the addition is complete, verify that MinGW is added to PATH:

image


2. gRPC installation

The source code of the latest version of gRPC is used here to compile and install, the version number is v1.50.0, and the installation steps are as follows:

1. Use Git to clone gRPC to the local

Open a certain folder in the terminal, it is recommended to create a new folder to store the gRPC source code separately, enter:

git clone -b v1.50.0 https://github.com/grpc/grpc

image

2. Installation dependencies

Some third-party dependencies need to be installed when compiling gRPC, use the command:

git submodule update --init

It will be installed automatically, but the download speed is very slow due to the domestic network or other reasons, so we need to manually modify "grpc/. /.gitmodules" file is as follows:

[submodule "third_party/abseil-cpp"]
	path = third_party/abseil-cpp
	url = https://gitee.com/suuair/abseil-cpp.git
[submodule "third_party/benchmark"]
	path = third_party/benchmark
	url = https://gitee.com/chahan/benchmark.git
[submodule "third_party/bloaty"]
	path = third_party/bloaty
	url = https://gitee.com/GgBoy_ssz/bloaty.git
[submodule "third_party/boringssl-with-bazel"]
	path = third_party/boringssl-with-bazel
	url = https://gitee.com/GgBoy_ssz/boringssl.git
[submodule "third_party/cares/cares"]
	path = third_party/cares/cares
	url = https://gitee.com/RicLee/c-ares.git
[submodule "third_party/envoy-api"]
	path = third_party/envoy-api
	url = https://gitee.com/RicLee/data-plane-api.git
[submodule "third_party/googleapis"]
	path = third_party/googleapis
	url = https://gitee.com/GgBoy_ssz/googleapis.git
[submodule "third_party/googletest"]
	path = third_party/googletest
	url = https://gitee.com/bosspoi/googletest.git
[submodule "third_party/libuv"]
	path = third_party/libuv
	url = https://gitee.com/RicLee/libuv.git
[submodule "third_party/opencensus-proto"]
	path = third_party/opencensus-proto
	url = https://gitee.com/RicLee/opencensus-proto.git
[submodule "third_party/opentelemetry"]
	path = third_party/opentelemetry
	url = https://gitee.com/EBServerStudy/opentelemetry-proto.git
[submodule "third_party/protobuf"]
	path = third_party/protobuf
	url = https://gitee.com/EBServerStudy/protobuf.git
[submodule "third_party/protoc-gen-validate"]
	path = third_party/protoc-gen-validate
	url = https://gitee.com/arzhe/protoc-gen-validate.git
[submodule "third_party/re2"]
	path = third_party/re2
	url = https://gitee.com/GgBoy_ssz/re2.git
[submodule "third_party/xds"]
	path = third_party/xds
	url = https://gitee.com/EBServerStudy/xds.git
[submodule "third_party/zlib"]
	path = third_party/zlib
	url = https://gitee.com/RicLee/zlib.git
	# When using CMake to build, the zlib submodule ends up with a
	# generated file that makes Git consider the submodule dirty. This
	# state can be ignored for day-to-day development on gRPC.
	ignore = dirty

  1. Open the grpc/.gitmodules file and update it to the above content
  2. Execute command git submodule syncSynchronize URL
  3. Execute command git submodule update --initto download third-party dependencies

image

2. Compile and install

  1. Enter the grpc folder in the terminal, enter to mkdir -p cmake/buildcreate a compilation folder,
  2. Build code, input cmake ../.. -G "MinGW Makefiles"Generate makefile and related files
  3. To compile the code, make -jenter
  4. To install grpc, enter it make install -jto be installed in the directory "C:\Program Files (x86)\grpc" by default

3. Compile and run the test program

The official provides a set of test samples, located in the grpc/examples/ directory, find the cpp/helloworld folder, where the programs we need to test are stored.

1. Compile HelloWorld

  1. Use the terminal to open the grpc/examples/cpp/helloworld folder, enter to mkdir -p cmake/buildcreate a compilation folder
  2. Open the "CMakeLists.txt" folder and link ws2_32 into the target.

image

  1. Build the code, enter the cmake/build folder, and enter the following command to generate the Makefile
cmake ../.. -DCMAKE_PREFIX_PATH="C:/Program Files (x86)/grpc/" -G "MinGW Makefiles"
  1. To compile the code, make -jenter

image

2. Run the test program

Run the server program:./greeter_server

image

Run the client program:./greeter_client

image

4. Reference Articles

Guess you like

Origin blog.csdn.net/qq_37434641/article/details/127561281