Skip to content

Commit 7860d66

Browse files
committed
Fix MacOS detection due to dotnet/runtime/issues/21660
1 parent 6774ba7 commit 7860d66

1 file changed

Lines changed: 37 additions & 30 deletions

File tree

dotnet/Client.cs

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -831,37 +831,44 @@ private static string GetLibraryPath()
831831
{
832832
string libfile;
833833
var arc = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture;
834-
switch (Environment.OSVersion.Platform)
834+
bool dumpLoadingPaths = Environment.GetEnvironmentVariable("DEBUG") != null ? true : false;
835+
if(dumpLoadingPaths) Console.WriteLine("***************");
836+
if(dumpLoadingPaths) Console.WriteLine($"Architecture: {arc}");
837+
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
835838
{
836-
case PlatformID.Win32NT:
837-
if (Environment.Is64BitProcess)
838-
{
839-
libfile = arc == Architecture.X64 ? "openiap-windows-x64.dll" : "openiap-windows-arm64.dll";
840-
}
841-
else
842-
{
843-
libfile = "openiap-windows-i686.dll";
844-
}
845-
break;
846-
case PlatformID.MacOSX:
847-
if (!Environment.Is64BitProcess) throw new LibraryLoadError("macOS requires a 64-bit process");
848-
libfile = arc == Architecture.Arm64 ? "libopeniap-macos-arm64.dylib" : "libopeniap-macos-x64.dylib";
849-
break;
850-
case PlatformID.Unix:
851-
if (!Environment.Is64BitProcess) throw new LibraryLoadError("Linux requires a 64-bit process");
852-
if (System.IO.File.Exists("/etc/alpine-release"))
853-
{
854-
libfile = arc == Architecture.Arm64 ? "libopeniap-linux-musl-arm64.a" : "libopeniap-linux-musl-x64.a";
855-
}
856-
else
857-
{
858-
libfile = arc == Architecture.Arm64 ? "libopeniap-linux-arm64.so" : "libopeniap-linux-x64.so";
859-
}
860-
break;
861-
default:
862-
throw new PlatformNotSupportedException("Unsupported OS platform");
839+
if(dumpLoadingPaths) Console.WriteLine("OS: Windows");
840+
if (Environment.Is64BitProcess)
841+
{
842+
libfile = arc == Architecture.X64 ? "openiap-windows-x64.dll" : "openiap-windows-arm64.dll";
843+
}
844+
else
845+
{
846+
libfile = "openiap-windows-i686.dll";
847+
}
848+
}
849+
else if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
850+
{
851+
if(dumpLoadingPaths) Console.WriteLine("OS: Linux");
852+
if (!Environment.Is64BitProcess) throw new LibraryLoadError("Linux requires a 64-bit process");
853+
if (System.IO.File.Exists("/etc/alpine-release"))
854+
{
855+
libfile = arc == Architecture.Arm64 ? "libopeniap-linux-musl-arm64.a" : "libopeniap-linux-musl-x64.a";
856+
}
857+
else
858+
{
859+
libfile = arc == Architecture.Arm64 ? "libopeniap-linux-arm64.so" : "libopeniap-linux-x64.so";
860+
}
861+
}
862+
else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
863+
{
864+
if(dumpLoadingPaths) Console.WriteLine("OS: macOS");
865+
if (!Environment.Is64BitProcess) throw new LibraryLoadError("macOS requires a 64-bit process");
866+
libfile = arc == Architecture.Arm64 ? "libopeniap-macos-arm64.dylib" : "libopeniap-macos-x64.dylib";
867+
}
868+
else
869+
{
870+
throw new PlatformNotSupportedException("Unsupported OS platform");
863871
}
864-
bool dumpLoadingPaths = false;
865872
if(dumpLoadingPaths) Console.WriteLine("****************************");
866873
if(dumpLoadingPaths) Console.WriteLine($"Loading library {libfile} for {Environment.OSVersion.Platform} ({arc})");
867874

@@ -3269,7 +3276,7 @@ public void UnRegisterQueue(string queuename)
32693276
Marshal.FreeHGlobal(queuenamePtr);
32703277
}
32713278
}
3272-
public async Task QueueMessage(string data, string queuename = "", string exchangename = "", string routingkey = "", string correlation_id = "", bool striptoken = false, int expiration = 0)
3279+
public async Task QueueMessage(string data, string queuename = "", string exchangename = "", string routingkey = "", string correlation_id = "", bool striptoken = false, int expiration = 0)
32733280
{
32743281
var tcs = new TaskCompletionSource<string>();
32753282
IntPtr dataPtr = Marshal.StringToHGlobalAnsi(data);

0 commit comments

Comments
 (0)