aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/experimental/build_native_ext_for_ios.sh
blob: 69c9cdf021c8b01c1eb0599def9e2b4575d045e0 (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
#!/bin/sh
# Copyright 2018 The gRPC Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Helper script to crosscompile grpc_csharp_ext native extension for Android.

set -ex

cd "$(dirname "$0")/../../.."

# Usage: build <iphoneos|iphonesimulator> <arm64|x86_64|...>
function build {
    SDK="$1"
    ARCH="$2"

    PATH_AR="$(xcrun --sdk $SDK --find ar)"
    PATH_CC="$(xcrun --sdk $SDK --find clang)"
    PATH_CXX="$(xcrun --sdk $SDK --find clang++)"

    # TODO(jtattermusch): add  -mios-version-min=6.0 and -Wl,ios_version_min=6.0
    CPPFLAGS="-O2 -Wframe-larger-than=16384 -arch $ARCH -isysroot $(xcrun --sdk $SDK --show-sdk-path) -DPB_NO_PACKED_STRUCTS=1"
    LDFLAGS="-arch $ARCH -isysroot $(xcrun --sdk $SDK --show-sdk-path)"

    # TODO(jtattermusch): revisit the build arguments
    make -j4 static_csharp \
        VALID_CONFIG_ios_$ARCH="1" \
        CC_ios_$ARCH="$PATH_CC" \
        CXX_ios_$ARCH="$PATH_CXX" \
        LD_ios_$ARCH="$PATH_CC" \
        LDXX_ios_$ARCH="$PATH_CXX" \
        CPPFLAGS_ios_$ARCH="$CPPFLAGS" \
        LDFLAGS_ios_$ARCH="$LDFLAGS" \
        DEFINES_ios_$ARCH="NDEBUG" \
        CONFIG="ios_$ARCH"
}

# Usage: fatten <grpc_csharp_ext|...>
function fatten {
    LIB_NAME="$1"

    mkdir -p libs/ios
    lipo -create -output libs/ios/lib$LIB_NAME.a \
        libs/ios_arm64/lib$LIB_NAME.a \
        libs/ios_x86_64/lib$LIB_NAME.a
}

build iphoneos arm64
build iphonesimulator x86_64

fatten grpc
fatten grpc_csharp_ext