Remove unused cmake things

This commit is contained in:
crazywhalecc 2025-06-09 01:48:48 +08:00
parent 059d134990
commit f158fba48d
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
3 changed files with 16 additions and 67 deletions

View File

@ -4,66 +4,11 @@ declare(strict_types=1);
namespace SPC\builder\traits;
use SPC\exception\FileSystemException;
use SPC\store\FileSystem;
/**
* Unix 系统的工具函数 Trait,适用于 Linux、macOS
*/
trait UnixSystemUtilTrait
{
/**
* 生成 toolchain.cmake用于 cmake 构建
*
* @param string $os 操作系统代号
* @param string $target_arch 目标架构
* @param string $cflags CFLAGS 参数
* @param null|string $cc CC 参数(默认空)
* @param null|string $cxx CXX 参数(默认空)
* @throws FileSystemException
*/
public static function makeCmakeToolchainFile(
string $os,
string $target_arch,
string $cflags,
?string $cc = null,
?string $cxx = null
): string {
logger()->debug("making cmake tool chain file for {$os} {$target_arch} with CFLAGS='{$cflags}'");
$root = BUILD_ROOT_PATH;
$ccLine = '';
if ($cc) {
$ccLine = 'SET(CMAKE_C_COMPILER ' . $cc . ')';
}
$cxxLine = '';
if ($cxx) {
$cxxLine = 'SET(CMAKE_CXX_COMPILER ' . $cxx . ')';
}
$toolchain = <<<CMAKE
{$ccLine}
{$cxxLine}
SET(CMAKE_C_FLAGS "{$cflags}")
SET(CMAKE_CXX_FLAGS "{$cflags}")
SET(CMAKE_FIND_ROOT_PATH "{$root}")
SET(CMAKE_PREFIX_PATH "{$root}")
SET(CMAKE_INSTALL_PREFIX "{$root}")
SET(CMAKE_INSTALL_LIBDIR "lib")
set(PKG_CONFIG_EXECUTABLE "{$root}/bin/pkg-config")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_EXE_LINKER_FLAGS "-ldl -lpthread -lm -lutil")
CMAKE;
// 有时候系统的 cmake 找不到 ar 命令,真奇怪
if (PHP_OS_FAMILY === 'Linux') {
$toolchain .= "\nSET(CMAKE_AR \"ar\")";
}
FileSystem::writeFile(SOURCE_PATH . '/toolchain.cmake', $toolchain);
return realpath(SOURCE_PATH . '/toolchain.cmake');
}
/**
* @param string $name 命令名称
* @param array $paths 寻找的目标路径(如果不传入,则使用环境变量 PATH

View File

@ -4,16 +4,18 @@ declare(strict_types=1);
namespace SPC\builder\unix\executor;
use Closure;
use SPC\exception\FileSystemException;
use SPC\exception\WrongUsageException;
use SPC\store\FileSystem;
/**
* Unix-like OS cmake command executor.
*/
class UnixCMakeExecutor extends Executor
{
/** @var null|string CMake build dir */
protected ?string $cmake_build_dir = null;
/** @var array CMake additional configure arguments */
protected array $configure_args = [];
protected ?array $custom_default_args = null;
@ -80,6 +82,12 @@ class UnixCMakeExecutor extends Executor
return $this;
}
/**
* To build steps.
*
* @param int $step Step number, accept 1-3
* @return $this
*/
public function toStep(int $step): static
{
$this->steps = $step;
@ -106,6 +114,10 @@ class UnixCMakeExecutor extends Executor
return $this;
}
/**
* Set the reset status.
* If we set it to false, it will not clean and create the specified cmake working directory.
*/
public function setReset(bool $reset): static
{
$this->reset = $reset;
@ -152,6 +164,8 @@ class UnixCMakeExecutor extends Executor
}
/**
* Generate cmake toolchain file for current spc instance, and return the file path.
*
* @return string CMake toolchain file path
* @throws FileSystemException
* @throws WrongUsageException

View File

@ -8,7 +8,6 @@ use PHPUnit\Framework\TestCase;
use SPC\builder\freebsd\SystemUtil as FreebsdSystemUtil;
use SPC\builder\linux\SystemUtil as LinuxSystemUtil;
use SPC\builder\macos\SystemUtil as MacosSystemUtil;
use SPC\exception\FileSystemException;
/**
* @internal
@ -31,15 +30,6 @@ class UnixSystemUtilTest extends TestCase
$this->util = new $util_class();
}
/**
* @throws FileSystemException
*/
public function testMakeCmakeToolchainFile()
{
$str = $this->util->makeCmakeToolchainFile(PHP_OS_FAMILY, 'x86_64', '');
$this->assertIsString($str);
}
public function testFindCommand()
{
$this->assertIsString($this->util->findCommand('bash'));