• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# Copyright 2018 The gRPC Authors
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Helper script to crosscompile grpc_csharp_ext native extension for Android.
17
18set -ex
19
20cd "$(dirname "$0")/../../.."
21
22# Usage: build <iphoneos|iphonesimulator> <arm64|x86_64|...>
23function build {
24    SDK="$1"
25    ARCH="$2"
26
27    PATH_AR="$(xcrun --sdk $SDK --find ar)"
28    PATH_CC="$(xcrun --sdk $SDK --find clang)"
29    PATH_CXX="$(xcrun --sdk $SDK --find clang++)"
30
31    # TODO(jtattermusch): add  -mios-version-min=6.0 and -Wl,ios_version_min=6.0
32    CPPFLAGS="-O2 -Wframe-larger-than=16384 -arch $ARCH -isysroot $(xcrun --sdk $SDK --show-sdk-path) -DPB_NO_PACKED_STRUCTS=1"
33    LDFLAGS="-arch $ARCH -isysroot $(xcrun --sdk $SDK --show-sdk-path)"
34
35    # TODO(jtattermusch): revisit the build arguments
36    make -j4 static_csharp \
37        VALID_CONFIG_ios_$ARCH="1" \
38        CC_ios_$ARCH="$PATH_CC" \
39        CXX_ios_$ARCH="$PATH_CXX" \
40        LD_ios_$ARCH="$PATH_CC" \
41        LDXX_ios_$ARCH="$PATH_CXX" \
42        CPPFLAGS_ios_$ARCH="$CPPFLAGS" \
43        LDFLAGS_ios_$ARCH="$LDFLAGS" \
44        DEFINES_ios_$ARCH="NDEBUG" \
45        CONFIG="ios_$ARCH"
46}
47
48# Usage: fatten <grpc_csharp_ext|...>
49function fatten {
50    LIB_NAME="$1"
51
52    mkdir -p libs/ios
53    lipo -create -output libs/ios/lib$LIB_NAME.a \
54        libs/ios_arm64/lib$LIB_NAME.a \
55        libs/ios_x86_64/lib$LIB_NAME.a
56}
57
58build iphoneos arm64
59build iphonesimulator x86_64
60
61fatten grpc
62fatten grpc_csharp_ext
63