Skip to content

Commit

Permalink
Changed the implementation of how the AnyCPU implementation calls the…
Browse files Browse the repository at this point in the history
… native methods and throw an exception when an unsupported architecture is detected.
  • Loading branch information
dlemstra committed Sep 12, 2024
1 parent bf7be94 commit f428c36
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 109 deletions.
15 changes: 13 additions & 2 deletions src/Magick.NET/Helpers/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ namespace ImageMagick;

internal static partial class Runtime
{
public static bool Is64Bit { get; } = IntPtr.Size == 8;
public static bool Is64Bit { get; } = Architecture is Architecture.X64 or Architecture.Arm64;

public static bool IsArm64 { get; } = RuntimeInformation.ProcessArchitecture == Architecture.Arm64;
public static Architecture Architecture { get; } = GetArchitecture();

public static bool IsWindows { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

private static Architecture GetArchitecture()
{
var processArchitecture = RuntimeInformation.ProcessArchitecture;

return processArchitecture switch
{
Architecture.X64 or Architecture.Arm64 or Architecture.X86 => processArchitecture,
_ => throw new NotSupportedException($"{processArchitecture} is an unsupported architecture, only {nameof(Architecture.X64)}, {nameof(Architecture.Arm64)} and {nameof(Architecture.X86)} are supported."),
};
}
}
2 changes: 1 addition & 1 deletion src/Magick.NET/Native/NativeLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal static class NativeLibrary

public const string X64Name = Name + "-" + QuantumName + "-x64.dll";

public const string ARM64Name = Name + "-" + QuantumName + "-arm64.dll";
public const string Arm64Name = Name + "-" + QuantumName + "-arm64.dll";

#if Q8
private const string Quantum = "Q8";
Expand Down
9 changes: 3 additions & 6 deletions tests/Magick.NET.Tests/TestHelpers/TestRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ namespace Magick.NET.Tests;

internal static class TestRuntime
{
public static bool HasFlakyLinuxArm64Result
=> IsLinux && Runtime.IsArm64;
public static bool HasFlakyLinuxArm64Result { get; } = IsLinux && Runtime.Architecture is Architecture.Arm64;

public static bool HasFlakyMacOSResult
=> IsMacOS;
public static bool HasFlakyMacOSResult { get; } = IsMacOS;

public static bool HasFlakyMacOSArm64Result
=> IsMacOS && Runtime.IsArm64;
public static bool HasFlakyMacOSArm64Result { get; } = IsMacOS && Runtime.Architecture is Architecture.Arm64;

private static bool IsLinux { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);

Expand Down
Loading

0 comments on commit f428c36

Please sign in to comment.