Skip to content

Commit

Permalink
make it possible to cross-compile for iOS and Android targets (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
eranrund authored and overvenus committed Feb 15, 2019
1 parent 9b27a5a commit 7189d27
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
14 changes: 0 additions & 14 deletions cross_compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,6 @@ yum install mingw64-openssl-static mingw64-zlib-static mingw64-winpthreads-stati
let mut zlib = "zlibstaticd";
```

## Fix try_run

```
# grpc-rs/grpc-sys/grpc/third_party/benchmark/cmake/CXXFeatureCheck.cmake
# add these code to fix try_run
SET( RUN_HAVE_STD_REGEX
0
CACHE STRING "Result from TRY_RUN" FORCE)
SET( RUN_HAVE_STEADY_CLOCK
0
CACHE STRING "Result from TRY_RUN" FORCE)
```

## Fix WIN32 API

```
Expand Down
42 changes: 42 additions & 0 deletions grpc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,54 @@ fn build_grpc(cc: &mut Build, library: &str) {
if env::var("CARGO_CFG_TARGET_ENV").unwrap_or("".to_owned()) == "musl" {
config.define("CMAKE_CXX_COMPILER", "g++");
}

// Cross-compile support for iOS
match env::var("TARGET").unwrap_or("".to_owned()).as_str() {
"aarch64-apple-ios" => {
config
.define("CMAKE_OSX_SYSROOT", "iphoneos")
.define("CMAKE_OSX_ARCHITECTURES", "arm64");
}
"armv7-apple-ios" => {
config
.define("CMAKE_OSX_SYSROOT", "iphoneos")
.define("CMAKE_OSX_ARCHITECTURES", "armv7");
}
"armv7s-apple-ios" => {
config
.define("CMAKE_OSX_SYSROOT", "iphoneos")
.define("CMAKE_OSX_ARCHITECTURES", "armv7s");
}
"i386-apple-ios" => {
config
.define("CMAKE_OSX_SYSROOT", "iphonesimulator")
.define("CMAKE_OSX_ARCHITECTURES", "i386");
}
"x86_64-apple-ios" => {
config
.define("CMAKE_OSX_SYSROOT", "iphonesimulator")
.define("CMAKE_OSX_ARCHITECTURES", "x86_64");
}
_ => {}
};

// Allow overriding of the target passed to cmake
// (needed for Android crosscompile)
match env::var("CMAKE_TARGET_OVERRIDE") {
Ok(val) => {
config.target(&val);
}
Err(_) => {}
};

// We don't need to generate install targets.
config.define("gRPC_INSTALL", "false");
// We don't need to build csharp target.
config.define("gRPC_BUILD_CSHARP_EXT", "false");
// We don't need to build codegen target.
config.define("gRPC_BUILD_CODEGEN", "false");
// We don't need to build benchmarks.
config.define("gRPC_BENCHMARK_PROVIDER", "none");
if cfg!(feature = "openssl") {
config.define("gRPC_SSL_PROVIDER", "package");
config.define("EMBED_OPENSSL", "false");
Expand Down

0 comments on commit 7189d27

Please sign in to comment.