44 lines
1.0 KiB
PHP
Raw Normal View History

2023-03-18 17:32:21 +08:00
<?php
declare(strict_types=1);
namespace SPC\builder\macos;
use SPC\builder\traits\UnixSystemUtilTrait;
use SPC\exception\RuntimeException;
2023-03-29 21:39:36 +08:00
use SPC\exception\WrongUsageException;
2023-03-18 17:32:21 +08:00
class SystemUtil
{
/** Unix System Util Compatible */
2023-03-18 17:32:21 +08:00
use UnixSystemUtilTrait;
/**
* Get Logic CPU Count for macOS
2023-03-18 17:32:21 +08:00
*/
public static function getCpuCount(): int
{
2024-06-30 22:32:17 +08:00
[$ret, $output] = shell()->execWithResult('sysctl -n hw.ncpu', false);
2023-03-18 17:32:21 +08:00
if ($ret !== 0) {
throw new RuntimeException('Failed to get cpu count');
}
return (int) $output[0];
}
/**
* Get Target Arch CFlags
2023-03-18 17:32:21 +08:00
*
* @param string $arch Arch Name
* @return string return Arch CFlags string
2023-03-18 17:32:21 +08:00
*/
public static function getArchCFlags(string $arch): string
{
return match ($arch) {
'x86_64' => '--target=x86_64-apple-darwin',
'arm64','aarch64' => '--target=arm64-apple-darwin',
2023-03-29 21:39:36 +08:00
default => throw new WrongUsageException('unsupported arch: ' . $arch),
2023-03-18 17:32:21 +08:00
};
}
}