fix(quic): statically link MsQuic for Alpine nodes [CI]
This commit is contained in:
1 parent
0d08e90dab
commit
a44895d860
17 files changed
+363
-65
No files matched your search
@@ -7,11 +7,13 @@ internal static class MsQuicRuntime
|
||||
{
|
||||
private const uint ApiVersion = 2;
|
||||
private static readonly object s_gate = new();
|
||||
#if !MOSHIRO_STATIC_MSQUIC
|
||||
private static nint s_library;
|
||||
private static nint s_api;
|
||||
private static OpenVersionDelegate? s_open;
|
||||
private static CloseDelegate? s_close;
|
||||
private static readonly List<nint> s_supportLibraries = [];
|
||||
#endif
|
||||
private static nint s_api;
|
||||
|
||||
public static nint Api
|
||||
{
|
||||
@@ -19,6 +21,19 @@ internal static class MsQuicRuntime
|
||||
{
|
||||
lock (s_gate)
|
||||
{
|
||||
#if MOSHIRO_STATIC_MSQUIC
|
||||
if (s_api == 0)
|
||||
{
|
||||
int status = OpenStatic(ApiVersion, out s_api);
|
||||
if (status != 0 || s_api == 0)
|
||||
{
|
||||
s_api = 0;
|
||||
throw new InvalidOperationException($"MsQuic API v{ApiVersion} could not be opened (status {status}).");
|
||||
}
|
||||
}
|
||||
|
||||
return s_api;
|
||||
#else
|
||||
if (s_api != 0)
|
||||
{
|
||||
return s_api;
|
||||
@@ -57,6 +72,7 @@ internal static class MsQuicRuntime
|
||||
}
|
||||
|
||||
return s_api;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,6 +81,13 @@ internal static class MsQuicRuntime
|
||||
{
|
||||
lock (s_gate)
|
||||
{
|
||||
#if MOSHIRO_STATIC_MSQUIC
|
||||
if (s_api != 0)
|
||||
{
|
||||
CloseStatic(s_api);
|
||||
s_api = 0;
|
||||
}
|
||||
#else
|
||||
if (s_api != 0)
|
||||
{
|
||||
s_close!(s_api);
|
||||
@@ -83,9 +106,11 @@ internal static class MsQuicRuntime
|
||||
}
|
||||
|
||||
s_supportLibraries.Clear();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if !MOSHIRO_STATIC_MSQUIC
|
||||
private static void LoadBundledSupportLibraries()
|
||||
{
|
||||
if (OperatingSystem.IsLinux())
|
||||
@@ -106,13 +131,22 @@ internal static class MsQuicRuntime
|
||||
s_supportLibraries.Add(handle);
|
||||
}
|
||||
}
|
||||
#else
|
||||
[DllImport("__Internal", EntryPoint = "MsQuicOpenVersion", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern int OpenStatic(uint version, out nint api);
|
||||
|
||||
[DllImport("__Internal", EntryPoint = "MsQuicClose", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern void CloseStatic(nint api);
|
||||
#endif
|
||||
|
||||
public static T Function<T>(int index)
|
||||
where T : Delegate => Marshal.GetDelegateForFunctionPointer<T>(Marshal.ReadIntPtr(Api, checked(index * IntPtr.Size)));
|
||||
|
||||
#if !MOSHIRO_STATIC_MSQUIC
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate int OpenVersionDelegate(uint version, out nint api);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate void CloseDelegate(nint api);
|
||||
#endif
|
||||
}
|
||||
Reference in new issue
Block a user