-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathNativeLibraryLoader.cs
More file actions
48 lines (41 loc) · 1.37 KB
/
Copy pathNativeLibraryLoader.cs
File metadata and controls
48 lines (41 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace DuckDB.NET.Benchmarks;
/// <summary>
/// Loads the platform-native DuckDB library for the benchmark process.
/// </summary>
internal static class NativeLibraryLoader
{
[ModuleInitializer]
public static void Init()
{
if (GetRid() is not { } rid)
{
return;
}
_ = NativeLibrary.TryLoad(Path.Join("runtimes", rid, "native", "duckdb"), Assembly.GetExecutingAssembly(), DllImportSearchPath.AssemblyDirectory, out _) ||
NativeLibrary.TryLoad(Path.Join("runtimes", rid, "native", "libduckdb"), Assembly.GetExecutingAssembly(), DllImportSearchPath.AssemblyDirectory, out _);
}
private static string? GetRid()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return Environment.Is64BitProcess ? "win-x64" : "win-x86";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return RuntimeInformation.ProcessArchitecture switch
{
Architecture.X64 => "linux-x64",
Architecture.Arm64 => "linux-arm64",
_ => null,
};
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return "osx";
}
return null;
}
}