-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathNativeLibraryHelper.cs
More file actions
45 lines (38 loc) · 1.25 KB
/
Copy pathNativeLibraryHelper.cs
File metadata and controls
45 lines (38 loc) · 1.25 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
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
namespace DuckDB.NET.Test.Helpers;
static class NativeLibraryHelper
{
public static bool TryLoad()
{
if (GetRid() is not { } rid)
{
return false;
}
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;
}
}