Skip to content

Commit

Permalink
Improve native rocksdb dependencies loading (#4445)
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Aug 22, 2022
1 parent 219fdef commit 60f920b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Nethermind/Nethermind.Runner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using System.IO.Abstractions;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -74,7 +76,7 @@ public static void Main(string[] args)
logger.Error(FailureString + eventArgs.ExceptionObject);
}
};

try
{
Run(args);
Expand Down Expand Up @@ -102,6 +104,7 @@ private static void Run(string[] args)
_logger.Info("Nethermind starting initialization.");

AppDomain.CurrentDomain.ProcessExit += CurrentDomainOnProcessExit;
AssemblyLoadContext.Default.ResolvingUnmanagedDll += OnResolvingUnmanagedDll;

GlobalDiagnosticsContext.Set("version", ClientVersion.Version);
CommandLineApplication app = new() { Name = "Nethermind.Runner" };
Expand Down Expand Up @@ -196,6 +199,21 @@ private static void Run(string[] args)
_appClosed.Wait();
}

private static IntPtr OnResolvingUnmanagedDll(Assembly _, string nativeLibraryName)
{
const string MacosSnappyPath = "/opt/homebrew/Cellar/snappy";
var alternativePath = nativeLibraryName switch
{
"libdl" or "liblibdl" => "libdl.so.2",
"libbz2.so.1.0" => "libbz2.so.1",
"libsnappy" or "snappy" => Directory.Exists(MacosSnappyPath) ?
Directory.EnumerateFiles(MacosSnappyPath, "libsnappy.dylib", SearchOption.AllDirectories).FirstOrDefault() : "libsnappy.so.1",
_ => null
};

return alternativePath is null ? IntPtr.Zero : NativeLibrary.Load(alternativePath);
}

private static void BuildOptionsFromConfigFiles(CommandLineApplication app)
{
Type configurationType = typeof(IConfig);
Expand Down

0 comments on commit 60f920b

Please sign in to comment.