aboutsummaryrefslogtreecommitdiff
path: root/cross_compile.md
blob: 67b16421248643350321957f4bf61ed442595661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Cross Compile gRPC-rs(0.2.1) to Windows under *nix

## First you need to install mingw

```bash
# macOS
brew install mingw-w64

# CentOS
yum install mingw64-openssl-static mingw64-zlib-static mingw64-winpthreads-static
```

## Fix CMake

```
# modify grpc-rs/grpc-sys/build.rs
# fix SYSTEM_PROCESSOR
"CMAKE_SYSTEM_PROCESSOR", get_env("CARGO_CFG_TARGET_ARCH").unwrap()
# fix try_run
"CMAKE_CROSSCOMPILING", "true"
```

### All diff in `fn build_grpc`

```rust
    let dst = {
        let mut config = Config::new("grpc");
        if get_env("CARGO_CFG_TARGET_OS").map_or(false, |s| s == "macos") {
            config.cxxflag("-stdlib=libc++");
        }
        config
            .define("CMAKE_SYSTEM_PROCESSOR", get_env("CARGO_CFG_TARGET_ARCH").unwrap())
            .define("CMAKE_CROSSCOMPILING", "true")
            .build_target(library)
            .uses_cxx11()
            .build()
        // config.build_target(library).uses_cxx11().build()
    };
```

### Fix find zlib

```rust
    // try these values
    let mut zlib = "z";
    let mut zlib = "zlibstatic";
    let mut zlib = "zlibstaticd";
```

## Fix WIN32 API

```
# grpc-rs/grpc-sys/grpc/CMakeLists.txt
# add these code after about line number 295
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_WIN32_WINNT=0x600")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=0x600")
set(C_CXX_FLAGS "${C_CXX_FLAGS} -D_WIN32_WINNT=0x600")
```

## Fix boringssl

Just update third_party/boringssl

```bash
cd third_party/boringssl
git checkout master
git pull
```