diff options
Diffstat (limited to 'src/csharp/Grpc.Core')
-rwxr-xr-x | src/csharp/Grpc.Core/Grpc.Core.csproj | 30 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Internal/NativeExtension.cs | 24 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Internal/NativeLogRedirector.cs | 19 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Internal/PlatformApis.cs | 34 | ||||
-rwxr-xr-x | src/csharp/Grpc.Core/Version.csproj.include | 2 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/VersionInfo.cs | 4 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/build/MonoAndroid/Grpc.Core.targets | 28 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/build/Xamarin.iOS/Grpc.Core.targets | 15 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/build/net45/Grpc.Core.targets (renamed from src/csharp/Grpc.Core/Grpc.Core.targets) | 0 |
9 files changed, 151 insertions, 5 deletions
diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj index 6d44be7ddd..fc32271063 100755 --- a/src/csharp/Grpc.Core/Grpc.Core.csproj +++ b/src/csharp/Grpc.Core/Grpc.Core.csproj @@ -46,10 +46,38 @@ <PackagePath>runtimes/win/native/grpc_csharp_ext.x86.dll</PackagePath> <Pack>true</Pack> </Content> - <Content Include="Grpc.Core.targets"> + <Content Include="..\nativelibs\csharp_ext_linux_android_armeabi-v7a\libgrpc_csharp_ext.so"> + <PackagePath>runtimes/monoandroid/armeabi-v7a/libgrpc_csharp_ext.so</PackagePath> + <Pack>true</Pack> + </Content> + <Content Include="..\nativelibs\csharp_ext_linux_android_arm64-v8a\libgrpc_csharp_ext.so"> + <PackagePath>runtimes/monoandroid/arm64-v8a/libgrpc_csharp_ext.so</PackagePath> + <Pack>true</Pack> + </Content> + <Content Include="..\nativelibs\csharp_ext_linux_android_x86\libgrpc_csharp_ext.so"> + <PackagePath>runtimes/monoandroid/x86/libgrpc_csharp_ext.so</PackagePath> + <Pack>true</Pack> + </Content> + <Content Include="..\nativelibs\csharp_ext_macos_ios\libgrpc_csharp_ext.a"> + <PackagePath>runtimes/ios/native/libgrpc_csharp_ext.a</PackagePath> + <Pack>true</Pack> + </Content> + <Content Include="..\nativelibs\csharp_ext_macos_ios\libgrpc.a"> + <PackagePath>runtimes/ios/native/libgrpc.a</PackagePath> + <Pack>true</Pack> + </Content> + <Content Include="build\net45\Grpc.Core.targets"> <PackagePath>build/net45/</PackagePath> <Pack>true</Pack> </Content> + <Content Include="build\MonoAndroid\Grpc.Core.targets"> + <PackagePath>build/MonoAndroid/</PackagePath> + <Pack>true</Pack> + </Content> + <Content Include="build\Xamarin.iOS\Grpc.Core.targets"> + <PackagePath>build/Xamarin.iOS/</PackagePath> + <Pack>true</Pack> + </Content> </ItemGroup> <ItemGroup> diff --git a/src/csharp/Grpc.Core/Internal/NativeExtension.cs b/src/csharp/Grpc.Core/Internal/NativeExtension.cs index d5ec998bbd..f526b913af 100644 --- a/src/csharp/Grpc.Core/Internal/NativeExtension.cs +++ b/src/csharp/Grpc.Core/Internal/NativeExtension.cs @@ -106,7 +106,15 @@ namespace Grpc.Core.Internal /// </summary> private static NativeMethods LoadNativeMethods() { - return PlatformApis.IsUnity ? LoadNativeMethodsUnity() : new NativeMethods(LoadUnmanagedLibrary()); + if (PlatformApis.IsUnity) + { + return LoadNativeMethodsUnity(); + } + if (PlatformApis.IsXamarin) + { + return LoadNativeMethodsXamarin(); + } + return new NativeMethods(LoadUnmanagedLibrary()); } /// <summary> @@ -128,6 +136,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/NativeLogRedirector.cs b/src/csharp/Grpc.Core/Internal/NativeLogRedirector.cs index bf6440123a..30264acb10 100644 --- a/src/csharp/Grpc.Core/Internal/NativeLogRedirector.cs +++ b/src/csharp/Grpc.Core/Internal/NativeLogRedirector.cs @@ -51,6 +51,7 @@ namespace Grpc.Core.Internal } } + [MonoPInvokeCallback(typeof(GprLogDelegate))] private static void HandleWrite(IntPtr fileStringPtr, int line, ulong threadId, IntPtr severityStringPtr, IntPtr msgPtr) { try @@ -86,4 +87,22 @@ namespace Grpc.Core.Internal } } } + + /// <summary> + /// Use this attribute to mark methods that will be called back from P/Invoke calls. + /// iOS (and probably other AOT platforms) needs to have delegates registered. + /// Instead of depending on Xamarin.iOS for this, we can just create our own, + /// the iOS runtime just checks for the type name. + /// See: https://docs.microsoft.com/en-gb/xamarin/ios/internals/limitations#reverse-callbacks + /// </summary> + [AttributeUsage(AttributeTargets.Method)] + internal sealed class MonoPInvokeCallbackAttribute : Attribute + { + public MonoPInvokeCallbackAttribute(Type type) + { + Type = type; + } + + public Type Type { get; private set; } + } } diff --git a/src/csharp/Grpc.Core/Internal/PlatformApis.cs b/src/csharp/Grpc.Core/Internal/PlatformApis.cs index b90fbccb2b..c501aa89fb 100644 --- a/src/csharp/Grpc.Core/Internal/PlatformApis.cs +++ b/src/csharp/Grpc.Core/Internal/PlatformApis.cs @@ -33,12 +33,18 @@ namespace Grpc.Core.Internal internal static class PlatformApis { const string UnityEngineApplicationClassName = "UnityEngine.Application, UnityEngine"; + const string XamarinAndroidObjectClassName = "Java.Lang.Object, Mono.Android"; + const string XamarinIOSObjectClassName = "Foundation.NSObject, Xamarin.iOS"; + 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 +64,9 @@ namespace Grpc.Core.Internal #endif isMono = Type.GetType("Mono.Runtime") != null; isUnity = Type.GetType(UnityEngineApplicationClassName) != null; + isXamarinIOS = Type.GetType(XamarinIOSObjectClassName) != null; + isXamarinAndroid = Type.GetType(XamarinAndroidObjectClassName) != null; + isXamarin = isXamarinIOS || isXamarinAndroid; } public static bool IsLinux @@ -89,6 +98,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..1a746acdd4 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.15.0-dev</GrpcCsharpVersion> <GoogleProtobufVersion>3.5.1</GoogleProtobufVersion> </PropertyGroup> </Project> diff --git a/src/csharp/Grpc.Core/VersionInfo.cs b/src/csharp/Grpc.Core/VersionInfo.cs index c4531e5275..295e0f2577 100644 --- a/src/csharp/Grpc.Core/VersionInfo.cs +++ b/src/csharp/Grpc.Core/VersionInfo.cs @@ -33,11 +33,11 @@ namespace Grpc.Core /// <summary> /// Current <c>AssemblyFileVersion</c> of gRPC C# assemblies /// </summary> - public const string CurrentAssemblyFileVersion = "1.14.0.0"; + public const string CurrentAssemblyFileVersion = "1.15.0.0"; /// <summary> /// Current version of gRPC C# /// </summary> - public const string CurrentVersion = "1.14.0-dev"; + public const string CurrentVersion = "1.15.0-dev"; } } 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..d75e5a2f2f --- /dev/null +++ b/src/csharp/Grpc.Core/build/MonoAndroid/Grpc.Core.targets @@ -0,0 +1,28 @@ +<?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> + + <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == 'MonoAndroid'"> + <AndroidNativeLibrary Include="$(_GrpcCoreNugetNativePath)runtimes\monoandroid\x86\libgrpc_csharp_ext.so"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + <Abi>x86</Abi> + </AndroidNativeLibrary> + </ItemGroup> + +</Project> 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 0000000000..658158f6ea --- /dev/null +++ b/src/csharp/Grpc.Core/build/Xamarin.iOS/Grpc.Core.targets @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + + <ItemGroup> + <NativeReference Include="$(MSBuildThisFileDirectory)..\..\runtimes\ios\native\libgrpc_csharp_ext.a"> + <Kind>Static</Kind> + <ForceLoad>True</ForceLoad> + </NativeReference> + <NativeReference Include="$(MSBuildThisFileDirectory)..\..\runtimes\ios\native\libgrpc.a"> + <Kind>Static</Kind> + <ForceLoad>True</ForceLoad> + </NativeReference> + </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 |