我是靠谱客的博主 发嗲人生,最近开发中收集的这篇文章主要介绍grpc gitee镜像编译,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

因为github被墙的厉害,git clone很慢,grpc submodule还特别多,幸亏找到了gitee上的源,感谢gitee/githubplus作者

下载编译步骤如下:
编译grpc需要go支持,windows编译需要nasm,在ubuntu上可使用apt直接安装

sudo apt install golang yasm nasm
git clone https://gitee.com/githubplus/grpc.git
cd grpc
git tag
git checkout v1.20.0

修改.gitmodules文件,替换其中的github源为gitee源

[submodule "third_party/zlib"]
	path = third_party/zlib
	url = https://gitee.com/githubplus/zlib
	# 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
[submodule "third_party/protobuf"]
	path = third_party/protobuf
	url = https://gitee.com/githubplus/protobuf.git
	branch = 3.0.x
[submodule "third_party/gflags"]
	path = third_party/gflags
	url = https://gitee.com/githubplus/gflags.git
[submodule "third_party/googletest"]
	path = third_party/googletest
	url = https://gitee.com/githubplus/googletest.git
[submodule "third_party/boringssl"]
	path = third_party/boringssl
	url = https://gitee.com/githubplus/boringssl.git
[submodule "third_party/benchmark"]
	path = third_party/benchmark
	url = https://gitee.com/githubplus/benchmark.git
[submodule "third_party/boringssl-with-bazel"]
	path = third_party/boringssl-with-bazel
	url = https://gitee.com/githubplus/boringssl.git
[submodule "third_party/cares/cares"]
	path = third_party/cares/cares
	url = https://gitee.com/githubplus/c-ares.git
	branch = cares-1_12_0
[submodule "third_party/bloaty"]
	path = third_party/bloaty
	url = https://gitee.com/githubplus/bloaty.git
[submodule "third_party/abseil-cpp"]
	path = third_party/abseil-cpp
	url = https://gitee.com/githubplus/abseil-cpp
[submodule "third_party/libcxxabi"]
	path = third_party/libcxxabi
	url = https://gitee.com/githubplus/libcxxabi.git
	branch = release_60
[submodule "third_party/libcxx"]
	path = third_party/libcxx
	url = https://gitee.com/githubplus/libcxx.git
	branch = release_60
[submodule "third_party/data-plane-api"]
	path = third_party/data-plane-api
	url = https://gitee.com/githubplus/data-plane-api.git
[submodule "third_party/googleapis"]
	path = third_party/googleapis
	url = https://gitee.com/githubplus/googleapis.git
[submodule "third_party/protoc-gen-validate"]
	path = third_party/protoc-gen-validate
	url = https://gitee.com/githubplus/protoc-gen-validate.git
[submodule "third_party/upb"]
	path = third_party/upb
	url = https://gitee.com/githubplus/upb.git
git submodule update --init
cd third_party/protobuf

类似修改protobuf.gitmodules后,执行git submodule update --init

[submodule "third_party/benchmark"]
	path = third_party/benchmark
	url = https://gitee.com/githubplus/benchmark.git
[submodule "third_party/googletest"]
	path = third_party/googletest
	url = https://gitee.com/githubplus/googletest.git
	ignore = dirty

使用cmake构建

mkdir build/linux-x86_64
cd build/linux-x864_64
cmake ../..
make

使用mingw交叉编译

mkdir -p build/mingw32
cd build/mingw32
cmake ../.. -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=x86
make grpc++
mkdir -p build/mingw64
cd build/mingw64
cmake ../.. -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=x86_64
make grpc++

error

Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)

include/grpc/impl/codegen/port_platform.h中添加

#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600                                                                                                                                                          
#undef  _WIN32_WINNT                                                                                                                                                          
#define _WIN32_WINNT 0x0600                                                                                                                                                   
#endif
                                                                                                                                                                                                                                                                                                                                                      
#ifndef _WIN32_WINNT                                                                                                                                                          
#error                                                                                                                                                                       
    "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"                                                                                             
#else /* !defined(_WIN32_WINNT) */                                                                                                                                            
#if (_WIN32_WINNT < 0x0600)                                                                                                                                                   
#error                                                                                                                                                                       
    "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"                                                                                             
#endif /* _WIN32_WINNT < 0x0600 */                                                                                                                                            
#endif /* defined(_WIN32_WINNT) */ 

find . -name *.a静态库

./libgrpc.a
./libgrpc++.a
./libaddress_sorting.a
./libgpr.a
./third_party/protobuf/libprotobuf.a
./third_party/boringssl/ssl/libssl.a
./third_party/boringssl/crypto/libcrypto.a
./third_party/cares/cares/lib/libcares.a
./third_party/zlib/libzlibstatic.a

Makefile中链接

GRPC_LIBS += protobuf grpc++ grpc gpr address_sorting cares ssl crypto z
LDFLAGS += $(addprefix -l, $(GRPC_LIBS))

ubuntu16.04下编译好的库https://gitee.com/ithewei/grpc-release.git

最后

以上就是发嗲人生为你收集整理的grpc gitee镜像编译的全部内容,希望文章能够帮你解决grpc gitee镜像编译所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部