Preload SQLite native lib from extension dir (0.15.13).
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using SQLitePCL;
|
||||
|
||||
@@ -5,7 +8,9 @@ namespace Mrleo1nid.SwarmAssistent;
|
||||
|
||||
/// <summary>
|
||||
/// SwarmUI loads extensions in an isolated AssemblyLoadContext — Microsoft.Data.Sqlite
|
||||
/// does not auto-init native SQLite there. Call once before the first connection.
|
||||
/// does not auto-init native SQLite there. Native libs ship under the extension dir
|
||||
/// (runtimes/linux-x64/native/libe_sqlite3.so), but the loader searches the host
|
||||
/// base dir unless we preload from the extension assembly location.
|
||||
/// </summary>
|
||||
internal static class AssistentSqliteBootstrap
|
||||
{
|
||||
@@ -17,6 +22,42 @@ internal static class AssistentSqliteBootstrap
|
||||
{
|
||||
return;
|
||||
}
|
||||
PreloadNativeLibrary();
|
||||
Batteries_V2.Init();
|
||||
}
|
||||
|
||||
static void PreloadNativeLibrary()
|
||||
{
|
||||
string extDir = Path.GetDirectoryName(typeof(AssistentSqliteBootstrap).Assembly.Location)
|
||||
?? AppContext.BaseDirectory
|
||||
?? "";
|
||||
if (string.IsNullOrWhiteSpace(extDir))
|
||||
{
|
||||
return;
|
||||
}
|
||||
string[] relPaths =
|
||||
[
|
||||
Path.Combine("runtimes", "linux-x64", "native", "libe_sqlite3.so"),
|
||||
Path.Combine("runtimes", "linux-x64", "native", "e_sqlite3.so"),
|
||||
"libe_sqlite3.so",
|
||||
"e_sqlite3.so",
|
||||
];
|
||||
foreach (string rel in relPaths)
|
||||
{
|
||||
string path = Path.Combine(extDir, rel);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
try
|
||||
{
|
||||
NativeLibrary.Load(path);
|
||||
return;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SwarmUI.Utils.Logs.Debug($"AssistentSqliteBootstrap: NativeLibrary.Load({path}): {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user