From 521af84797447ac281f24e8f3c908424d125d645 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 00:16:18 +0800 Subject: [PATCH 01/14] Add cmake executor and default library path var wrapper --- src/SPC/builder/LibraryBase.php | 15 ++ src/SPC/builder/unix/executor/Executor.php | 22 +++ .../unix/executor/UnixCMakeExecutor.php | 180 ++++++++++++++++++ 3 files changed, 217 insertions(+) create mode 100644 src/SPC/builder/unix/executor/Executor.php create mode 100644 src/SPC/builder/unix/executor/UnixCMakeExecutor.php diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index abf9dd50..0d8ab739 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -328,6 +328,21 @@ abstract class LibraryBase return false; } + public function getIncludeDir(): string + { + return BUILD_INCLUDE_PATH; + } + + public function getBuildRootPath(): string + { + return BUILD_ROOT_PATH; + } + + public function getLibDir(): string + { + return BUILD_LIB_PATH; + } + /** * Build this library. * diff --git a/src/SPC/builder/unix/executor/Executor.php b/src/SPC/builder/unix/executor/Executor.php new file mode 100644 index 00000000..0d50d49a --- /dev/null +++ b/src/SPC/builder/unix/executor/Executor.php @@ -0,0 +1,22 @@ +initCMakeBuildDir(); + FileSystem::resetDir($this->cmake_build_dir); + + // prepare environment variables + $env = [ + 'CFLAGS' => $this->library->getLibExtraCFlags(), + 'LDFLAGS' => $this->library->getLibExtraLdFlags(), + 'LIBS' => $this->library->getLibExtraLibs(), + ]; + + // prepare shell + $shell = shell()->cd($this->cmake_build_dir)->setEnv($env); + + // config + $shell->execWithEnv("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()}"); + + // make + $shell->execWithEnv("cmake --build . -j {$this->library->getBuilder()->concurrency}"); + + // install + $shell->execWithEnv('make install'); + } + + /** + * Add optional library configuration. + * This method checks if a library is available and adds the corresponding arguments to the CMake configuration. + * + * @param string $name library name to check + * @param string $true_args arguments to use if the library is available + * @param string $false_args arguments to use if the library is not available + * @return $this + */ + public function optionalLib(string $name, string $true_args, string $false_args = ''): static + { + $this->addConfigureArgs($this->library->getBuilder()->getLib($name) ? $true_args : $false_args); + return $this; + } + + /** + * Add configure args. + */ + public function addConfigureArgs(...$args): static + { + $this->configure_args = [$this->configure_args, ...$args]; + return $this; + } + + /** + * Set custom CMake build directory. + * + * @param string $dir custom CMake build directory + */ + public function setCMakeBuildDir(string $dir): static + { + $this->cmake_build_dir = $dir; + return $this; + } + + /** + * Set the custom default args. + */ + public function setCustomDefaultArgs(...$args): static + { + $this->custom_default_args = $args; + return $this; + } + + /** + * Get configure argument line. + */ + private function getConfigureArgs(): string + { + return implode(' ', $this->configure_args); + } + + /** + * @throws WrongUsageException + * @throws FileSystemException + */ + private function getDefaultCMakeArgs(): string + { + return implode(' ', $this->custom_default_args ?? [ + '-DCMAKE_BUILD_TYPE=Release', + "-DCMAKE_INSTALL_PREFIX={$this->library->getBuildRootPath()}", + '-DCMAKE_INSTALL_BINDIR=bin', + '-DCMAKE_INSTALL_LIBDIR=lib', + '-DCMAKE_INSTALL_INCLUDE_DIR=include', + "-DCMAKE_TOOLCHAIN_FILE={$this->makeCmakeToolchainFile()}", + '..', + ]); + } + + /** + * Initialize the CMake build directory. + * If the directory is not set, it defaults to the library's source directory with '/build' appended. + * + * @throws FileSystemException + */ + private function initCMakeBuildDir(): void + { + if ($this->cmake_build_dir === null) { + $this->cmake_build_dir = "{$this->library->getSourceDir()}/build"; + } + FileSystem::resetDir($this->cmake_build_dir); + } + + /** + * @return string CMake toolchain file path + * @throws FileSystemException + * @throws WrongUsageException + */ + private function makeCmakeToolchainFile(): string + { + static $created; + if (isset($created)) { + return $created; + } + $os = PHP_OS_FAMILY; + $target_arch = arch2gnu(php_uname('m')); + $cflags = getenv('SPC_DEFAULT_C_FLAGS'); + $cc = getenv('CC'); + $cxx = getenv('CCX'); + 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 = << Date: Mon, 9 Jun 2025 00:34:25 +0800 Subject: [PATCH 02/14] Add cmake tool functions --- .../builder/unix/executor/UnixCMakeExecutor.php | 15 ++++++++++----- src/globals/functions.php | 6 ++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php index b74d8fc8..421bd4bb 100644 --- a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php +++ b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php @@ -48,14 +48,19 @@ class UnixCMakeExecutor extends Executor * Add optional library configuration. * This method checks if a library is available and adds the corresponding arguments to the CMake configuration. * - * @param string $name library name to check - * @param string $true_args arguments to use if the library is available - * @param string $false_args arguments to use if the library is not available + * @param string $name library name to check + * @param \Closure|string $true_args arguments to use if the library is available (allow closure, returns string) + * @param string $false_args arguments to use if the library is not available * @return $this */ - public function optionalLib(string $name, string $true_args, string $false_args = ''): static + public function optionalLib(string $name, \Closure|string $true_args, string $false_args = ''): static { - $this->addConfigureArgs($this->library->getBuilder()->getLib($name) ? $true_args : $false_args); + if ($get = $this->library->getBuilder()->getLib($name)) { + $args = $true_args instanceof \Closure ? $true_args($get) : $true_args; + } else { + $args = $false_args; + } + $this->addConfigureArgs($args); return $this; } diff --git a/src/globals/functions.php b/src/globals/functions.php index 1b5474cb..ea96df58 100644 --- a/src/globals/functions.php +++ b/src/globals/functions.php @@ -210,3 +210,9 @@ function get_cmake_version(): ?string } return null; } + +function cmake_boolean_args(string $arg_name, bool $negative = false): array +{ + $res = ["-D{$arg_name}=ON", "-D{$arg_name}=OFF"]; + return $negative ? array_reverse($res) : $res; +} From 171880604227191810bb545ee68c18c663758ec8 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 01:07:30 +0800 Subject: [PATCH 03/14] Use cmake executor instead of raw command --- src/SPC/builder/unix/executor/Executor.php | 2 - .../unix/executor/UnixCMakeExecutor.php | 16 +++- src/SPC/builder/unix/library/brotli.php | 20 ++--- src/SPC/builder/unix/library/curl.php | 90 ++++--------------- src/SPC/builder/unix/library/freetype.php | 27 +++--- src/SPC/builder/unix/library/gmssl.php | 17 +--- src/SPC/builder/unix/library/libaom.php | 21 ++--- src/SPC/builder/unix/library/libavif.php | 13 +-- src/SPC/builder/unix/library/libde265.php | 20 +---- src/SPC/builder/unix/library/libevent.php | 30 +++---- src/SPC/builder/unix/library/libheif.php | 30 +++---- src/SPC/builder/unix/library/libjpeg.php | 18 ++-- src/SPC/builder/unix/library/librabbitmq.php | 18 +--- src/SPC/builder/unix/library/libssh2.php | 26 ++---- src/SPC/builder/unix/library/libuuid.php | 12 +-- src/SPC/builder/unix/library/libuv.php | 12 +-- src/SPC/builder/unix/library/libwebp.php | 18 +--- src/SPC/builder/unix/library/libyaml.php | 26 +----- src/SPC/builder/unix/library/libzip.php | 44 ++++----- src/SPC/builder/unix/library/mimalloc.php | 31 ++----- src/SPC/builder/unix/library/snappy.php | 19 ++-- src/SPC/builder/unix/library/tidy.php | 17 ++-- src/SPC/builder/unix/library/zstd.php | 18 ++-- 23 files changed, 151 insertions(+), 394 deletions(-) diff --git a/src/SPC/builder/unix/executor/Executor.php b/src/SPC/builder/unix/executor/Executor.php index 0d50d49a..9667de9c 100644 --- a/src/SPC/builder/unix/executor/Executor.php +++ b/src/SPC/builder/unix/executor/Executor.php @@ -17,6 +17,4 @@ abstract class Executor { return new static($library); } - - abstract public function build(): void; } diff --git a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php index 421bd4bb..727607ab 100644 --- a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php +++ b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php @@ -18,7 +18,9 @@ class UnixCMakeExecutor extends Executor protected ?array $custom_default_args = null; - public function build(): void + protected int $steps = 3; + + public function build(string $build_pos = '..'): void { // set cmake dir $this->initCMakeBuildDir(); @@ -35,13 +37,13 @@ class UnixCMakeExecutor extends Executor $shell = shell()->cd($this->cmake_build_dir)->setEnv($env); // config - $shell->execWithEnv("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()}"); + $this->steps >= 1 && $shell->execWithEnv("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()} {$build_pos}"); // make - $shell->execWithEnv("cmake --build . -j {$this->library->getBuilder()->concurrency}"); + $this->steps >= 2 && $shell->execWithEnv("cmake --build . -j {$this->library->getBuilder()->concurrency}"); // install - $shell->execWithEnv('make install'); + $this->steps >= 3 && $shell->execWithEnv('make install'); } /** @@ -73,6 +75,11 @@ class UnixCMakeExecutor extends Executor return $this; } + public function toStep(int $step): static + { + $this->steps = $step; + } + /** * Set custom CMake build directory. * @@ -113,6 +120,7 @@ class UnixCMakeExecutor extends Executor '-DCMAKE_INSTALL_BINDIR=bin', '-DCMAKE_INSTALL_LIBDIR=lib', '-DCMAKE_INSTALL_INCLUDE_DIR=include', + '-DBUILD_SHARED_LIBS=OFF', "-DCMAKE_TOOLCHAIN_FILE={$this->makeCmakeToolchainFile()}", '..', ]); diff --git a/src/SPC/builder/unix/library/brotli.php b/src/SPC/builder/unix/library/brotli.php index 9e764fcb..a12810d7 100644 --- a/src/SPC/builder/unix/library/brotli.php +++ b/src/SPC/builder/unix/library/brotli.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\store\FileSystem; @@ -16,21 +17,10 @@ trait brotli */ protected function build(): void { - FileSystem::resetDir($this->source_dir . '/build-dir'); - shell()->cd($this->source_dir . '/build-dir') - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( - 'cmake ' . - '-DCMAKE_BUILD_TYPE=Release ' . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . - '-DCMAKE_INSTALL_LIBDIR=lib ' . - '-DSHARE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '..' - ) - ->execWithEnv("cmake --build . -j {$this->builder->concurrency}") - ->execWithEnv('make install'); + UnixCMakeExecutor::create($this) + ->setCMakeBuildDir("{$this->getSourceDir()}/build-dir") + ->build(); + $this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']); shell()->cd(BUILD_ROOT_PATH . '/lib')->exec('ln -sf libbrotlicommon.a libbrotli.a'); foreach (FileSystem::scanDirFiles(BUILD_ROOT_PATH . '/lib/', false, true) as $filename) { diff --git a/src/SPC/builder/unix/library/curl.php b/src/SPC/builder/unix/library/curl.php index 23b1c80a..95afe34e 100644 --- a/src/SPC/builder/unix/library/curl.php +++ b/src/SPC/builder/unix/library/curl.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; -use SPC\store\FileSystem; trait curl { @@ -16,79 +16,25 @@ trait curl */ protected function build(): void { - $extra = ''; - // lib:openssl - if ($this->builder->getLib('openssl')) { - $extra .= - '-DCURL_USE_OPENSSL=ON ' . - '-DCURL_CA_BUNDLE=OFF ' . - '-DCURL_CA_PATH=OFF ' . - '-DCURL_CA_FALLBACK=ON '; - } else { - $extra .= '-DCURL_USE_OPENSSL=OFF -DCURL_ENABLE_SSL=OFF '; - } - // lib:brotli - $extra .= $this->builder->getLib('brotli') ? '-DCURL_BROTLI=ON ' : '-DCURL_BROTLI=OFF '; - // lib:libssh2 - $libssh2 = $this->builder->getLib('libssh2'); - if ($this->builder->getLib('libssh2')) { - /* @phpstan-ignore-next-line */ - $extra .= '-DLIBSSH2_LIBRARY="' . $libssh2->getStaticLibFiles(style: 'cmake') . '" ' . - '-DLIBSSH2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DCURL_USE_LIBSSH2=OFF '; - } - // lib:nghttp2 - if ($nghttp2 = $this->builder->getLib('nghttp2')) { - $extra .= '-DUSE_NGHTTP2=ON ' . - /* @phpstan-ignore-next-line */ - '-DNGHTTP2_LIBRARY="' . $nghttp2->getStaticLibFiles(style: 'cmake') . '" ' . - '-DNGHTTP2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DUSE_NGHTTP2=OFF '; - } - // lib:nghttp3 - if ($nghttp3 = $this->builder->getLib('nghttp3')) { - $extra .= '-DUSE_NGHTTP3=ON ' . - /* @phpstan-ignore-next-line */ - '-DNGHTTP3_LIBRARY="' . $nghttp3->getStaticLibFiles(style: 'cmake') . '" ' . - '-DNGHTTP3_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DUSE_NGHTTP3=OFF '; - } - // lib:ngtcp2 - if ($ngtcp2 = $this->builder->getLib('ngtcp2')) { - $extra .= '-DUSE_NGTCP2=ON ' . - /* @phpstan-ignore-next-line */ - '-DNGTCP2_LIBRARY="' . $ngtcp2->getStaticLibFiles(style: 'cmake') . '" ' . - '-DNGTCP2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DUSE_NGTCP2=OFF '; - } - // lib:ldap - $extra .= $this->builder->getLib('ldap') ? '-DCURL_DISABLE_LDAP=OFF ' : '-DCURL_DISABLE_LDAP=ON '; - // lib:zstd - $extra .= $this->builder->getLib('zstd') ? '-DCURL_ZSTD=ON ' : '-DCURL_ZSTD=OFF '; - // lib:idn2 - $extra .= $this->builder->getLib('idn2') ? '-DUSE_LIBIDN2=ON ' : '-DUSE_LIBIDN2=OFF '; - // lib:psl - $extra .= $this->builder->getLib('psl') ? '-DCURL_USE_LIBPSL=ON ' : '-DCURL_USE_LIBPSL=OFF '; - // lib:libcares - $extra .= $this->builder->getLib('libcares') ? '-DENABLE_ARES=ON ' : ''; + shell()->cd($this->source_dir)->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ./CMakeLists.txt'); - FileSystem::resetDir($this->source_dir . '/build'); + UnixCMakeExecutor::create($this) + ->optionalLib('openssl', '-DCURL_USE_OPENSSL=ON -DCURL_CA_BUNDLE=OFF -DCURL_CA_PATH=OFF -DCURL_FALLBACK=ON', '-DCURL_USE_OPENSSL=OFF -DCURL_ENABLE_SSL=OFF') + ->optionalLib('brotli', ...cmake_boolean_args('CURL_BROTLI')) + ->optionalLib('libssh2', fn ($lib) => "-DLIBSSH2_LIBRARY=\"{$lib->getStaticLibFiles(style: 'cmake')}\" -DLIBSSH2_INCLUDE_DIR={$lib->getIncludeDir()}", '-DCURL_USE_LIBSSH2=OFF') + ->optionalLib('nghttp2', fn ($lib) => "-DUSE_NGHTTP2=ON -DNGHTTP2_LIBRARY=\"{$lib->getStaticLibFiles(style: 'cmake')}\" -DNGHTTP2_INCLUDE_DIR={$lib->getIncludeDir()}", '-DUSE_NGHTTP2=OFF') + ->optionalLib('nghttp3', fn ($lib) => "-DUSE_NGHTTP3=ON -DNGHTTP3_LIBRARY=\"{$lib->getStaticLibFiles(style: 'cmake')}\" -DNGHTTP3_INCLUDE_DIR={$lib->getIncludeDir()}", '-DUSE_NGHTTP3=OFF') + ->optionalLib('ldap', ...cmake_boolean_args('CURL_DISABLE_LDAP', true)) + ->optionalLib('zstd', ...cmake_boolean_args('CURL_ZSTD')) + ->optionalLib('idn2', ...cmake_boolean_args('USE_LIBIDN2')) + ->optionalLib('psl', ...cmake_boolean_args('CURL_USE_LIBPSL')) + ->optionalLib('libcares', '-DENABLE_ARES=ON') + ->addConfigureArgs( + '-DBUILD_CURL_EXE=OFF', + '-DBUILD_LIBCURL_DOCS=OFF', + ) + ->build(); - // compile! - shell()->cd($this->source_dir . '/build') - ->setEnv([ - 'CFLAGS' => $this->getLibExtraCFlags(), - 'LDFLAGS' => $this->getLibExtraLdFlags(), - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ../CMakeLists.txt') - ->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF {$extra} ..") - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install'); // patch pkgconf $this->patchPkgconfPrefix(['libcurl.pc']); shell()->cd(BUILD_LIB_PATH . '/cmake/CURL/') diff --git a/src/SPC/builder/unix/library/freetype.php b/src/SPC/builder/unix/library/freetype.php index 94998b7c..fd551593 100644 --- a/src/SPC/builder/unix/library/freetype.php +++ b/src/SPC/builder/unix/library/freetype.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; @@ -18,24 +19,18 @@ trait freetype */ protected function build(): void { - $extra = ''; + $cmake = UnixCMakeExecutor::create($this) + ->optionalLib('libpng', ...cmake_boolean_args('FT_DISABLE_PNG', true)) + ->optionalLib('bzip2', ...cmake_boolean_args('FT_DISABLE_BZIP2', true)) + ->optionalLib('brotli', ...cmake_boolean_args('FT_DISABLE_BROTLI', true)) + ->addConfigureArgs('-DFT_DISABLE_HARFBUZZ=ON'); + + // fix cmake 4.0 compatibility if (version_compare(get_cmake_version(), '4.0.0', '>=')) { - $extra .= '-DCMAKE_POLICY_VERSION_MINIMUM=3.12 '; + $cmake->addConfigureArgs('-DCMAKE_POLICY_VERSION_MINIMUM=3.12'); } - $extra .= $this->builder->getLib('libpng') ? '-DFT_DISABLE_PNG=OFF ' : '-DFT_DISABLE_PNG=ON '; - $extra .= $this->builder->getLib('bzip2') ? '-DFT_DISABLE_BZIP2=OFF ' : '-DFT_DISABLE_BZIP2=ON '; - $extra .= $this->builder->getLib('brotli') ? '-DFT_DISABLE_BROTLI=OFF ' : '-DFT_DISABLE_BROTLI=ON '; - FileSystem::resetDir($this->source_dir . '/build'); - shell()->cd($this->source_dir . '/build') - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( - "cmake {$this->builder->makeCmakeArgs()} -DFT_DISABLE_HARFBUZZ=ON " . - '-DBUILD_SHARED_LIBS=OFF ' . - "{$extra}.." - ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install'); + + $cmake->build(); $this->patchPkgconfPrefix(['freetype2.pc']); FileSystem::replaceFileStr( diff --git a/src/SPC/builder/unix/library/gmssl.php b/src/SPC/builder/unix/library/gmssl.php index 1d946621..7c007f52 100644 --- a/src/SPC/builder/unix/library/gmssl.php +++ b/src/SPC/builder/unix/library/gmssl.php @@ -4,25 +4,12 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\exception\FileSystemException; -use SPC\exception\RuntimeException; -use SPC\store\FileSystem; +use SPC\builder\unix\executor\UnixCMakeExecutor; trait gmssl { - /** - * @throws FileSystemException - * @throws RuntimeException - */ protected function build(): void { - // CMake needs a clean build directory - FileSystem::resetDir($this->source_dir . '/build'); - // Start build - shell()->cd($this->source_dir . '/build') - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF ..") - ->execWithEnv("cmake --build . -j {$this->builder->concurrency}") - ->execWithEnv('make install'); + UnixCMakeExecutor::create($this)->build(); } } diff --git a/src/SPC/builder/unix/library/libaom.php b/src/SPC/builder/unix/library/libaom.php index 5ecf6704..e4a28903 100644 --- a/src/SPC/builder/unix/library/libaom.php +++ b/src/SPC/builder/unix/library/libaom.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; -use SPC\store\FileSystem; trait libaom { @@ -16,21 +16,10 @@ trait libaom */ protected function build(): void { - // CMake needs a clean build directory - FileSystem::resetDir($this->source_dir . '/builddir'); - // Start build - shell()->cd($this->source_dir . '/builddir') - ->exec( - 'cmake ' . - '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DAOM_TARGET_CPU=generic ' . - '..' - ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + UnixCMakeExecutor::create($this) + ->setCMakeBuildDir("{$this->source_dir}/builddir") + ->addConfigureArgs('-DAOM_TARGET_GPU=generic') + ->build(); $this->patchPkgconfPrefix(['aom.pc']); } } diff --git a/src/SPC/builder/unix/library/libavif.php b/src/SPC/builder/unix/library/libavif.php index c2aaafcd..dd9efb33 100644 --- a/src/SPC/builder/unix/library/libavif.php +++ b/src/SPC/builder/unix/library/libavif.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; -use SPC\store\FileSystem; trait libavif { @@ -18,14 +18,9 @@ trait libavif */ protected function build(): void { - // CMake needs a clean build directory - FileSystem::resetDir($this->source_dir . '/build'); - // Start build - shell()->cd($this->source_dir . '/build') - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DAVIF_LIBYUV=OFF ..") - ->execWithEnv("cmake --build . -j {$this->builder->concurrency}") - ->execWithEnv('make install'); + UnixCMakeExecutor::create($this) + ->addConfigureArgs('-DAVIF_LIBYUV=OFF') + ->build(); // patch pkgconfig $this->patchPkgconfPrefix(['libavif.pc']); $this->cleanLaFiles(); diff --git a/src/SPC/builder/unix/library/libde265.php b/src/SPC/builder/unix/library/libde265.php index df02bbb3..e6e57c44 100644 --- a/src/SPC/builder/unix/library/libde265.php +++ b/src/SPC/builder/unix/library/libde265.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; -use SPC\store\FileSystem; trait libde265 { @@ -16,21 +16,9 @@ trait libde265 */ protected function build(): void { - // CMake needs a clean build directory - FileSystem::resetDir($this->source_dir . '/build'); - // Start build - shell()->cd($this->source_dir . '/build') - ->exec( - 'cmake ' . - '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DENABLE_SDL=OFF ' . // Disable SDL, currently not supported - '..' - ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + UnixCMakeExecutor::create($this) + ->addConfigureArgs('-DENABLE_SDL=OFF') + ->build(); $this->patchPkgconfPrefix(['libde265.pc']); } } diff --git a/src/SPC/builder/unix/library/libevent.php b/src/SPC/builder/unix/library/libevent.php index 2e80f32e..ee9357ac 100644 --- a/src/SPC/builder/unix/library/libevent.php +++ b/src/SPC/builder/unix/library/libevent.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\store\FileSystem; @@ -39,27 +40,16 @@ trait libevent */ protected function build(): void { - [$lib, $include, $destdir] = SEPARATED_PATH; - // CMake needs a clean build directory - FileSystem::resetDir($this->source_dir . '/build'); - // Start build - shell()->cd($this->source_dir . '/build') - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( - 'cmake ' . - '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DEVENT__LIBRARY_TYPE=STATIC ' . - '-DEVENT__DISABLE_BENCHMARK=ON ' . - '-DEVENT__DISABLE_THREAD_SUPPORT=ON ' . - '-DEVENT__DISABLE_MBEDTLS=ON ' . - '-DEVENT__DISABLE_TESTS=ON ' . - '-DEVENT__DISABLE_SAMPLES=ON ' . - '..' + UnixCMakeExecutor::create($this) + ->addConfigureArgs( + '-DEVENT__LIBRARY_TYPE=STATIC', + '-DEVENT__DISABLE_BENCHMARK=ON', + '-DEVENT__DISABLE_THREAD_SUPPORT=ON', + '-DEVENT__DISABLE_MBEDTLS=ON', + '-DEVENT__DISABLE_TESTS=ON', + '-DEVENT__DISABLE_SAMPLES=ON', ) - ->execWithEnv("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + ->build(); $this->patchPkgconfPrefix(['libevent.pc', 'libevent_core.pc', 'libevent_extra.pc', 'libevent_openssl.pc']); diff --git a/src/SPC/builder/unix/library/libheif.php b/src/SPC/builder/unix/library/libheif.php index e2d2a486..0a171431 100644 --- a/src/SPC/builder/unix/library/libheif.php +++ b/src/SPC/builder/unix/library/libheif.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; -use SPC\store\FileSystem; trait libheif { @@ -16,26 +16,16 @@ trait libheif */ protected function build(): void { - // CMake needs a clean build directory - FileSystem::resetDir($this->source_dir . '/build'); - // Start build - shell()->cd($this->source_dir . '/build') - ->exec( - 'cmake ' . - '--preset=release ' . - '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DWITH_EXAMPLES=OFF ' . - '-DWITH_GDK_PIXBUF=OFF ' . - '-DBUILD_TESTING=OFF ' . - '-DWITH_LIBSHARPYUV=ON ' . // optional: libwebp - '-DENABLE_PLUGIN_LOADING=OFF ' . - '..' + UnixCMakeExecutor::create($this) + ->addConfigureArgs( + '--preset=release', + '-DWITH_EXAMPLES=OFF', + '-DWITH_GDK_PIXBUF=OFF', + '-DBUILD_TESTING=OFF', + '-DWITH_LIBSHARPYUV=ON', // optional: libwebp + '-DENABLE_PLUGIN_LOADING=OFF', ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + ->build(); $this->patchPkgconfPrefix(['libheif.pc']); } } diff --git a/src/SPC/builder/unix/library/libjpeg.php b/src/SPC/builder/unix/library/libjpeg.php index c4f9833d..1be81cf3 100644 --- a/src/SPC/builder/unix/library/libjpeg.php +++ b/src/SPC/builder/unix/library/libjpeg.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; -use SPC\store\FileSystem; trait libjpeg { @@ -18,18 +18,12 @@ trait libjpeg */ protected function build(): void { - // CMake needs a clean build directory - FileSystem::resetDir($this->source_dir . '/build'); - // Start build - shell()->cd($this->source_dir . '/build') - ->exec( - "cmake {$this->builder->makeCmakeArgs()} " . - '-DENABLE_STATIC=ON ' . - '-DENABLE_SHARED=OFF ' . - '..' + UnixCMakeExecutor::create($this) + ->addConfigureArgs( + '-DENABLE_STATIC=ON', + '-DENABLE_SHARED=OFF', ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + ->build(); // patch pkgconfig $this->patchPkgconfPrefix(['libjpeg.pc', 'libturbojpeg.pc']); $this->cleanLaFiles(); diff --git a/src/SPC/builder/unix/library/librabbitmq.php b/src/SPC/builder/unix/library/librabbitmq.php index 42ef553b..dbf2e8ad 100644 --- a/src/SPC/builder/unix/library/librabbitmq.php +++ b/src/SPC/builder/unix/library/librabbitmq.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; -use SPC\store\FileSystem; trait librabbitmq { @@ -16,20 +16,6 @@ trait librabbitmq */ protected function build(): void { - // CMake needs a clean build directory - FileSystem::resetDir($this->source_dir . '/build'); - // Start build - shell()->cd($this->source_dir . '/build') - ->exec( - 'cmake ' . - '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DBUILD_STATIC_LIBS=ON ' . - '..' - ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + UnixCMakeExecutor::create($this)->addConfigureArgs('-DBUILD_STATIC_LIBS=ON')->build(); } } diff --git a/src/SPC/builder/unix/library/libssh2.php b/src/SPC/builder/unix/library/libssh2.php index 9e999ca9..9aee6116 100644 --- a/src/SPC/builder/unix/library/libssh2.php +++ b/src/SPC/builder/unix/library/libssh2.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; -use SPC\store\FileSystem; trait libssh2 { @@ -16,24 +16,14 @@ trait libssh2 */ protected function build(): void { - $enable_zlib = $this->builder->getLib('zlib') !== null ? 'ON' : 'OFF'; - - FileSystem::resetDir($this->source_dir . '/build'); - shell()->cd($this->source_dir . '/build') - ->exec( - 'cmake ' . - '-DCMAKE_BUILD_TYPE=Release ' . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . - '-DCMAKE_INSTALL_LIBDIR=lib ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DBUILD_EXAMPLES=OFF ' . - '-DBUILD_TESTING=OFF ' . - "-DENABLE_ZLIB_COMPRESSION={$enable_zlib} " . - '..' + UnixCMakeExecutor::create($this) + ->optionalLib('zlib', ...cmake_boolean_args('ENABLE_ZLIB_COMPRESSION')) + ->addConfigureArgs( + '-DBUILD_EXAMPLES=OFF', + '-DBUILD_TESTING=OFF' ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + ->build(); + $this->patchPkgconfPrefix(['libssh2.pc']); } } diff --git a/src/SPC/builder/unix/library/libuuid.php b/src/SPC/builder/unix/library/libuuid.php index 65ed02ac..becb5e41 100644 --- a/src/SPC/builder/unix/library/libuuid.php +++ b/src/SPC/builder/unix/library/libuuid.php @@ -4,26 +4,18 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; -use SPC\exception\RuntimeException; use SPC\store\FileSystem; trait libuuid { /** * @throws FileSystemException - * @throws RuntimeException */ protected function build(): void { - FileSystem::resetDir($this->source_dir . '/build'); - shell()->cd($this->source_dir . '/build') - ->exec( - 'cmake ' . - "{$this->builder->makeCmakeArgs()} " . - '..' - ) - ->exec("cmake --build . -j {$this->builder->concurrency}"); + UnixCMakeExecutor::create($this)->toStep(2)->build(); copy($this->source_dir . '/build/libuuid.a', BUILD_LIB_PATH . '/libuuid.a'); FileSystem::createDir(BUILD_INCLUDE_PATH . '/uuid'); copy($this->source_dir . '/uuid.h', BUILD_INCLUDE_PATH . '/uuid/uuid.h'); diff --git a/src/SPC/builder/unix/library/libuv.php b/src/SPC/builder/unix/library/libuv.php index fda11c0a..1110d34d 100644 --- a/src/SPC/builder/unix/library/libuv.php +++ b/src/SPC/builder/unix/library/libuv.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; -use SPC\store\FileSystem; trait libuv { @@ -16,13 +16,9 @@ trait libuv */ protected function build(): void { - // CMake needs a clean build directory - FileSystem::resetDir($this->source_dir . '/build'); - // Start build - shell()->cd($this->source_dir . '/build') - ->exec("cmake {$this->builder->makeCmakeArgs()} -DLIBUV_BUILD_SHARED=OFF ..") - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + UnixCMakeExecutor::create($this) + ->addConfigureArgs('-DLIBUV_BUILD_SHARED=OFF') + ->build(); // patch pkgconfig $this->patchPkgconfPrefix(['libuv-static.pc']); } diff --git a/src/SPC/builder/unix/library/libwebp.php b/src/SPC/builder/unix/library/libwebp.php index efb78a68..b735fa8e 100644 --- a/src/SPC/builder/unix/library/libwebp.php +++ b/src/SPC/builder/unix/library/libwebp.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; -use SPC\store\FileSystem; trait libwebp { @@ -18,19 +18,9 @@ trait libwebp */ protected function build(): void { - // CMake needs a clean build directory - FileSystem::resetDir($this->source_dir . '/build'); - // Start build - shell()->cd($this->source_dir . '/build') - ->exec( - 'cmake ' . - $this->builder->makeCmakeArgs() . ' ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DWEBP_BUILD_EXTRAS=ON ' . - '..' - ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + UnixCMakeExecutor::create($this) + ->addConfigureArgs('-DWEBP_BUILD_EXTRAS=ON') + ->build(); // patch pkgconfig $this->patchPkgconfPrefix(['libsharpyuv.pc', 'libwebp.pc', 'libwebpdecoder.pc', 'libwebpdemux.pc', 'libwebpmux.pc'], PKGCONF_PATCH_PREFIX | PKGCONF_PATCH_LIBDIR); $this->patchPkgconfPrefix(['libsharpyuv.pc'], PKGCONF_PATCH_CUSTOM, ['/^includedir=.*$/m', 'includedir=${prefix}/include/webp']); diff --git a/src/SPC/builder/unix/library/libyaml.php b/src/SPC/builder/unix/library/libyaml.php index 53962e9b..799b141a 100644 --- a/src/SPC/builder/unix/library/libyaml.php +++ b/src/SPC/builder/unix/library/libyaml.php @@ -4,8 +4,7 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\exception\FileSystemException; -use SPC\exception\RuntimeException; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\store\FileSystem; trait libyaml @@ -25,29 +24,8 @@ trait libyaml return null; } - /** - * @throws RuntimeException - * @throws FileSystemException - */ protected function build(): void { - [$lib, $include, $destdir] = SEPARATED_PATH; - - FileSystem::resetDir($this->source_dir . '/build'); - shell()->cd($this->source_dir . '/build') - ->exec( - 'cmake ' . - // '--debug-find ' . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_TESTING=OFF ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DCMAKE_INSTALL_PREFIX=/ ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '..' - ) - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); + UnixCMakeExecutor::create($this)->addConfigureArgs('-DBUILD_TESTING=OFF')->build(); } } diff --git a/src/SPC/builder/unix/library/libzip.php b/src/SPC/builder/unix/library/libzip.php index 5e2bd0d6..406be44f 100644 --- a/src/SPC/builder/unix/library/libzip.php +++ b/src/SPC/builder/unix/library/libzip.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; -use SPC\store\FileSystem; trait libzip { @@ -16,35 +16,21 @@ trait libzip */ protected function build(): void { - $extra = ''; - // lib:bzip2 - $extra .= $this->builder->getLib('bzip2') ? '-DENABLE_BZIP2=ON ' : '-DENABLE_BZIP2=OFF '; - // lib:xz - $extra .= $this->builder->getLib('xz') ? '-DENABLE_LZMA=ON ' : '-DENABLE_LZMA=OFF '; - // lib:zstd (disabled due to imagemagick link issue - $extra .= /* $this->builder->getLib('zstd') ? '-DENABLE_ZSTD=ON ' : */ '-DENABLE_ZSTD=OFF '; - // lib:openssl - $extra .= $this->builder->getLib('openssl') ? '-DENABLE_OPENSSL=ON ' : '-DENABLE_OPENSSL=OFF '; - - FileSystem::resetDir($this->source_dir . '/build'); - shell()->cd($this->source_dir . '/build') - ->exec( - 'cmake ' . - '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DENABLE_GNUTLS=OFF ' . - '-DENABLE_MBEDTLS=OFF ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DBUILD_DOC=OFF ' . - '-DBUILD_EXAMPLES=OFF ' . - '-DBUILD_REGRESS=OFF ' . - '-DBUILD_TOOLS=OFF ' . - $extra . - '..' + UnixCMakeExecutor::create($this) + ->optionalLib('bzip2', ...cmake_boolean_args('ENABLE_BZIP2')) + ->optionalLib('xz', ...cmake_boolean_args('ENABLE_LZMA')) + ->optionalLib('openssl', ...cmake_boolean_args('ENABLE_OPENSSL')) + ->addConfigureArgs( + '-DENABLE_GNUTLS=OFF', + '-DENABLE_MBEDTLS=OFF', + '-DBUILD_SHARED_LIBS=OFF', + '-DBUILD_DOC=OFF', + '-DBUILD_EXAMPLES=OFF', + '-DBUILD_REGRESS=OFF', + '-DBUILD_TOOLS=OFF', + '-DENABLE_ZSTD=OFF', ) - ->exec("make -j{$this->builder->concurrency}") - ->exec('make install'); + ->build(); $this->patchPkgconfPrefix(['libzip.pc'], PKGCONF_PATCH_PREFIX); } } diff --git a/src/SPC/builder/unix/library/mimalloc.php b/src/SPC/builder/unix/library/mimalloc.php index 40790a98..7655e321 100644 --- a/src/SPC/builder/unix/library/mimalloc.php +++ b/src/SPC/builder/unix/library/mimalloc.php @@ -4,35 +4,20 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\exception\FileSystemException; -use SPC\exception\RuntimeException; -use SPC\store\FileSystem; +use SPC\builder\unix\executor\UnixCMakeExecutor; trait mimalloc { - /** - * @throws RuntimeException - * @throws FileSystemException - */ protected function build(): void { - $args = ''; + $cmake = UnixCMakeExecutor::create($this) + ->addConfigureArgs( + '-DMI_BUILD_SHARED=OFF', + '-DMI_INSTALL_TOPLEVEL=ON' + ); if (getenv('SPC_LIBC') === 'musl') { - $args .= '-DMI_LIBC_MUSL=ON '; + $cmake->addConfigureArgs('-DMI_LIBC_MUSL=ON'); } - $args .= '-DMI_BUILD_SHARED=OFF '; - $args .= '-DMI_INSTALL_TOPLEVEL=ON '; - FileSystem::resetDir($this->source_dir . '/build'); - shell()->cd($this->source_dir . '/build') - ->execWithEnv( - 'cmake ' . - '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '-DCMAKE_BUILD_TYPE=Release ' . - $args . - '..' - ) - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install'); + $cmake->build(); } } diff --git a/src/SPC/builder/unix/library/snappy.php b/src/SPC/builder/unix/library/snappy.php index f1b4c825..94d93372 100644 --- a/src/SPC/builder/unix/library/snappy.php +++ b/src/SPC/builder/unix/library/snappy.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; -use SPC\store\FileSystem; trait snappy { @@ -16,17 +16,12 @@ trait snappy */ protected function build(): void { - FileSystem::resetDir($this->source_dir . '/cmake/build'); - - shell()->cd($this->source_dir . '/cmake/build') - ->exec( - 'cmake ' . - "{$this->builder->makeCmakeArgs()} " . - '-DSNAPPY_BUILD_TESTS=OFF ' . - '-DSNAPPY_BUILD_BENCHMARKS=OFF ' . - '../..' + UnixCMakeExecutor::create($this) + ->setCMakeBuildDir("{$this->source_dir}/cmake/build") + ->addConfigureArgs( + '-DSNAPPY_BUILD_TESTS=OFF', + '-DSNAPPY_BUILD_BENCHMARKS=OFF', ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + ->build('../..'); } } diff --git a/src/SPC/builder/unix/library/tidy.php b/src/SPC/builder/unix/library/tidy.php index 31c851d1..ed143548 100644 --- a/src/SPC/builder/unix/library/tidy.php +++ b/src/SPC/builder/unix/library/tidy.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; -use SPC\store\FileSystem; trait tidy { @@ -16,17 +16,10 @@ trait tidy */ protected function build(): void { - FileSystem::resetDir($this->source_dir . '/build-dir'); - shell()->cd($this->source_dir . '/build-dir') - ->exec( - 'cmake ' . - "{$this->builder->makeCmakeArgs()} " . - '-DBUILD_SHARED_LIB=OFF ' . - '-DSUPPORT_CONSOLE_APP=OFF ' . - '..' - ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + UnixCMakeExecutor::create($this) + ->setCMakeBuildDir("{$this->source_dir}/build-dir") + ->addConfigureArgs('-DSUPPORT_CONSOLE_APP=OFF') + ->build(); $this->patchPkgconfPrefix(['tidy.pc']); } } diff --git a/src/SPC/builder/unix/library/zstd.php b/src/SPC/builder/unix/library/zstd.php index 1990f658..d081baae 100644 --- a/src/SPC/builder/unix/library/zstd.php +++ b/src/SPC/builder/unix/library/zstd.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; -use SPC\store\FileSystem; trait zstd { @@ -16,17 +16,13 @@ trait zstd */ protected function build(): void { - FileSystem::resetDir($this->source_dir . '/build/cmake/build'); - shell()->cd($this->source_dir . '/build/cmake/build') - ->exec( - 'cmake ' . - "{$this->builder->makeCmakeArgs()} " . - '-DZSTD_BUILD_STATIC=ON ' . - '-DZSTD_BUILD_SHARED=OFF ' . - '..' + UnixCMakeExecutor::create($this) + ->setCMakeBuildDir("{$this->source_dir}/build/cmake/build") + ->addConfigureArgs( + '-DZSTD_BUILD_STATIC=ON', + '-DZSTD_BUILD_SHARED=OFF', ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); + ->build(); $this->patchPkgconfPrefix(['libzstd.pc']); } } From 1cf2a3dd3fc5ba29d0bc89009fb9b0f901568314 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 01:08:24 +0800 Subject: [PATCH 04/14] Fix UnixCMakeExecutor.php missing return --- src/SPC/builder/unix/executor/UnixCMakeExecutor.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php index 727607ab..5def0057 100644 --- a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php +++ b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php @@ -78,6 +78,7 @@ class UnixCMakeExecutor extends Executor public function toStep(int $step): static { $this->steps = $step; + return $this; } /** From 37b9ccfaa8b0cdc7019c7681c690f43df58439d6 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 01:15:48 +0800 Subject: [PATCH 05/14] Fix UnixCMakeExecutor.php --- src/SPC/builder/unix/executor/UnixCMakeExecutor.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php index 5def0057..068dd965 100644 --- a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php +++ b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php @@ -71,7 +71,7 @@ class UnixCMakeExecutor extends Executor */ public function addConfigureArgs(...$args): static { - $this->configure_args = [$this->configure_args, ...$args]; + $this->configure_args = [...$this->configure_args, ...$args]; return $this; } @@ -123,7 +123,6 @@ class UnixCMakeExecutor extends Executor '-DCMAKE_INSTALL_INCLUDE_DIR=include', '-DBUILD_SHARED_LIBS=OFF', "-DCMAKE_TOOLCHAIN_FILE={$this->makeCmakeToolchainFile()}", - '..', ]); } From 42943b315c8a3361a552d53c248afaab3377c5a4 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 01:33:06 +0800 Subject: [PATCH 06/14] Refactor remaining cmake libs --- src/SPC/builder/linux/library/libxml2.php | 45 +---------------------- src/SPC/builder/macos/library/glfw.php | 14 ++++--- src/SPC/builder/macos/library/libxml2.php | 39 +------------------- src/SPC/builder/unix/library/libxml2.php | 42 +++++++++++++++++++++ 4 files changed, 55 insertions(+), 85 deletions(-) create mode 100644 src/SPC/builder/unix/library/libxml2.php diff --git a/src/SPC/builder/linux/library/libxml2.php b/src/SPC/builder/linux/library/libxml2.php index 6f42d672..102f60b7 100644 --- a/src/SPC/builder/linux/library/libxml2.php +++ b/src/SPC/builder/linux/library/libxml2.php @@ -4,50 +4,9 @@ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\FileSystemException; -use SPC\exception\RuntimeException; -use SPC\store\FileSystem; - class libxml2 extends LinuxLibraryBase { + use \SPC\builder\unix\library\libxml2; + public const NAME = 'libxml2'; - - /** - * @throws RuntimeException - * @throws FileSystemException - */ - public function build(): void - { - $enable_zlib = $this->builder->getLib('zlib') ? ('ON -DZLIB_LIBRARY=' . BUILD_LIB_PATH . '/libz.a -DZLIB_INCLUDE_DIR=' . BUILD_INCLUDE_PATH) : 'OFF'; - $enable_icu = $this->builder->getLib('icu') ? 'ON' : 'OFF'; - $enable_xz = $this->builder->getLib('xz') ? 'ON' : 'OFF'; - - FileSystem::resetDir($this->source_dir . '/build'); - shell()->cd($this->source_dir . '/build') - ->exec( - 'cmake ' . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . - '-DCMAKE_INSTALL_LIBDIR=' . BUILD_LIB_PATH . ' ' . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DIconv_IS_BUILT_IN=OFF ' . - '-DLIBXML2_WITH_ICONV=ON ' . - "-DLIBXML2_WITH_ZLIB={$enable_zlib} " . - "-DLIBXML2_WITH_ICU={$enable_icu} " . - "-DLIBXML2_WITH_LZMA={$enable_xz} " . - '-DLIBXML2_WITH_PYTHON=OFF ' . - '-DLIBXML2_WITH_PROGRAMS=OFF ' . - '-DLIBXML2_WITH_TESTS=OFF ' . - '..' - ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); - - FileSystem::replaceFileStr( - BUILD_LIB_PATH . '/pkgconfig/libxml-2.0.pc', - '-licudata -licui18n -licuuc', - '-licui18n -licuuc -licudata' - ); - } } diff --git a/src/SPC/builder/macos/library/glfw.php b/src/SPC/builder/macos/library/glfw.php index 355785ed..efc73b8f 100644 --- a/src/SPC/builder/macos/library/glfw.php +++ b/src/SPC/builder/macos/library/glfw.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SPC\builder\macos\library; +use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; @@ -17,11 +18,14 @@ class glfw extends MacOSLibraryBase */ protected function build(): void { - // compile! - shell()->cd(SOURCE_PATH . '/ext-glfw/vendor/glfw') - ->exec("cmake . {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF") - ->exec("make -j{$this->builder->concurrency}") - ->exec('make install'); + UnixCMakeExecutor::create($this) + ->setCMakeBuildDir("{$this->source_dir}/vendor/glfw") + ->setReset(false) + ->addConfigureArgs( + '-DGLFW_BUILD_EXAMPLES=OFF', + '-DGLFW_BUILD_TESTS=OFF', + ) + ->build('.'); // patch pkgconf $this->patchPkgconfPrefix(['glfw3.pc']); } diff --git a/src/SPC/builder/macos/library/libxml2.php b/src/SPC/builder/macos/library/libxml2.php index c0ed36c0..51fd031e 100644 --- a/src/SPC/builder/macos/library/libxml2.php +++ b/src/SPC/builder/macos/library/libxml2.php @@ -4,44 +4,9 @@ declare(strict_types=1); namespace SPC\builder\macos\library; -use SPC\exception\FileSystemException; -use SPC\exception\RuntimeException; -use SPC\store\FileSystem; - class libxml2 extends MacOSLibraryBase { + use \SPC\builder\unix\library\libxml2; + public const NAME = 'libxml2'; - - /** - * @throws RuntimeException - * @throws FileSystemException - */ - protected function build(): void - { - $enable_zlib = $this->builder->getLib('zlib') ? ('ON -DZLIB_LIBRARY=' . BUILD_LIB_PATH . '/libz.a -DZLIB_INCLUDE_DIR=' . BUILD_INCLUDE_PATH) : 'OFF'; - $enable_icu = $this->builder->getLib('icu') ? 'ON' : 'OFF'; - $enable_xz = $this->builder->getLib('xz') ? 'ON' : 'OFF'; - - FileSystem::resetDir($this->source_dir . '/build'); - shell()->cd($this->source_dir . '/build') - ->exec( - 'cmake ' . - // '--debug-find ' . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . - '-DCMAKE_INSTALL_LIBDIR=' . BUILD_LIB_PATH . ' ' . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DLIBXML2_WITH_ICONV=ON ' . - "-DLIBXML2_WITH_ZLIB={$enable_zlib} " . - "-DLIBXML2_WITH_ICU={$enable_icu} " . - "-DLIBXML2_WITH_LZMA={$enable_xz} " . - '-DLIBXML2_WITH_PYTHON=OFF ' . - '-DLIBXML2_WITH_PROGRAMS=OFF ' . - '-DLIBXML2_WITH_TESTS=OFF ' . - '..' - ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install'); - } } diff --git a/src/SPC/builder/unix/library/libxml2.php b/src/SPC/builder/unix/library/libxml2.php new file mode 100644 index 00000000..8497646d --- /dev/null +++ b/src/SPC/builder/unix/library/libxml2.php @@ -0,0 +1,42 @@ +optionalLib('zlib', "-DLIBXML2_WITH_ZLIB=ON -DZLIB_LIBRARY={$this->getLibDir()}/libz.a -DZLIB_INCLUDE_DIR={$this->getIncludeDir()}", '-DLIBXML2_WITH_ZLIB=OFF') + ->optionalLib('icu', ...cmake_boolean_args('LIBXML2_WITH_ICU')) + ->optionalLib('xz', ...cmake_boolean_args('LIBXML2_WITH_LZMA')) + ->addConfigureArgs( + '-DLIBXML2_WITH_ICONV=ON', + '-DLIBXML2_WITH_PYTHON=OFF', + '-DLIBXML2_WITH_PROGRAMS=OFF', + '-DLIBXML2_WITH_TESTS=OFF', + ); + + if ($this instanceof LinuxLibraryBase) { + $cmake->addConfigureArgs('-DIconv_IS_BUILD_IN=OFF'); + } + + $cmake->build(); + + FileSystem::replaceFileStr( + BUILD_LIB_PATH . '/pkgconfig/libxml-2.0.pc', + '-licudata -licui18n -licuuc', + '-licui18n -licuuc -licudata' + ); + } +} From f7871c0036568d4eba8dd1d4d8e94c7a9d448c35 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 01:33:21 +0800 Subject: [PATCH 07/14] Add reset function --- src/SPC/builder/unix/executor/UnixCMakeExecutor.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php index 068dd965..1cc57954 100644 --- a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php +++ b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php @@ -20,11 +20,16 @@ class UnixCMakeExecutor extends Executor protected int $steps = 3; + protected bool $reset = true; + public function build(string $build_pos = '..'): void { // set cmake dir $this->initCMakeBuildDir(); - FileSystem::resetDir($this->cmake_build_dir); + + if ($this->reset) { + FileSystem::resetDir($this->cmake_build_dir); + } // prepare environment variables $env = [ @@ -101,6 +106,12 @@ class UnixCMakeExecutor extends Executor return $this; } + public function setReset(bool $reset): static + { + $this->reset = $reset; + return $this; + } + /** * Get configure argument line. */ From 059d1349905e88091f01c338bfa767811ec44832 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 01:34:32 +0800 Subject: [PATCH 08/14] Remove unused cmake things --- src/SPC/builder/freebsd/BSDBuilder.php | 2 -- src/SPC/builder/linux/LinuxBuilder.php | 8 -------- src/SPC/builder/macos/MacOSBuilder.php | 2 -- src/SPC/builder/unix/UnixBuilderBase.php | 19 ------------------- 4 files changed, 31 deletions(-) diff --git a/src/SPC/builder/freebsd/BSDBuilder.php b/src/SPC/builder/freebsd/BSDBuilder.php index b2e246b3..0727e103 100644 --- a/src/SPC/builder/freebsd/BSDBuilder.php +++ b/src/SPC/builder/freebsd/BSDBuilder.php @@ -47,8 +47,6 @@ class BSDBuilder extends UnixBuilderBase // cflags $this->arch_c_flags = SystemUtil::getArchCFlags($this->getOption('arch')); $this->arch_cxx_flags = SystemUtil::getArchCFlags($this->getOption('arch')); - // cmake toolchain - $this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile('BSD', $this->getOption('arch'), $this->arch_c_flags); // create pkgconfig and include dir (some libs cannot create them automatically) f_mkdir(BUILD_LIB_PATH . '/pkgconfig', recursive: true); diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 1470ce50..d8ced3b0 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -48,14 +48,6 @@ class LinuxBuilder extends UnixBuilderBase // cflags $this->arch_c_flags = getenv('SPC_DEFAULT_C_FLAGS'); $this->arch_cxx_flags = getenv('SPC_DEFAULT_CXX_FLAGS'); - // cmake toolchain - $this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile( - 'Linux', - $arch, - $this->arch_c_flags, - getenv('CC'), - getenv('CXX'), - ); // cross-compiling is not supported yet /*if (php_uname('m') !== $this->arch) { diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 0baf1e7d..e218407c 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -36,8 +36,6 @@ class MacOSBuilder extends UnixBuilderBase // cflags $this->arch_c_flags = getenv('SPC_DEFAULT_C_FLAGS'); $this->arch_cxx_flags = getenv('SPC_DEFAULT_CXX_FLAGS'); - // cmake toolchain - $this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile('Darwin', getenv('SPC_ARCH'), $this->arch_c_flags); // create pkgconfig and include dir (some libs cannot create them automatically) f_mkdir(BUILD_LIB_PATH . '/pkgconfig', recursive: true); diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 8a6fc5ee..e44b4476 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -7,7 +7,6 @@ namespace SPC\builder\unix; use SPC\builder\BuilderBase; use SPC\builder\freebsd\library\BSDLibraryBase; use SPC\builder\linux\library\LinuxLibraryBase; -use SPC\builder\linux\LinuxBuilder; use SPC\builder\macos\library\MacOSLibraryBase; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; @@ -25,9 +24,6 @@ abstract class UnixBuilderBase extends BuilderBase /** @var string C++ flags */ public string $arch_cxx_flags; - /** @var string cmake toolchain file */ - public string $cmake_toolchain_file; - /** * @throws WrongUsageException * @throws FileSystemException @@ -56,21 +52,6 @@ abstract class UnixBuilderBase extends BuilderBase return array_map(fn ($x) => realpath(BUILD_LIB_PATH . "/{$x}"), $libFiles); } - /** - * Return generic cmake options when configuring cmake projects - */ - public function makeCmakeArgs(): string - { - $extra = $this instanceof LinuxBuilder ? '-DCMAKE_C_COMPILER=' . getenv('CC') . ' ' : ''; - return $extra . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . - '-DCMAKE_INSTALL_BINDIR=bin ' . - '-DCMAKE_INSTALL_LIBDIR=lib ' . - '-DCMAKE_INSTALL_INCLUDEDIR=include ' . - "-DCMAKE_TOOLCHAIN_FILE={$this->cmake_toolchain_file}"; - } - /** * Generate configure flags */ From f158fba48df405bf407d75f451e3daa135cc7247 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 01:48:48 +0800 Subject: [PATCH 09/14] Remove unused cmake things --- .../builder/traits/UnixSystemUtilTrait.php | 55 ------------------- .../unix/executor/UnixCMakeExecutor.php | 18 +++++- tests/SPC/builder/unix/UnixSystemUtilTest.php | 10 ---- 3 files changed, 16 insertions(+), 67 deletions(-) diff --git a/src/SPC/builder/traits/UnixSystemUtilTrait.php b/src/SPC/builder/traits/UnixSystemUtilTrait.php index 8b8cb743..3407a00b 100644 --- a/src/SPC/builder/traits/UnixSystemUtilTrait.php +++ b/src/SPC/builder/traits/UnixSystemUtilTrait.php @@ -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 = <<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 diff --git a/tests/SPC/builder/unix/UnixSystemUtilTest.php b/tests/SPC/builder/unix/UnixSystemUtilTest.php index 8da6c278..e17574af 100644 --- a/tests/SPC/builder/unix/UnixSystemUtilTest.php +++ b/tests/SPC/builder/unix/UnixSystemUtilTest.php @@ -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')); From 802950d941414e0a6338863965751cf131dec411 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 01:52:23 +0800 Subject: [PATCH 10/14] Whoops --- src/SPC/builder/unix/executor/UnixCMakeExecutor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php index e5064029..62bcd808 100644 --- a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php +++ b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php @@ -208,7 +208,7 @@ 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 命令,真奇怪 + // Whoops, linux may need CMAKE_AR sometimes if (PHP_OS_FAMILY === 'Linux') { $toolchain .= "\nSET(CMAKE_AR \"ar\")"; } From acd10bd978899f927ebcdbd56b25bc8530a98fd8 Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Mon, 9 Jun 2025 09:17:04 +0800 Subject: [PATCH 11/14] Update src/SPC/builder/unix/library/libzip.php Co-authored-by: Marc --- src/SPC/builder/unix/library/libzip.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SPC/builder/unix/library/libzip.php b/src/SPC/builder/unix/library/libzip.php index 406be44f..40b0970e 100644 --- a/src/SPC/builder/unix/library/libzip.php +++ b/src/SPC/builder/unix/library/libzip.php @@ -28,7 +28,6 @@ trait libzip '-DBUILD_EXAMPLES=OFF', '-DBUILD_REGRESS=OFF', '-DBUILD_TOOLS=OFF', - '-DENABLE_ZSTD=OFF', ) ->build(); $this->patchPkgconfPrefix(['libzip.pc'], PKGCONF_PATCH_PREFIX); From 3497b2a76077d34af54224ccc5c82411c09b5e7e Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Mon, 9 Jun 2025 09:17:11 +0800 Subject: [PATCH 12/14] Update src/SPC/builder/unix/library/libzip.php Co-authored-by: Marc --- src/SPC/builder/unix/library/libzip.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SPC/builder/unix/library/libzip.php b/src/SPC/builder/unix/library/libzip.php index 40b0970e..85f11211 100644 --- a/src/SPC/builder/unix/library/libzip.php +++ b/src/SPC/builder/unix/library/libzip.php @@ -20,6 +20,7 @@ trait libzip ->optionalLib('bzip2', ...cmake_boolean_args('ENABLE_BZIP2')) ->optionalLib('xz', ...cmake_boolean_args('ENABLE_LZMA')) ->optionalLib('openssl', ...cmake_boolean_args('ENABLE_OPENSSL')) + ->optionalLib('zstd', ...cmake_boolean_args('ENABLE_ZSTD')) ->addConfigureArgs( '-DENABLE_GNUTLS=OFF', '-DENABLE_MBEDTLS=OFF', From f46b714990e0e8cf05a45f6c6c57be5a714b89f9 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 09:24:31 +0800 Subject: [PATCH 13/14] For tomorrow windows executor, move it --- src/SPC/builder/macos/library/glfw.php | 2 +- src/SPC/builder/unix/library/brotli.php | 2 +- src/SPC/builder/unix/library/curl.php | 2 +- src/SPC/builder/unix/library/freetype.php | 2 +- src/SPC/builder/unix/library/gmssl.php | 2 +- src/SPC/builder/unix/library/libaom.php | 2 +- src/SPC/builder/unix/library/libavif.php | 2 +- src/SPC/builder/unix/library/libde265.php | 2 +- src/SPC/builder/unix/library/libevent.php | 2 +- src/SPC/builder/unix/library/libheif.php | 2 +- src/SPC/builder/unix/library/libjpeg.php | 2 +- src/SPC/builder/unix/library/librabbitmq.php | 2 +- src/SPC/builder/unix/library/libssh2.php | 2 +- src/SPC/builder/unix/library/libuuid.php | 2 +- src/SPC/builder/unix/library/libuv.php | 2 +- src/SPC/builder/unix/library/libwebp.php | 2 +- src/SPC/builder/unix/library/libxml2.php | 2 +- src/SPC/builder/unix/library/libyaml.php | 2 +- src/SPC/builder/unix/library/libzip.php | 2 +- src/SPC/builder/unix/library/mimalloc.php | 2 +- src/SPC/builder/unix/library/snappy.php | 2 +- src/SPC/builder/unix/library/tidy.php | 2 +- src/SPC/builder/unix/library/zstd.php | 2 +- src/SPC/{builder/unix => util}/executor/Executor.php | 2 +- src/SPC/{builder/unix => util}/executor/UnixCMakeExecutor.php | 2 +- 25 files changed, 25 insertions(+), 25 deletions(-) rename src/SPC/{builder/unix => util}/executor/Executor.php (92%) rename src/SPC/{builder/unix => util}/executor/UnixCMakeExecutor.php (99%) diff --git a/src/SPC/builder/macos/library/glfw.php b/src/SPC/builder/macos/library/glfw.php index efc73b8f..5baf5663 100644 --- a/src/SPC/builder/macos/library/glfw.php +++ b/src/SPC/builder/macos/library/glfw.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\macos\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\util\executor\UnixCMakeExecutor; class glfw extends MacOSLibraryBase { diff --git a/src/SPC/builder/unix/library/brotli.php b/src/SPC/builder/unix/library/brotli.php index a12810d7..022f31ce 100644 --- a/src/SPC/builder/unix/library/brotli.php +++ b/src/SPC/builder/unix/library/brotli.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\store\FileSystem; +use SPC\util\executor\UnixCMakeExecutor; trait brotli { diff --git a/src/SPC/builder/unix/library/curl.php b/src/SPC/builder/unix/library/curl.php index 95afe34e..ea8b6320 100644 --- a/src/SPC/builder/unix/library/curl.php +++ b/src/SPC/builder/unix/library/curl.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\util\executor\UnixCMakeExecutor; trait curl { diff --git a/src/SPC/builder/unix/library/freetype.php b/src/SPC/builder/unix/library/freetype.php index fd551593..35e62602 100644 --- a/src/SPC/builder/unix/library/freetype.php +++ b/src/SPC/builder/unix/library/freetype.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\FileSystem; +use SPC\util\executor\UnixCMakeExecutor; trait freetype { diff --git a/src/SPC/builder/unix/library/gmssl.php b/src/SPC/builder/unix/library/gmssl.php index 7c007f52..89fc5207 100644 --- a/src/SPC/builder/unix/library/gmssl.php +++ b/src/SPC/builder/unix/library/gmssl.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; +use SPC\util\executor\UnixCMakeExecutor; trait gmssl { diff --git a/src/SPC/builder/unix/library/libaom.php b/src/SPC/builder/unix/library/libaom.php index e4a28903..de92eecf 100644 --- a/src/SPC/builder/unix/library/libaom.php +++ b/src/SPC/builder/unix/library/libaom.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\util\executor\UnixCMakeExecutor; trait libaom { diff --git a/src/SPC/builder/unix/library/libavif.php b/src/SPC/builder/unix/library/libavif.php index dd9efb33..cbec640b 100644 --- a/src/SPC/builder/unix/library/libavif.php +++ b/src/SPC/builder/unix/library/libavif.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; +use SPC\util\executor\UnixCMakeExecutor; trait libavif { diff --git a/src/SPC/builder/unix/library/libde265.php b/src/SPC/builder/unix/library/libde265.php index e6e57c44..eaba0cfc 100644 --- a/src/SPC/builder/unix/library/libde265.php +++ b/src/SPC/builder/unix/library/libde265.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\util\executor\UnixCMakeExecutor; trait libde265 { diff --git a/src/SPC/builder/unix/library/libevent.php b/src/SPC/builder/unix/library/libevent.php index ee9357ac..04c35d18 100644 --- a/src/SPC/builder/unix/library/libevent.php +++ b/src/SPC/builder/unix/library/libevent.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\store\FileSystem; +use SPC\util\executor\UnixCMakeExecutor; trait libevent { diff --git a/src/SPC/builder/unix/library/libheif.php b/src/SPC/builder/unix/library/libheif.php index 0a171431..131a330d 100644 --- a/src/SPC/builder/unix/library/libheif.php +++ b/src/SPC/builder/unix/library/libheif.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\util\executor\UnixCMakeExecutor; trait libheif { diff --git a/src/SPC/builder/unix/library/libjpeg.php b/src/SPC/builder/unix/library/libjpeg.php index 1be81cf3..3f8aff9e 100644 --- a/src/SPC/builder/unix/library/libjpeg.php +++ b/src/SPC/builder/unix/library/libjpeg.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; +use SPC\util\executor\UnixCMakeExecutor; trait libjpeg { diff --git a/src/SPC/builder/unix/library/librabbitmq.php b/src/SPC/builder/unix/library/librabbitmq.php index dbf2e8ad..1e1e64d1 100644 --- a/src/SPC/builder/unix/library/librabbitmq.php +++ b/src/SPC/builder/unix/library/librabbitmq.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\util\executor\UnixCMakeExecutor; trait librabbitmq { diff --git a/src/SPC/builder/unix/library/libssh2.php b/src/SPC/builder/unix/library/libssh2.php index 9aee6116..26337ee4 100644 --- a/src/SPC/builder/unix/library/libssh2.php +++ b/src/SPC/builder/unix/library/libssh2.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\util\executor\UnixCMakeExecutor; trait libssh2 { diff --git a/src/SPC/builder/unix/library/libuuid.php b/src/SPC/builder/unix/library/libuuid.php index becb5e41..197e0f80 100644 --- a/src/SPC/builder/unix/library/libuuid.php +++ b/src/SPC/builder/unix/library/libuuid.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\store\FileSystem; +use SPC\util\executor\UnixCMakeExecutor; trait libuuid { diff --git a/src/SPC/builder/unix/library/libuv.php b/src/SPC/builder/unix/library/libuv.php index 1110d34d..b4b5e01c 100644 --- a/src/SPC/builder/unix/library/libuv.php +++ b/src/SPC/builder/unix/library/libuv.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\util\executor\UnixCMakeExecutor; trait libuv { diff --git a/src/SPC/builder/unix/library/libwebp.php b/src/SPC/builder/unix/library/libwebp.php index b735fa8e..e4f45eb4 100644 --- a/src/SPC/builder/unix/library/libwebp.php +++ b/src/SPC/builder/unix/library/libwebp.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; +use SPC\util\executor\UnixCMakeExecutor; trait libwebp { diff --git a/src/SPC/builder/unix/library/libxml2.php b/src/SPC/builder/unix/library/libxml2.php index 8497646d..72a418ef 100644 --- a/src/SPC/builder/unix/library/libxml2.php +++ b/src/SPC/builder/unix/library/libxml2.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; use SPC\builder\linux\library\LinuxLibraryBase; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\store\FileSystem; +use SPC\util\executor\UnixCMakeExecutor; trait libxml2 { diff --git a/src/SPC/builder/unix/library/libyaml.php b/src/SPC/builder/unix/library/libyaml.php index 799b141a..47ce3fb3 100644 --- a/src/SPC/builder/unix/library/libyaml.php +++ b/src/SPC/builder/unix/library/libyaml.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\store\FileSystem; +use SPC\util\executor\UnixCMakeExecutor; trait libyaml { diff --git a/src/SPC/builder/unix/library/libzip.php b/src/SPC/builder/unix/library/libzip.php index 85f11211..b8d2893f 100644 --- a/src/SPC/builder/unix/library/libzip.php +++ b/src/SPC/builder/unix/library/libzip.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\util\executor\UnixCMakeExecutor; trait libzip { diff --git a/src/SPC/builder/unix/library/mimalloc.php b/src/SPC/builder/unix/library/mimalloc.php index 7655e321..78868856 100644 --- a/src/SPC/builder/unix/library/mimalloc.php +++ b/src/SPC/builder/unix/library/mimalloc.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; +use SPC\util\executor\UnixCMakeExecutor; trait mimalloc { diff --git a/src/SPC/builder/unix/library/snappy.php b/src/SPC/builder/unix/library/snappy.php index 94d93372..7f53d78e 100644 --- a/src/SPC/builder/unix/library/snappy.php +++ b/src/SPC/builder/unix/library/snappy.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\util\executor\UnixCMakeExecutor; trait snappy { diff --git a/src/SPC/builder/unix/library/tidy.php b/src/SPC/builder/unix/library/tidy.php index ed143548..872e6e7d 100644 --- a/src/SPC/builder/unix/library/tidy.php +++ b/src/SPC/builder/unix/library/tidy.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\util\executor\UnixCMakeExecutor; trait tidy { diff --git a/src/SPC/builder/unix/library/zstd.php b/src/SPC/builder/unix/library/zstd.php index d081baae..62ac7f2c 100644 --- a/src/SPC/builder/unix/library/zstd.php +++ b/src/SPC/builder/unix/library/zstd.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\unix\executor\UnixCMakeExecutor; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; +use SPC\util\executor\UnixCMakeExecutor; trait zstd { diff --git a/src/SPC/builder/unix/executor/Executor.php b/src/SPC/util/executor/Executor.php similarity index 92% rename from src/SPC/builder/unix/executor/Executor.php rename to src/SPC/util/executor/Executor.php index 9667de9c..05bb408c 100644 --- a/src/SPC/builder/unix/executor/Executor.php +++ b/src/SPC/util/executor/Executor.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace SPC\builder\unix\executor; +namespace SPC\util\executor; use SPC\builder\freebsd\library\BSDLibraryBase; use SPC\builder\LibraryBase; diff --git a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php b/src/SPC/util/executor/UnixCMakeExecutor.php similarity index 99% rename from src/SPC/builder/unix/executor/UnixCMakeExecutor.php rename to src/SPC/util/executor/UnixCMakeExecutor.php index 62bcd808..6fe04eaa 100644 --- a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php +++ b/src/SPC/util/executor/UnixCMakeExecutor.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace SPC\builder\unix\executor; +namespace SPC\util\executor; use Closure; use SPC\exception\FileSystemException; From 9babe7f1d24531c8212819b6206dc883e77f4597 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 09:26:39 +0800 Subject: [PATCH 14/14] Rename setCMakeBuildDir to setBuildDir --- src/SPC/builder/macos/library/glfw.php | 2 +- src/SPC/builder/unix/library/brotli.php | 2 +- src/SPC/builder/unix/library/libaom.php | 2 +- src/SPC/builder/unix/library/snappy.php | 2 +- src/SPC/builder/unix/library/tidy.php | 2 +- src/SPC/builder/unix/library/zstd.php | 2 +- src/SPC/util/executor/UnixCMakeExecutor.php | 21 +++++++++------------ 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/SPC/builder/macos/library/glfw.php b/src/SPC/builder/macos/library/glfw.php index 5baf5663..8bc7ca18 100644 --- a/src/SPC/builder/macos/library/glfw.php +++ b/src/SPC/builder/macos/library/glfw.php @@ -19,7 +19,7 @@ class glfw extends MacOSLibraryBase protected function build(): void { UnixCMakeExecutor::create($this) - ->setCMakeBuildDir("{$this->source_dir}/vendor/glfw") + ->setBuildDir("{$this->source_dir}/vendor/glfw") ->setReset(false) ->addConfigureArgs( '-DGLFW_BUILD_EXAMPLES=OFF', diff --git a/src/SPC/builder/unix/library/brotli.php b/src/SPC/builder/unix/library/brotli.php index 022f31ce..7f5f4dbb 100644 --- a/src/SPC/builder/unix/library/brotli.php +++ b/src/SPC/builder/unix/library/brotli.php @@ -18,7 +18,7 @@ trait brotli protected function build(): void { UnixCMakeExecutor::create($this) - ->setCMakeBuildDir("{$this->getSourceDir()}/build-dir") + ->setBuildDir("{$this->getSourceDir()}/build-dir") ->build(); $this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']); diff --git a/src/SPC/builder/unix/library/libaom.php b/src/SPC/builder/unix/library/libaom.php index de92eecf..57129389 100644 --- a/src/SPC/builder/unix/library/libaom.php +++ b/src/SPC/builder/unix/library/libaom.php @@ -17,7 +17,7 @@ trait libaom protected function build(): void { UnixCMakeExecutor::create($this) - ->setCMakeBuildDir("{$this->source_dir}/builddir") + ->setBuildDir("{$this->source_dir}/builddir") ->addConfigureArgs('-DAOM_TARGET_GPU=generic') ->build(); $this->patchPkgconfPrefix(['aom.pc']); diff --git a/src/SPC/builder/unix/library/snappy.php b/src/SPC/builder/unix/library/snappy.php index 7f53d78e..d2bce8fc 100644 --- a/src/SPC/builder/unix/library/snappy.php +++ b/src/SPC/builder/unix/library/snappy.php @@ -17,7 +17,7 @@ trait snappy protected function build(): void { UnixCMakeExecutor::create($this) - ->setCMakeBuildDir("{$this->source_dir}/cmake/build") + ->setBuildDir("{$this->source_dir}/cmake/build") ->addConfigureArgs( '-DSNAPPY_BUILD_TESTS=OFF', '-DSNAPPY_BUILD_BENCHMARKS=OFF', diff --git a/src/SPC/builder/unix/library/tidy.php b/src/SPC/builder/unix/library/tidy.php index 872e6e7d..1d05a060 100644 --- a/src/SPC/builder/unix/library/tidy.php +++ b/src/SPC/builder/unix/library/tidy.php @@ -17,7 +17,7 @@ trait tidy protected function build(): void { UnixCMakeExecutor::create($this) - ->setCMakeBuildDir("{$this->source_dir}/build-dir") + ->setBuildDir("{$this->source_dir}/build-dir") ->addConfigureArgs('-DSUPPORT_CONSOLE_APP=OFF') ->build(); $this->patchPkgconfPrefix(['tidy.pc']); diff --git a/src/SPC/builder/unix/library/zstd.php b/src/SPC/builder/unix/library/zstd.php index 62ac7f2c..4bb99c7e 100644 --- a/src/SPC/builder/unix/library/zstd.php +++ b/src/SPC/builder/unix/library/zstd.php @@ -17,7 +17,7 @@ trait zstd protected function build(): void { UnixCMakeExecutor::create($this) - ->setCMakeBuildDir("{$this->source_dir}/build/cmake/build") + ->setBuildDir("{$this->source_dir}/build/cmake/build") ->addConfigureArgs( '-DZSTD_BUILD_STATIC=ON', '-DZSTD_BUILD_SHARED=OFF', diff --git a/src/SPC/util/executor/UnixCMakeExecutor.php b/src/SPC/util/executor/UnixCMakeExecutor.php index 6fe04eaa..71319fa0 100644 --- a/src/SPC/util/executor/UnixCMakeExecutor.php +++ b/src/SPC/util/executor/UnixCMakeExecutor.php @@ -14,7 +14,7 @@ use SPC\store\FileSystem; */ class UnixCMakeExecutor extends Executor { - protected ?string $cmake_build_dir = null; + protected ?string $build_dir = null; protected array $configure_args = []; @@ -27,10 +27,10 @@ class UnixCMakeExecutor extends Executor public function build(string $build_pos = '..'): void { // set cmake dir - $this->initCMakeBuildDir(); + $this->initBuildDir(); if ($this->reset) { - FileSystem::resetDir($this->cmake_build_dir); + FileSystem::resetDir($this->build_dir); } // prepare environment variables @@ -41,7 +41,7 @@ class UnixCMakeExecutor extends Executor ]; // prepare shell - $shell = shell()->cd($this->cmake_build_dir)->setEnv($env); + $shell = shell()->cd($this->build_dir)->setEnv($env); // config $this->steps >= 1 && $shell->execWithEnv("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()} {$build_pos}"); @@ -99,9 +99,9 @@ class UnixCMakeExecutor extends Executor * * @param string $dir custom CMake build directory */ - public function setCMakeBuildDir(string $dir): static + public function setBuildDir(string $dir): static { - $this->cmake_build_dir = $dir; + $this->build_dir = $dir; return $this; } @@ -152,15 +152,12 @@ class UnixCMakeExecutor extends Executor /** * Initialize the CMake build directory. * If the directory is not set, it defaults to the library's source directory with '/build' appended. - * - * @throws FileSystemException */ - private function initCMakeBuildDir(): void + private function initBuildDir(): void { - if ($this->cmake_build_dir === null) { - $this->cmake_build_dir = "{$this->library->getSourceDir()}/build"; + if ($this->build_dir === null) { + $this->build_dir = "{$this->library->getSourceDir()}/build"; } - FileSystem::resetDir($this->cmake_build_dir); } /**