diff options
author | Jan Tattermusch <jtattermusch@google.com> | 2016-09-21 19:57:10 +0200 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2016-09-21 19:57:19 +0200 |
commit | 4d2df96ff58429961f7b63bdd0c9ceeea1d2fe44 (patch) | |
tree | 9f9a05ea151b458ac705a28883d5e823f8244532 /src | |
parent | d23f8166d862cf7767b68944b44af92b88212383 (diff) |
dont require libc-dev on coreclr
Diffstat (limited to 'src')
-rw-r--r-- | src/csharp/Grpc.Core/Internal/PlatformApis.cs | 11 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs | 22 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/csharp/Grpc.Core/Internal/PlatformApis.cs b/src/csharp/Grpc.Core/Internal/PlatformApis.cs index 15391ddc64..406204e0a7 100644 --- a/src/csharp/Grpc.Core/Internal/PlatformApis.cs +++ b/src/csharp/Grpc.Core/Internal/PlatformApis.cs @@ -50,6 +50,7 @@ namespace Grpc.Core.Internal static readonly bool isMacOSX; static readonly bool isWindows; static readonly bool isMono; + static readonly bool isNetCore; static PlatformApis() { @@ -57,6 +58,7 @@ namespace Grpc.Core.Internal isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); isMacOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + isNetCore = RuntimeInformation.FrameworkDescription.StartsWith(".NET Core"); #else var platform = Environment.OSVersion.Platform; @@ -64,6 +66,7 @@ namespace Grpc.Core.Internal isMacOSX = (platform == PlatformID.Unix && GetUname() == "Darwin"); isLinux = (platform == PlatformID.Unix && !isMacOSX); isWindows = (platform == PlatformID.Win32NT || platform == PlatformID.Win32S || platform == PlatformID.Win32Windows); + isNetCore = false; #endif isMono = Type.GetType("Mono.Runtime") != null; } @@ -88,6 +91,14 @@ namespace Grpc.Core.Internal get { return isMono; } } + /// <summary> + /// true if running on .NET Core (CoreCLR), false otherwise. + /// </summary> + public static bool IsNetCore + { + get { return isNetCore; } + } + public static bool Is64Bit { get { return IntPtr.Size == 8; } diff --git a/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs b/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs index dc629bd714..0b934f823b 100644 --- a/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs +++ b/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs @@ -114,6 +114,10 @@ namespace Grpc.Core.Internal { return Mono.dlsym(this.handle, symbolName); } + if (PlatformApis.IsNetCore) + { + return CoreCLR.dlsym(this.handle, symbolName); + } return Linux.dlsym(this.handle, symbolName); } if (PlatformApis.IsMacOSX) @@ -149,6 +153,10 @@ namespace Grpc.Core.Internal { return Mono.dlopen(libraryPath, RTLD_GLOBAL + RTLD_LAZY); } + if (PlatformApis.IsNetCore) + { + return CoreCLR.dlopen(libraryPath, RTLD_GLOBAL + RTLD_LAZY); + } return Linux.dlopen(libraryPath, RTLD_GLOBAL + RTLD_LAZY); } if (PlatformApis.IsMacOSX) @@ -215,5 +223,19 @@ namespace Grpc.Core.Internal [DllImport("__Internal")] internal static extern IntPtr dlsym(IntPtr handle, string symbol); } + + /// <summary> + /// Similarly as for Mono on Linux, we load symbols for + /// dlopen and dlsym from the "libcoreclr.so", + /// to avoid the dependency on libc-dev Linux. + /// </summary> + private static class CoreCLR + { + [DllImport("libcoreclr.so")] + internal static extern IntPtr dlopen(string filename, int flags); + + [DllImport("libcoreclr.so")] + internal static extern IntPtr dlsym(IntPtr handle, string symbol); + } } } |