From 081c27baad81f3f4862b5c89f0bf1bd792d19876 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 23 Jul 2018 22:59:02 +0200 Subject: [PATCH 1/7] add static_csharp rule to Makefile --- Makefile | 2 ++ templates/Makefile.template | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/Makefile b/Makefile index 2b4ed146ccc..bad41975a05 100644 --- a/Makefile +++ b/Makefile @@ -1381,6 +1381,8 @@ static_c: pc_c pc_c_unsecure cache.mk $(LIBDIR)/$(CONFIG)/libaddress_sorting.a static_cxx: pc_cxx pc_cxx_unsecure cache.mk $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc++_cronet.a $(LIBDIR)/$(CONFIG)/libgrpc++_error_details.a $(LIBDIR)/$(CONFIG)/libgrpc++_reflection.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpcpp_channelz.a +static_csharp: static_c $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.a + shared: shared_c shared_cxx shared_c: pc_c pc_c_unsecure cache.mk $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)address_sorting$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)gpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) diff --git a/templates/Makefile.template b/templates/Makefile.template index 628056ed4db..50b81e5f9f2 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -921,6 +921,16 @@ % endfor + static_csharp: static_c \ + % for lib in libs: + % if 'Makefile' in lib.get('build_system', ['Makefile']): + % if lib.build == 'all' and lib.language == 'csharp': + $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ + % endif + % endif + % endfor + + shared: shared_c shared_cxx shared_c: pc_c pc_c_unsecure cache.mk\ From cbc2b1f40562b772c61e1448d4fa290587fca256 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 23 Jul 2018 23:13:34 +0200 Subject: [PATCH 2/7] experiment: build grpc_csharp_ext for ios --- .../experimental/build_native_ext_for_ios.sh | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 src/csharp/experimental/build_native_ext_for_ios.sh diff --git a/src/csharp/experimental/build_native_ext_for_ios.sh b/src/csharp/experimental/build_native_ext_for_ios.sh new file mode 100755 index 00000000000..518390ea63b --- /dev/null +++ b/src/csharp/experimental/build_native_ext_for_ios.sh @@ -0,0 +1,45 @@ +#!/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")/../../.." + +# +SDK="iphoneos" +# +ARCH="arm64" + +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" From 5bb8a33eb26a347bc790620552649c957dcc17e5 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 23 Jul 2018 23:14:11 +0200 Subject: [PATCH 3/7] copying files --- src/csharp/Grpc.Core/Grpc.Core.csproj | 12 ++++++++++++ .../Grpc.Core/build/Xamarin.iOS/Grpc.Core.targets | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/csharp/Grpc.Core/build/Xamarin.iOS/Grpc.Core.targets diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj index 0da95d203c6..7b0ae46dc18 100755 --- a/src/csharp/Grpc.Core/Grpc.Core.csproj +++ b/src/csharp/Grpc.Core/Grpc.Core.csproj @@ -54,6 +54,14 @@ runtimes/monoandroid/arm64-v8a/libgrpc_csharp_ext.so true + + runtimes/ios/native/libgrpc_csharp_ext.a + true + + + runtimes/ios/native/libgrpc.a + true + build/net45/ true @@ -62,6 +70,10 @@ build/MonoAndroid/ true + + build/Xamarin.iOS/ + true + diff --git a/src/csharp/Grpc.Core/build/Xamarin.iOS/Grpc.Core.targets b/src/csharp/Grpc.Core/build/Xamarin.iOS/Grpc.Core.targets new file mode 100644 index 00000000000..658158f6ea9 --- /dev/null +++ b/src/csharp/Grpc.Core/build/Xamarin.iOS/Grpc.Core.targets @@ -0,0 +1,15 @@ + + + + + + Static + True + + + Static + True + + + + From d9ad1c3f93540572b2336fdf584eed8bc87495b6 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 23 Jul 2018 23:26:56 +0200 Subject: [PATCH 4/7] building ios artifact --- tools/run_tests/artifacts/artifact_targets.py | 6 +++++ .../artifacts/build_artifact_csharp_ios.sh | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 tools/run_tests/artifacts/build_artifact_csharp_ios.sh diff --git a/tools/run_tests/artifacts/artifact_targets.py b/tools/run_tests/artifacts/artifact_targets.py index 4500b220e97..3a1142dfee6 100644 --- a/tools/run_tests/artifacts/artifact_targets.py +++ b/tools/run_tests/artifacts/artifact_targets.py @@ -234,6 +234,11 @@ class CSharpExtArtifact: environ={ 'ANDROID_ABI': self.arch_abi }) + elif self.arch == 'ios': + return create_jobspec( + self.name, + ['tools/run_tests/artifacts/build_artifact_csharp_ios.sh'], + use_workspace=True) elif self.platform == 'windows': cmake_arch_option = 'Win32' if self.arch == 'x86' else self.arch return create_jobspec( @@ -356,6 +361,7 @@ def targets(): ] + [ CSharpExtArtifact('linux', 'android', arch_abi='arm64-v8a'), CSharpExtArtifact('linux', 'android', arch_abi='armeabi-v7a'), + CSharpExtArtifact('macos', 'ios'), PythonArtifact('linux', 'x86', 'cp27-cp27m'), PythonArtifact('linux', 'x86', 'cp27-cp27mu'), PythonArtifact('linux', 'x86', 'cp34-cp34m'), diff --git a/tools/run_tests/artifacts/build_artifact_csharp_ios.sh b/tools/run_tests/artifacts/build_artifact_csharp_ios.sh new file mode 100755 index 00000000000..8b3c7a17b38 --- /dev/null +++ b/tools/run_tests/artifacts/build_artifact_csharp_ios.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Copyright 2016 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. + +set -ex + +cd "$(dirname "$0")/../../.." + +src/csharp/experimental/build_native_ext_for_ios.sh + +mkdir -p "${ARTIFACTS_OUT}" +cp libs/ios_arm64/libgrpc_csharp_ext.a libs/ios_arm64/libgrpc.a "${ARTIFACTS_OUT}" From 527d87add53b0ac7f13799facf0115c38846a23d Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 24 Jul 2018 11:36:25 +0200 Subject: [PATCH 5/7] fix Grpc.Core.csproj --- src/csharp/Grpc.Core/Grpc.Core.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj index 7b0ae46dc18..c4db3a3a875 100755 --- a/src/csharp/Grpc.Core/Grpc.Core.csproj +++ b/src/csharp/Grpc.Core/Grpc.Core.csproj @@ -54,11 +54,11 @@ runtimes/monoandroid/arm64-v8a/libgrpc_csharp_ext.so true - + runtimes/ios/native/libgrpc_csharp_ext.a true - + runtimes/ios/native/libgrpc.a true From 5aa2a0e376b22f35babf095ab1bc83078a7bf51b Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 24 Jul 2018 14:47:35 +0200 Subject: [PATCH 6/7] build fat binary for ios --- .../experimental/build_native_ext_for_ios.sh | 65 ++++++++++++------- .../artifacts/build_artifact_csharp_ios.sh | 2 +- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/csharp/experimental/build_native_ext_for_ios.sh b/src/csharp/experimental/build_native_ext_for_ios.sh index 518390ea63b..69c9cdf021c 100755 --- a/src/csharp/experimental/build_native_ext_for_ios.sh +++ b/src/csharp/experimental/build_native_ext_for_ios.sh @@ -19,27 +19,44 @@ set -ex cd "$(dirname "$0")/../../.." -# -SDK="iphoneos" -# -ARCH="arm64" - -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: build +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 +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 diff --git a/tools/run_tests/artifacts/build_artifact_csharp_ios.sh b/tools/run_tests/artifacts/build_artifact_csharp_ios.sh index 8b3c7a17b38..0d0a9c86da7 100755 --- a/tools/run_tests/artifacts/build_artifact_csharp_ios.sh +++ b/tools/run_tests/artifacts/build_artifact_csharp_ios.sh @@ -20,4 +20,4 @@ cd "$(dirname "$0")/../../.." src/csharp/experimental/build_native_ext_for_ios.sh mkdir -p "${ARTIFACTS_OUT}" -cp libs/ios_arm64/libgrpc_csharp_ext.a libs/ios_arm64/libgrpc.a "${ARTIFACTS_OUT}" +cp libs/ios/libgrpc_csharp_ext.a libs/ios/libgrpc.a "${ARTIFACTS_OUT}" From 056d061b3138ed26afe3132ed0d3f7d900d4735b Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 24 Jul 2018 19:29:04 +0200 Subject: [PATCH 7/7] Fix license year --- tools/run_tests/artifacts/build_artifact_csharp_ios.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run_tests/artifacts/build_artifact_csharp_ios.sh b/tools/run_tests/artifacts/build_artifact_csharp_ios.sh index 0d0a9c86da7..c902a45db7d 100755 --- a/tools/run_tests/artifacts/build_artifact_csharp_ios.sh +++ b/tools/run_tests/artifacts/build_artifact_csharp_ios.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2016 The gRPC Authors +# 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.