Esempio n. 1
0
        static Platform()
        {
            Os = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? OsKind.Windows
               : RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? OsKind.Linux
               : RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? OsKind.MacOsX
               : OsKind.Unknown;

            switch (RuntimeInformation.OSArchitecture)
            {
            case Architecture.X86: Cpu = CpuKind.X86; break;

            case Architecture.X64: Cpu = CpuKind.X64; break;

            // We do not have build tools for other architectures.
            default: Cpu = CpuKind.Unknown; break;
            }
        }
Esempio n. 2
0
        static Platform()
        {
#if NETCORE
            Os = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? OsKind.Windows
               : RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? OsKind.Linux
               : RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? OsKind.MacOsX
               : OsKind.Unknown;

            switch (RuntimeInformation.OSArchitecture)
            {
            case Architecture.X86: Cpu = CpuKind.X86; break;

            case Architecture.X64: Cpu = CpuKind.X64; break;

            // We do not have build tools for other architectures.
            default: Cpu = CpuKind.Unknown; break;
            }
#else
            // Running under either Mono or full MS framework.
            Os = OsKind.Windows;
            if (Type.GetType("Mono.Runtime", throwOnError: false) != null)
            {
                // Congratulations. We are running under Mono.
                var plat = Environment.OSVersion.Platform;
                if (plat == PlatformID.MacOSX)
                {
                    Os = OsKind.MacOsX;
                }
                else if (plat == PlatformID.Unix || (int)plat == 128)
                {
                    // This is how Mono detects OSX internally.
                    Os = File.Exists("/usr/lib/libc.dylib") ? OsKind.MacOsX : OsKind.Linux;
                }
            }

            // Hope we are not building on ARM under Xamarin!
            Cpu = Environment.Is64BitOperatingSystem ? CpuKind.X64 : CpuKind.X86;
#endif
        }
Esempio n. 3
0
        static Platform()
        {
#if NETCORE
            Os = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? OsKind.Windows
               : RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? OsKind.Linux
               : RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? OsKind.MacOsX
               : OsKind.Unknown;

            switch (RuntimeInformation.ProcessArchitecture)
            {
            case Architecture.X86: Cpu = CpuKind.X86; break;

            case Architecture.X64: Cpu = CpuKind.X64; break;

            // We do not have build tools for other architectures.
            default: Cpu = CpuKind.Unknown; break;
            }
#else
            // Using the same best-effort detection logic as Grpc.Core/PlatformApis.cs
            var platform = Environment.OSVersion.Platform;
            if (platform == PlatformID.Win32NT || platform == PlatformID.Win32S || platform == PlatformID.Win32Windows)
            {
                Os = OsKind.Windows;
            }
            else if (platform == PlatformID.Unix && GetUname() == "Darwin")
            {
                Os = OsKind.MacOsX;
            }
            else
            {
                Os = OsKind.Linux;
            }

            // Hope we are not building on ARM under Xamarin!
            Cpu = Environment.Is64BitProcess ? CpuKind.X64 : CpuKind.X86;
#endif
        }