Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove unused cmake things
  • Loading branch information
crazywhalecc committed Jun 8, 2025
commit f158fba48df405bf407d75f451e3daa135cc7247
55 changes: 0 additions & 55 deletions src/SPC/builder/traits/UnixSystemUtilTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,11 @@

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)
Expand Down
18 changes: 16 additions & 2 deletions src/SPC/builder/unix/executor/UnixCMakeExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

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;
Expand Down Expand Up @@ -80,6 +82,12 @@ public function addConfigureArgs(...$args): static
return $this;
}

/**
* To build steps.
*
* @param int $step Step number, accept 1-3
* @return $this
*/
public function toStep(int $step): static
{
$this->steps = $step;
Expand All @@ -106,6 +114,10 @@ public function setCustomDefaultArgs(...$args): static
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;
Expand Down Expand Up @@ -152,6 +164,8 @@ private function initCMakeBuildDir(): void
}

/**
* Generate cmake toolchain file for current spc instance, and return the file path.
*
* @return string CMake toolchain file path
* @throws FileSystemException
* @throws WrongUsageException
Expand Down
10 changes: 0 additions & 10 deletions tests/SPC/builder/unix/UnixSystemUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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
Expand All @@ -31,15 +30,6 @@ public function setUp(): void
$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'));
Expand Down