From cfae76b28b86d2c86d54a71fe3a776335bb7cd02 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 5 Mar 2018 16:42:15 +0100 Subject: add experimental script for building the unitypackage --- src/csharp/experimental/build_native_ext_for_android.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/csharp/experimental/build_native_ext_for_android.sh') diff --git a/src/csharp/experimental/build_native_ext_for_android.sh b/src/csharp/experimental/build_native_ext_for_android.sh index 3063d78efa..6d1871a538 100755 --- a/src/csharp/experimental/build_native_ext_for_android.sh +++ b/src/csharp/experimental/build_native_ext_for_android.sh @@ -15,6 +15,8 @@ # Helper script to crosscompile grpc_csharp_ext native extension for Android. +set -ex + cd "$(dirname "$0")/../../../cmake" mkdir -p build -- cgit v1.2.3 From dcf340e8c97bc8efb3536132f3e3938dae6702c8 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 7 Mar 2018 21:01:29 +0100 Subject: address comments --- .../experimental/build_native_ext_for_android.sh | 2 +- .../Internal/NativeMethods.Generated.cs.template | 33 +++------------------- 2 files changed, 5 insertions(+), 30 deletions(-) (limited to 'src/csharp/experimental/build_native_ext_for_android.sh') diff --git a/src/csharp/experimental/build_native_ext_for_android.sh b/src/csharp/experimental/build_native_ext_for_android.sh index 6d1871a538..958778e929 100755 --- a/src/csharp/experimental/build_native_ext_for_android.sh +++ b/src/csharp/experimental/build_native_ext_for_android.sh @@ -36,4 +36,4 @@ cmake ../.. \ -DRUN_HAVE_STEADY_CLOCK=0 \ -DCMAKE_BUILD_TYPE=Release -make grpc_csharp_ext +make -j4 grpc_csharp_ext diff --git a/templates/src/csharp/Grpc.Core/Internal/NativeMethods.Generated.cs.template b/templates/src/csharp/Grpc.Core/Internal/NativeMethods.Generated.cs.template index 4d4185d068..8ce2a57323 100644 --- a/templates/src/csharp/Grpc.Core/Internal/NativeMethods.Generated.cs.template +++ b/templates/src/csharp/Grpc.Core/Internal/NativeMethods.Generated.cs.template @@ -5,7 +5,6 @@ 'void grpcsharp_init()', 'void grpcsharp_shutdown()', 'IntPtr grpcsharp_version_string() // returns not-owned const char*', - '', 'BatchContextSafeHandle grpcsharp_batch_context_create()', 'IntPtr grpcsharp_batch_context_recv_initial_metadata(BatchContextSafeHandle ctx)', 'IntPtr grpcsharp_batch_context_recv_message_length(BatchContextSafeHandle ctx)', @@ -16,7 +15,6 @@ 'int grpcsharp_batch_context_recv_close_on_server_cancelled(BatchContextSafeHandle ctx)', 'void grpcsharp_batch_context_reset(BatchContextSafeHandle ctx)', 'void grpcsharp_batch_context_destroy(IntPtr ctx)', - '', 'RequestCallContextSafeHandle grpcsharp_request_call_context_create()', 'CallSafeHandle grpcsharp_request_call_context_call(RequestCallContextSafeHandle ctx)', 'IntPtr grpcsharp_request_call_context_method(RequestCallContextSafeHandle ctx, out UIntPtr methodLength)', @@ -25,10 +23,8 @@ 'IntPtr grpcsharp_request_call_context_request_metadata(RequestCallContextSafeHandle ctx)', 'void grpcsharp_request_call_context_reset(RequestCallContextSafeHandle ctx)', 'void grpcsharp_request_call_context_destroy(IntPtr ctx)', - '', 'CallCredentialsSafeHandle grpcsharp_composite_call_credentials_create(CallCredentialsSafeHandle creds1, CallCredentialsSafeHandle creds2)', 'void grpcsharp_call_credentials_release(IntPtr credentials)', - '', 'CallError grpcsharp_call_cancel(CallSafeHandle call)', 'CallError grpcsharp_call_cancel_with_status(CallSafeHandle call, StatusCode status, string description)', 'CallError grpcsharp_call_start_unary(CallSafeHandle call, BatchContextSafeHandle ctx, byte[] sendBuffer, UIntPtr sendBufferLen, WriteFlags writeFlags, MetadataArraySafeHandle metadataArray, CallFlags metadataFlags)', @@ -45,17 +41,14 @@ 'CallError grpcsharp_call_set_credentials(CallSafeHandle call, CallCredentialsSafeHandle credentials)', 'CStringSafeHandle grpcsharp_call_get_peer(CallSafeHandle call)', 'void grpcsharp_call_destroy(IntPtr call)', - '', 'ChannelArgsSafeHandle grpcsharp_channel_args_create(UIntPtr numArgs)', 'void grpcsharp_channel_args_set_string(ChannelArgsSafeHandle args, UIntPtr index, string key, string value)', 'void grpcsharp_channel_args_set_integer(ChannelArgsSafeHandle args, UIntPtr index, string key, int value)', 'void grpcsharp_channel_args_destroy(IntPtr args)', - '', 'void grpcsharp_override_default_ssl_roots(string pemRootCerts)', 'ChannelCredentialsSafeHandle grpcsharp_ssl_credentials_create(string pemRootCerts, string keyCertPairCertChain, string keyCertPairPrivateKey)', 'ChannelCredentialsSafeHandle grpcsharp_composite_channel_credentials_create(ChannelCredentialsSafeHandle channelCreds, CallCredentialsSafeHandle callCreds)', 'void grpcsharp_channel_credentials_release(IntPtr credentials)', - '', 'ChannelSafeHandle grpcsharp_insecure_channel_create(string target, ChannelArgsSafeHandle channelArgs)', 'ChannelSafeHandle grpcsharp_secure_channel_create(ChannelCredentialsSafeHandle credentials, string target, ChannelArgsSafeHandle channelArgs)', 'CallSafeHandle grpcsharp_channel_create_call(ChannelSafeHandle channel, CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline)', @@ -63,33 +56,25 @@ 'void grpcsharp_channel_watch_connectivity_state(ChannelSafeHandle channel, ChannelState lastObservedState, Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx)', 'CStringSafeHandle grpcsharp_channel_get_target(ChannelSafeHandle call)', 'void grpcsharp_channel_destroy(IntPtr channel)', - '', 'int grpcsharp_sizeof_grpc_event()', - '', 'CompletionQueueSafeHandle grpcsharp_completion_queue_create_async()', 'CompletionQueueSafeHandle grpcsharp_completion_queue_create_sync()', 'void grpcsharp_completion_queue_shutdown(CompletionQueueSafeHandle cq)', 'CompletionQueueEvent grpcsharp_completion_queue_next(CompletionQueueSafeHandle cq)', 'CompletionQueueEvent grpcsharp_completion_queue_pluck(CompletionQueueSafeHandle cq, IntPtr tag)', 'void grpcsharp_completion_queue_destroy(IntPtr cq)', - '', 'void gprsharp_free(IntPtr ptr)', - '', 'MetadataArraySafeHandle grpcsharp_metadata_array_create(UIntPtr capacity)', 'void grpcsharp_metadata_array_add(MetadataArraySafeHandle array, string key, byte[] value, UIntPtr valueLength)', 'UIntPtr grpcsharp_metadata_array_count(IntPtr metadataArray)', 'IntPtr grpcsharp_metadata_array_get_key(IntPtr metadataArray, UIntPtr index, out UIntPtr keyLength)', 'IntPtr grpcsharp_metadata_array_get_value(IntPtr metadataArray, UIntPtr index, out UIntPtr valueLength)', 'void grpcsharp_metadata_array_destroy_full(IntPtr array)', - '', 'void grpcsharp_redirect_log(GprLogDelegate callback)', - '', 'CallCredentialsSafeHandle grpcsharp_metadata_credentials_create_from_plugin(NativeMetadataInterceptor interceptor)', 'void grpcsharp_metadata_credentials_notify_from_plugin(IntPtr callbackPtr, IntPtr userData, MetadataArraySafeHandle metadataArray, StatusCode statusCode, string errorDetails)', - '', 'ServerCredentialsSafeHandle grpcsharp_ssl_server_credentials_create(string pemRootCerts, string[] keyCertPairCertChainArray, string[] keyCertPairPrivateKeyArray, UIntPtr numKeyCertPairs, int forceClientAuth)', 'void grpcsharp_server_credentials_release(IntPtr credentials)', - '', 'ServerSafeHandle grpcsharp_server_create(ChannelArgsSafeHandle args)', 'void grpcsharp_server_register_completion_queue(ServerSafeHandle server, CompletionQueueSafeHandle cq)', 'int grpcsharp_server_add_insecure_http2_port(ServerSafeHandle server, string addr)', @@ -99,20 +84,16 @@ 'void grpcsharp_server_cancel_all_calls(ServerSafeHandle server)', 'void grpcsharp_server_shutdown_and_notify_callback(ServerSafeHandle server, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx)', 'void grpcsharp_server_destroy(IntPtr server)', - '', 'AuthContextSafeHandle grpcsharp_call_auth_context(CallSafeHandle call)', 'IntPtr grpcsharp_auth_context_peer_identity_property_name(AuthContextSafeHandle authContext) // returns const char*', 'AuthContextSafeHandle.NativeAuthPropertyIterator grpcsharp_auth_context_property_iterator(AuthContextSafeHandle authContext)', 'IntPtr grpcsharp_auth_property_iterator_next(ref AuthContextSafeHandle.NativeAuthPropertyIterator iterator) // returns const auth_property*', 'void grpcsharp_auth_context_release(IntPtr authContext)', - '', 'Timespec gprsharp_now(ClockType clockType)', 'Timespec gprsharp_inf_future(ClockType clockType)', 'Timespec gprsharp_inf_past(ClockType clockType)', - '', 'Timespec gprsharp_convert_clock_type(Timespec t, ClockType targetClock)', 'int gprsharp_sizeof_timespec()', - '', 'CallError grpcsharp_test_callback([MarshalAs(UnmanagedType.FunctionPtr)] NativeCallbackTestDelegate callback)', 'IntPtr grpcsharp_test_nop(IntPtr ptr)', 'void grpcsharp_test_override_method(string methodName, string variant)', @@ -121,16 +102,10 @@ import re native_methods = [] for signature in native_method_signatures: - if not signature: - continue - match = re.match('([^ ]+) +([A-Za-z0-9_]+)\\((.*)\\)(.*)', signature) - native_methods.append({'name': match.group(2), 'returntype': match.group(1), 'params': match.group(3), 'comment': match.group(4)}) - - - #native_methods = [ - # {'name': 'grpcsharp_init', 'returntype': 'void', 'params': ''}, - # {'name': 'grpcsharp_server_request_call', 'returntype': 'CallError', 'params': 'ServerSafeHandle server, CompletionQueueSafeHandle cq, RequestCallContextSafeHandle ctx'}, - #] + match = re.match('([A-Za-z0-9_.]+) +([A-Za-z0-9_]+)\\((.*)\\)(.*)', signature) + if not match: + raise Exception('Malformed signature "%s"' % signature) + native_methods.append({'returntype': match.group(1), 'name': match.group(2), 'params': match.group(3), 'comment': match.group(4)}) %> #region Copyright notice and license -- cgit v1.2.3 From 0767878b6efb059c209e82ca1d6d2fbcfb309b70 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 12 Apr 2018 13:56:03 +0200 Subject: build C# android artifact --- .../experimental/build_native_ext_for_android.sh | 2 +- .../grpc_artifact_android_ndk/Dockerfile | 68 ++++++++++++++++++++++ tools/run_tests/artifacts/artifact_targets.py | 9 ++- .../artifacts/build_artifact_csharp_android.sh | 23 ++++++++ 4 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 tools/dockerfile/grpc_artifact_android_ndk/Dockerfile create mode 100755 tools/run_tests/artifacts/build_artifact_csharp_android.sh (limited to 'src/csharp/experimental/build_native_ext_for_android.sh') diff --git a/src/csharp/experimental/build_native_ext_for_android.sh b/src/csharp/experimental/build_native_ext_for_android.sh index 958778e929..8197df7c53 100755 --- a/src/csharp/experimental/build_native_ext_for_android.sh +++ b/src/csharp/experimental/build_native_ext_for_android.sh @@ -23,7 +23,7 @@ mkdir -p build cd build # set to the location where Android SDK is installed -ANDROID_NDK_PATH="$HOME/android-ndk-r16b" +# e.g. ANDROID_NDK_PATH="$HOME/android-ndk-r16b" cmake ../.. \ -DCMAKE_SYSTEM_NAME=Android \ diff --git a/tools/dockerfile/grpc_artifact_android_ndk/Dockerfile b/tools/dockerfile/grpc_artifact_android_ndk/Dockerfile new file mode 100644 index 0000000000..77b6acfb16 --- /dev/null +++ b/tools/dockerfile/grpc_artifact_android_ndk/Dockerfile @@ -0,0 +1,68 @@ +# Copyright 2016 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. + +# Docker file for building gRPC artifacts. + +# Recent enough cmake (>=3.9) needed by Android SDK +FROM debian:sid + +RUN apt-get update && apt-get install -y debian-keyring && apt-key update + +# Install Git and basic packages. +RUN apt-get update && apt-key update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + clang \ + curl \ + gcc \ + gcc-multilib \ + git \ + golang \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + perl \ + strace \ + python-dev \ + python-setuptools \ + python-yaml \ + telnet \ + unzip \ + wget \ + zip && apt-get clean + +# Cmake for cross-compilation +RUN apt-get update && apt-get install -y cmake golang && apt-get clean + +################## +# Android NDK + +# Download and install Android NDK +RUN wget -q https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip -O android_ndk.zip \ + && unzip -q android_ndk.zip \ + && rm android_ndk.zip \ + && mv ./android-ndk-r16b /opt +ENV ANDROID_NDK_PATH /opt/android-ndk-r16b + +RUN apt-get update && apt-get install -y libpthread-stubs0-dev && apt-get clean + +RUN mkdir /var/local/jenkins + +# Define the default command. +CMD ["bash"] diff --git a/tools/run_tests/artifacts/artifact_targets.py b/tools/run_tests/artifacts/artifact_targets.py index daa163e6dd..e4d9e6bdfe 100644 --- a/tools/run_tests/artifacts/artifact_targets.py +++ b/tools/run_tests/artifacts/artifact_targets.py @@ -222,7 +222,13 @@ class CSharpExtArtifact: return [] def build_jobspec(self): - if self.platform == 'windows': + if self.arch == 'android': + return create_docker_jobspec( + self.name, + 'tools/dockerfile/grpc_artifact_android_ndk', + 'tools/run_tests/artifacts/build_artifact_csharp_android.sh', + environ={}) + elif self.platform == 'windows': cmake_arch_option = 'Win32' if self.arch == 'x86' else self.arch return create_jobspec( self.name, [ @@ -342,6 +348,7 @@ def targets(): for Cls in (CSharpExtArtifact, ProtocArtifact) for platform in ('linux', 'macos', 'windows') for arch in ('x86', 'x64') ] + [ + CSharpExtArtifact('linux', 'android'), 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_android.sh b/tools/run_tests/artifacts/build_artifact_csharp_android.sh new file mode 100755 index 0000000000..ba598e76a4 --- /dev/null +++ b/tools/run_tests/artifacts/build_artifact_csharp_android.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Copyright 2016 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_android.sh + +mkdir -p "${ARTIFACTS_OUT}" +cp cmake/build/libgrpc_csharp_ext.so "${ARTIFACTS_OUT}" -- cgit v1.2.3