• 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 iOS.
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    CPPFLAGS="-O2 -Wframe-larger-than=16384 -arch $ARCH -isysroot $(xcrun --sdk $SDK --show-sdk-path) -mios-version-min=9.0 -DPB_NO_PACKED_STRUCTS=1"
32    LDFLAGS="-arch $ARCH -isysroot $(xcrun --sdk $SDK --show-sdk-path) -Wl,ios_version_min=9.0"
33
34    # TODO(jtattermusch): revisit the build arguments
35    make -j4 static_csharp \
36        VALID_CONFIG_ios_$ARCH="1" \
37        CC_ios_$ARCH="$PATH_CC" \
38        CXX_ios_$ARCH="$PATH_CXX" \
39        LD_ios_$ARCH="$PATH_CC" \
40        LDXX_ios_$ARCH="$PATH_CXX" \
41        CPPFLAGS_ios_$ARCH="$CPPFLAGS" \
42        LDFLAGS_ios_$ARCH="$LDFLAGS" \
43        DEFINES_ios_$ARCH="NDEBUG" \
44        CONFIG="ios_$ARCH"
45}
46
47# Usage: fatten <grpc_csharp_ext|...>
48function fatten {
49    LIB_NAME="$1"
50
51    mkdir -p libs/ios
52    lipo -create -output libs/ios/lib$LIB_NAME.a \
53        libs/ios_armv7/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 armv7
59build iphoneos arm64
60build iphonesimulator x86_64
61
62fatten grpc
63fatten grpc_csharp_ext
64