1# Cross Compile gRPC-rs(0.2.1) to Windows under *nix 2 3## First you need to install mingw 4 5```bash 6# macOS 7brew install mingw-w64 8 9# CentOS 10yum install mingw64-openssl-static mingw64-zlib-static mingw64-winpthreads-static 11``` 12 13## Fix CMake 14 15``` 16# modify grpc-rs/grpc-sys/build.rs 17# fix SYSTEM_PROCESSOR 18"CMAKE_SYSTEM_PROCESSOR", get_env("CARGO_CFG_TARGET_ARCH").unwrap() 19# fix try_run 20"CMAKE_CROSSCOMPILING", "true" 21``` 22 23### All diff in `fn build_grpc` 24 25```rust 26 let dst = { 27 let mut config = Config::new("grpc"); 28 if get_env("CARGO_CFG_TARGET_OS").map_or(false, |s| s == "macos") { 29 config.cxxflag("-stdlib=libc++"); 30 } 31 config 32 .define("CMAKE_SYSTEM_PROCESSOR", get_env("CARGO_CFG_TARGET_ARCH").unwrap()) 33 .define("CMAKE_CROSSCOMPILING", "true") 34 .build_target(library) 35 .uses_cxx11() 36 .build() 37 // config.build_target(library).uses_cxx11().build() 38 }; 39``` 40 41### Fix find zlib 42 43```rust 44 // try these values 45 let mut zlib = "z"; 46 let mut zlib = "zlibstatic"; 47 let mut zlib = "zlibstaticd"; 48``` 49 50## Fix WIN32 API 51 52``` 53# grpc-rs/grpc-sys/grpc/CMakeLists.txt 54# add these code after about line number 295 55set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_WIN32_WINNT=0x600") 56set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=0x600") 57set(C_CXX_FLAGS "${C_CXX_FLAGS} -D_WIN32_WINNT=0x600") 58``` 59 60## Fix boringssl 61 62Just update third_party/boringssl 63 64```bash 65cd third_party/boringssl 66git checkout master 67git pull 68``` 69