aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp
diff options
context:
space:
mode:
Diffstat (limited to 'src/csharp')
-rwxr-xr-xsrc/csharp/Grpc.Core/Grpc.Core.csproj15
-rw-r--r--src/csharp/Grpc.Core/Internal/NativeExtension.cs18
-rw-r--r--src/csharp/Grpc.Core/Internal/PlatformApis.cs33
-rwxr-xr-xsrc/csharp/Grpc.Core/Version.csproj.include2
-rw-r--r--src/csharp/Grpc.Core/build/MonoAndroid/Grpc.Core.targets21
-rw-r--r--src/csharp/Grpc.Core/build/net45/Grpc.Core.targets (renamed from src/csharp/Grpc.Core/Grpc.Core.targets)0
-rwxr-xr-xsrc/csharp/experimental/build_native_ext_for_android.sh24
7 files changed, 103 insertions, 10 deletions
diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj
index 6d44be7ddd..315d54b7c6 100755
--- a/src/csharp/Grpc.Core/Grpc.Core.csproj
+++ b/src/csharp/Grpc.Core/Grpc.Core.csproj
@@ -46,8 +46,12 @@
<PackagePath>runtimes/win/native/grpc_csharp_ext.x86.dll</PackagePath>
<Pack>true</Pack>
</Content>
- <Content Include="Grpc.Core.targets">
- <PackagePath>build/net45/</PackagePath>
+ <Content Include="..\nativelibs\csharp_ext_monoandroid81_x86\libgrpc_csharp_ext.so">
+ <PackagePath>runtimes/monoandroid/armeabi-v7a/libgrpc_csharp_ext.so</PackagePath>
+ <Pack>true</Pack>
+ </Content>
+ <Content Include="..\nativelibs\csharp_ext_monoandroid81_x64\libgrpc_csharp_ext.so">
+ <PackagePath>runtimes/monoandroid/arm64-v8a/libgrpc_csharp_ext.so</PackagePath>
<Pack>true</Pack>
</Content>
</ItemGroup>
@@ -69,4 +73,11 @@
<Import Project="NativeDeps.csproj.include" />
+ <ItemGroup>
+ <Content Include="build\**\*.*">
+ <Pack>true</Pack>
+ <PackagePath>build</PackagePath>
+ </Content>
+ </ItemGroup>
+
</Project>
diff --git a/src/csharp/Grpc.Core/Internal/NativeExtension.cs b/src/csharp/Grpc.Core/Internal/NativeExtension.cs
index d5ec998bbd..5e1affcb99 100644
--- a/src/csharp/Grpc.Core/Internal/NativeExtension.cs
+++ b/src/csharp/Grpc.Core/Internal/NativeExtension.cs
@@ -106,7 +106,9 @@ namespace Grpc.Core.Internal
/// </summary>
private static NativeMethods LoadNativeMethods()
{
- return PlatformApis.IsUnity ? LoadNativeMethodsUnity() : new NativeMethods(LoadUnmanagedLibrary());
+ return PlatformApis.IsUnity ? LoadNativeMethodsUnity() :
+ PlatformApis.IsXamarin ? LoadNativeMethodsXamarin() :
+ new NativeMethods(LoadUnmanagedLibrary());
}
/// <summary>
@@ -128,6 +130,20 @@ namespace Grpc.Core.Internal
}
}
+ /// <summary>
+ /// Return native method delegates when running on the Xamarin platform.
+ /// WARNING: Xamarin support is experimental and work-in-progress. Don't expect it to work.
+ /// </summary>
+ private static NativeMethods LoadNativeMethodsXamarin()
+ {
+ if (PlatformApis.IsXamarinAndroid)
+ {
+ return new NativeMethods(new NativeMethods.DllImportsFromSharedLib());
+ }
+ // not tested yet
+ return new NativeMethods(new NativeMethods.DllImportsFromStaticLib());
+ }
+
private static string GetAssemblyPath()
{
var assembly = typeof(NativeExtension).GetTypeInfo().Assembly;
diff --git a/src/csharp/Grpc.Core/Internal/PlatformApis.cs b/src/csharp/Grpc.Core/Internal/PlatformApis.cs
index b90fbccb2b..6c4ee0bdb7 100644
--- a/src/csharp/Grpc.Core/Internal/PlatformApis.cs
+++ b/src/csharp/Grpc.Core/Internal/PlatformApis.cs
@@ -33,12 +33,17 @@ namespace Grpc.Core.Internal
internal static class PlatformApis
{
const string UnityEngineApplicationClassName = "UnityEngine.Application, UnityEngine";
+ const string XamarinAndroidActivityClassName = "Android.App.Activity, Mono.Android";
+ const string XamariniOSEnumClassName = "Mono.CSharp.Enum, Mono.CSharp";
static readonly bool isLinux;
static readonly bool isMacOSX;
static readonly bool isWindows;
static readonly bool isMono;
static readonly bool isNetCore;
static readonly bool isUnity;
+ static readonly bool isXamarin;
+ static readonly bool isXamariniOS;
+ static readonly bool isXamarinAndroid;
static PlatformApis()
{
@@ -58,6 +63,9 @@ namespace Grpc.Core.Internal
#endif
isMono = Type.GetType("Mono.Runtime") != null;
isUnity = Type.GetType(UnityEngineApplicationClassName) != null;
+ isXamariniOS = Type.GetType(XamariniOSEnumClassName) != null;
+ isXamarinAndroid = Type.GetType(XamarinAndroidActivityClassName) != null;
+ isXamarin = isXamariniOS || isXamarinAndroid;
}
public static bool IsLinux
@@ -89,6 +97,31 @@ namespace Grpc.Core.Internal
}
/// <summary>
+ /// true if running on a Xamarin platform (either Xamarin.Android or Xamarin.iOS),
+ /// false otherwise.
+ /// </summary>
+ public static bool IsXamarin
+ {
+ get { return isXamarin; }
+ }
+
+ /// <summary>
+ /// true if running on Xamarin.iOS, false otherwise.
+ /// </summary>
+ public static bool IsXamariniOS
+ {
+ get { return isXamariniOS; }
+ }
+
+ /// <summary>
+ /// true if running on Xamarin.Android, false otherwise.
+ /// </summary>
+ public static bool IsXamarinAndroid
+ {
+ get { return isXamarinAndroid; }
+ }
+
+ /// <summary>
/// true if running on .NET Core (CoreCLR), false otherwise.
/// </summary>
public static bool IsNetCore
diff --git a/src/csharp/Grpc.Core/Version.csproj.include b/src/csharp/Grpc.Core/Version.csproj.include
index 2b45e7ae20..cadf091e99 100755
--- a/src/csharp/Grpc.Core/Version.csproj.include
+++ b/src/csharp/Grpc.Core/Version.csproj.include
@@ -1,7 +1,7 @@
<!-- This file is generated -->
<Project>
<PropertyGroup>
- <GrpcCsharpVersion>1.14.0-dev</GrpcCsharpVersion>
+ <GrpcCsharpVersion>1.14.1-dev</GrpcCsharpVersion>
<GoogleProtobufVersion>3.5.1</GoogleProtobufVersion>
</PropertyGroup>
</Project>
diff --git a/src/csharp/Grpc.Core/build/MonoAndroid/Grpc.Core.targets b/src/csharp/Grpc.Core/build/MonoAndroid/Grpc.Core.targets
new file mode 100644
index 0000000000..f764f4cae1
--- /dev/null
+++ b/src/csharp/Grpc.Core/build/MonoAndroid/Grpc.Core.targets
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <_GrpcCoreNugetNativePath Condition="'$(_GrpcCoreNugetNativePath)' == ''">$(MSBuildThisFileDirectory)..\..\</_GrpcCoreNugetNativePath>
+ </PropertyGroup>
+
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == 'MonoAndroid'">
+ <AndroidNativeLibrary Include="$(_GrpcCoreNugetNativePath)runtimes\monoandroid\arm64-v8a\libgrpc_csharp_ext.so">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ <Abi>arm64-v8a</Abi>
+ </AndroidNativeLibrary>
+ </ItemGroup>
+
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == 'MonoAndroid'">
+ <AndroidNativeLibrary Include="$(_GrpcCoreNugetNativePath)runtimes\monoandroid\armeabi-v7a\libgrpc_csharp_ext.so">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ <Abi>armeabi-v7a</Abi>
+ </AndroidNativeLibrary>
+ </ItemGroup>
+
+</Project>
diff --git a/src/csharp/Grpc.Core/Grpc.Core.targets b/src/csharp/Grpc.Core/build/net45/Grpc.Core.targets
index cce53db82b..cce53db82b 100644
--- a/src/csharp/Grpc.Core/Grpc.Core.targets
+++ b/src/csharp/Grpc.Core/build/net45/Grpc.Core.targets
diff --git a/src/csharp/experimental/build_native_ext_for_android.sh b/src/csharp/experimental/build_native_ext_for_android.sh
index 8197df7c53..5687a43a4e 100755
--- a/src/csharp/experimental/build_native_ext_for_android.sh
+++ b/src/csharp/experimental/build_native_ext_for_android.sh
@@ -23,17 +23,29 @@ mkdir -p build
cd build
# set to the location where Android SDK is installed
-# e.g. ANDROID_NDK_PATH="$HOME/android-ndk-r16b"
+# e.g. ANDROID_SDK_PATH="$HOME/Android/Sdk"
-cmake ../.. \
- -DCMAKE_SYSTEM_NAME=Android \
- -DCMAKE_SYSTEM_VERSION=15 \
- -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a \
+# set to location where Android NDK is installed, usually a subfolder of Android SDK
+# to install the Android NKD, use the "sdkmanager" tool
+# e.g. ANDROID_NDK_PATH=${ANDROID_SDK_PATH}/ndk-bundle
+
+# set to location of the cmake executable from the Android SDK
+# to install cmake, use the "sdkmanager" tool
+# e.g. ANDROID_SDK_CMAKE=${ANDROID_SDK_PATH}/cmake/3.6.4111459/bin/cmake
+
+# ANDROID_ABI in ('arm64-v8a', 'armeabi-v7a')
+# e.g. ANDROID_ABI=armeabi-v7a
+
+${ANDROID_SDK_CMAKE} ../.. \
+ -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_PATH}/build/cmake/android.toolchain.cmake" \
-DCMAKE_ANDROID_NDK="${ANDROID_NDK_PATH}" \
-DCMAKE_ANDROID_STL_TYPE=c++_static \
-DRUN_HAVE_POSIX_REGEX=0 \
-DRUN_HAVE_STD_REGEX=0 \
-DRUN_HAVE_STEADY_CLOCK=0 \
- -DCMAKE_BUILD_TYPE=Release
+ -DCMAKE_BUILD_TYPE=Release \
+ -DANDROID_PLATFORM=android-28 \
+ -DANDROID_ABI="${ANDROID_ABI}" \
+ -DANDROID_NDK="${ANDROID_NDK_PATH}"
make -j4 grpc_csharp_ext