Preload SQLite native lib from extension dir (0.15.13).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Leonid Pershin
2026-08-23 20:31:12 +03:00
co-authored by Cursor
parent c170aff4e3
commit 5a7a72d972
3 changed files with 52 additions and 3 deletions
+42 -1
View File
@@ -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}");
}
}
}
}