From 07d9815ee704ec36c68dc54256871c40c6f843d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com>
Date: Sat, 11 Apr 2026 16:55:52 +0800
Subject: [PATCH 1/3] add loader cache.
---
.../TedToolkit.CppInteropGen/CppObject.cs | 24 ++++++++-----------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/src/libraries/TedToolkit.CppInteropGen/CppObject.cs b/src/libraries/TedToolkit.CppInteropGen/CppObject.cs
index 07a3024..dc6bbca 100644
--- a/src/libraries/TedToolkit.CppInteropGen/CppObject.cs
+++ b/src/libraries/TedToolkit.CppInteropGen/CppObject.cs
@@ -7,7 +7,14 @@ namespace TedToolkit.CppInteropGen;
public abstract class CppObject(bool disposed = false) : IDisposable
{
private bool _disposed = disposed;
+ private NativeFunctionLoader? _loader;
protected abstract string FileName { get; }
+
+ private static readonly string Rid = (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win" :
+ RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "linux" :
+ RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "osx" :
+ throw new PlatformNotSupportedException("Unsupported OS platform"))
+ + "-" + RuntimeInformation.OSArchitecture.ToString().ToLower();
private string FileFullPath
{
@@ -18,22 +25,11 @@ private string FileFullPath
var fullPath = Path.Combine(basePath, fileName);
if (File.Exists(fullPath)) return fullPath;
- var ridPath = Path.Combine(basePath, "runtimes", GetRid(), "native", fileName);
+ var ridPath = Path.Combine(basePath, "runtimes", Rid, "native", fileName);
if (File.Exists(ridPath)) return ridPath;
throw new DllNotFoundException($"Native library not found: {fullPath} or {ridPath}");
-
- static string GetRid()
- {
- var prefix =
- RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win" :
- RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "linux" :
- RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "osx" :
- throw new PlatformNotSupportedException("Unsupported OS platform");
-
- return prefix + "-" + RuntimeInformation.OSArchitecture.ToString().ToLower();
- }
-
+
static string GetLibraryFileName(string baseName)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@@ -61,7 +57,7 @@ void IDisposable.Dispose()
/// Get the Method Pointer.
///
protected IntPtr GetFunctionPointer(string name) =>
- NativeFunctionLoader.GetLoader(FileFullPath).GetFunctionPointer(name);
+ (_loader ??= NativeFunctionLoader.GetLoader(FileFullPath)).GetFunctionPointer(name);
[DebuggerStepThrough]
protected unsafe void ThrowIfError(IntPtr errorPtr)
From e4543b239e51c064b4ce61820393018d2747b8d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com>
Date: Sat, 11 Apr 2026 17:01:14 +0800
Subject: [PATCH 2/3] fix, change the library to package.
---
Directory.Build.props | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Directory.Build.props b/Directory.Build.props
index 6f4fb77..0cd8be5 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -12,7 +12,7 @@
$(MSBuildProjectDirectory.Contains('applications'))
$(MSBuildProjectDirectory.Contains('libraries'))
False
- True
+ True
False
True
False
From cacc499c8c01f349059a83449d90bfc19fe696d2 Mon Sep 17 00:00:00 2001
From: nuke-bot
Date: Sat, 11 Apr 2026 09:05:51 +0000
Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=96=202026.4.11.0=20Released!?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Directory.Build.props | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Directory.Build.props b/Directory.Build.props
index 0cd8be5..74bc064 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,7 +1,7 @@
- 2026.2.2.0
+ 2026.4.11.0
enable
enable
preview