aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core/Internal/NativeExtension.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/csharp/Grpc.Core/Internal/NativeExtension.cs')
-rw-r--r--src/csharp/Grpc.Core/Internal/NativeExtension.cs31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/csharp/Grpc.Core/Internal/NativeExtension.cs b/src/csharp/Grpc.Core/Internal/NativeExtension.cs
index a6d7925816..509baf7cb1 100644
--- a/src/csharp/Grpc.Core/Internal/NativeExtension.cs
+++ b/src/csharp/Grpc.Core/Internal/NativeExtension.cs
@@ -44,9 +44,6 @@ namespace Grpc.Core.Internal
/// </summary>
internal sealed class NativeExtension
{
- const string NativeLibrariesDir = "nativelibs";
- const string DnxStyleNativeLibrariesDir = "../../build/native/bin/";
-
static readonly ILogger Logger = GrpcEnvironment.Logger.ForType<NativeExtension>();
static readonly object staticLock = new object();
static volatile NativeExtension instance;
@@ -98,20 +95,25 @@ namespace Grpc.Core.Internal
private static UnmanagedLibrary Load()
{
// TODO: allow customizing path to native extension (possibly through exposing a GrpcEnvironment property).
-
- var libraryFlavor = string.Format("{0}_{1}", GetPlatformString(), GetArchitectureString());
-
+ // See https://github.com/grpc/grpc/pull/7303 for one option.
var assemblyDirectory = Path.GetDirectoryName(GetAssemblyPath());
// With old-style VS projects, the native libraries get copied using a .targets rule to the build output folder
// alongside the compiled assembly.
- var classicPath = Path.Combine(assemblyDirectory, NativeLibrariesDir, libraryFlavor, GetNativeLibraryFilename());
+ // With dotnet cli projects, the native libraries (just the required ones) are similarly copied to the built output folder,
+ // through the magic of Microsoft.NETCore.Platforms.
+ var classicPath = Path.Combine(assemblyDirectory, GetNativeLibraryFilename());
// DNX-style project.json projects will use Grpc.Core assembly directly in the location where it got restored
// by nuget. We locate the native libraries based on known structure of Grpc.Core nuget package.
- var dnxStylePath = Path.Combine(assemblyDirectory, DnxStyleNativeLibrariesDir, libraryFlavor, GetNativeLibraryFilename());
- return new UnmanagedLibrary(new string[] {classicPath, dnxStylePath});
+ // TODO: Support .NET Core applications, which act slightly differently. We may be okay if "dotnet publish"
+ // is used, but "dotnet run" leaves the native libraries in-package, while copying assemblies.
+ string platform = GetPlatformString();
+ string relativeDirectory = string.Format("../../runtimes/{0}/native", platform);
+ var dnxStylePath = Path.Combine(assemblyDirectory, relativeDirectory, GetNativeLibraryFilename());
+ string[] paths = new[] { classicPath, dnxStylePath };
+ return new UnmanagedLibrary(paths);
}
private static string GetAssemblyPath()
@@ -147,7 +149,7 @@ namespace Grpc.Core.Internal
{
if (PlatformApis.IsWindows)
{
- return "windows";
+ return "win";
}
if (PlatformApis.IsLinux)
{
@@ -155,7 +157,7 @@ namespace Grpc.Core.Internal
}
if (PlatformApis.IsMacOSX)
{
- return "macosx";
+ return "osx";
}
throw new InvalidOperationException("Unsupported platform.");
}
@@ -176,17 +178,18 @@ namespace Grpc.Core.Internal
// platform specific file name of the extension library
private static string GetNativeLibraryFilename()
{
+ string architecture = GetArchitectureString();
if (PlatformApis.IsWindows)
{
- return "grpc_csharp_ext.dll";
+ return string.Format("grpc_csharp_ext.{0}.dll", architecture);
}
if (PlatformApis.IsLinux)
{
- return "libgrpc_csharp_ext.so";
+ return string.Format("libgrpc_csharp_ext.{0}.so", architecture);
}
if (PlatformApis.IsMacOSX)
{
- return "libgrpc_csharp_ext.dylib";
+ return string.Format("libgrpc_csharp_ext.{0}.dylib", architecture);
}
throw new InvalidOperationException("Unsupported platform.");
}