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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章