Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/2.x] Make PlatformConfiguration properties trimmable (fixes tvOS compilation) #2734

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading