Skip to content

Commit

Permalink
Make PlatformConfiguration properties trimmable (#2717) (#2734)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8c296e5)

Co-authored-by: Max Katz <maxkatz6@outlook.com>
  • Loading branch information
github-actions[bot] and maxkatz6 authored Mar 1, 2024
1 parent 76ed7a0 commit 66aa5b7
Showing 1 changed file with 37 additions and 27 deletions.
64 changes: 37 additions & 27 deletions binding/Binding.Shared/PlatformConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,52 @@ public static class PlatformConfiguration
{
private const string LibCLibrary = "libc";

public static bool IsUnix { get; }
public static bool IsUnix => IsMac || IsLinux;

public static bool IsWindows { get; }

public static bool IsMac { get; }

public static bool IsLinux { get; }

public static bool IsArm { get; }

public static bool Is64Bit { get; }
public static bool IsWindows {
#if WINDOWS_UWP
get => true;
#elif NET6_0_OR_GREATER
get => OperatingSystem.IsWindows ();
#else
get => RuntimeInformation.IsOSPlatform (OSPlatform.Windows);
#endif
}

static PlatformConfiguration ()
{
public static bool IsMac {
#if WINDOWS_UWP
IsMac = false;
IsLinux = false;
IsUnix = false;
IsWindows = true;

var arch = Package.Current.Id.Architecture;
const ProcessorArchitecture arm64 = (ProcessorArchitecture)12;
IsArm = arch == ProcessorArchitecture.Arm || arch == arm64;
get => false;
#elif NET6_0_OR_GREATER
get => OperatingSystem.IsMacOS ();
#else
IsMac = RuntimeInformation.IsOSPlatform (OSPlatform.OSX);
IsLinux = RuntimeInformation.IsOSPlatform (OSPlatform.Linux);
IsUnix = IsMac || IsLinux;
IsWindows = RuntimeInformation.IsOSPlatform (OSPlatform.Windows);
get => RuntimeInformation.IsOSPlatform (OSPlatform.OSX);
#endif
}

var arch = RuntimeInformation.ProcessArchitecture;
IsArm = arch == Architecture.Arm || arch == Architecture.Arm64;
public static bool IsLinux {
#if WINDOWS_UWP
get => false;
#elif NET6_0_OR_GREATER
get => OperatingSystem.IsLinux ();
#else
get => RuntimeInformation.IsOSPlatform (OSPlatform.Linux);
#endif
}

Is64Bit = IntPtr.Size == 8;
public static bool IsArm {
#if WINDOWS_UWP
get {
var arch = Package.Current.Id.Architecture;
const ProcessorArchitecture arm64 = (ProcessorArchitecture)12;
return arch == ProcessorArchitecture.Arm || arch == arm64;
}
#else
get => RuntimeInformation.ProcessArchitecture is Architecture.Arm or Architecture.Arm64;
#endif
}

public static bool Is64Bit => IntPtr.Size == 8;

private static string linuxFlavor;

public static string LinuxFlavor
Expand Down

0 comments on commit 66aa5b7

Please sign in to comment.