From 521af84797447ac281f24e8f3c908424d125d645 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 00:16:18 +0800 Subject: [PATCH 01/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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); } /** From 123cc92756fa9f530892e3d820224533cafc7e09 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 10:24:06 +0800 Subject: [PATCH 15/24] Extract default build env to unix shell --- src/SPC/builder/Extension.php | 8 ++-- src/SPC/builder/linux/library/libffi.php | 10 ++--- src/SPC/builder/linux/library/libpng.php | 15 +++---- src/SPC/builder/linux/library/openssl.php | 7 ++- src/SPC/builder/macos/library/openssl.php | 5 +-- src/SPC/builder/unix/library/attr.php | 16 +++---- src/SPC/builder/unix/library/bzip2.php | 7 ++- src/SPC/builder/unix/library/gettext.php | 16 +++---- src/SPC/builder/unix/library/gmp.php | 9 ++-- src/SPC/builder/unix/library/imagemagick.php | 11 ++--- src/SPC/builder/unix/library/ldap.php | 11 ++--- src/SPC/builder/unix/library/libacl.php | 16 +++---- src/SPC/builder/unix/library/libargon2.php | 7 ++- src/SPC/builder/unix/library/libcares.php | 9 ++-- src/SPC/builder/unix/library/libiconv.php | 11 +++-- src/SPC/builder/unix/library/liblz4.php | 9 ++-- src/SPC/builder/unix/library/libtiff.php | 11 +++-- src/SPC/builder/unix/library/libxslt.php | 18 ++++---- src/SPC/builder/unix/library/ncurses.php | 11 +++-- src/SPC/builder/unix/library/nghttp2.php | 11 +++-- src/SPC/builder/unix/library/nghttp3.php | 15 +++---- src/SPC/builder/unix/library/ngtcp2.php | 15 +++---- src/SPC/builder/unix/library/onig.php | 9 ++-- src/SPC/builder/unix/library/pkgconfig.php | 10 ++--- src/SPC/builder/unix/library/readline.php | 11 +++-- src/SPC/builder/unix/library/sqlite.php | 11 +++-- src/SPC/builder/unix/library/zlib.php | 11 +++-- src/SPC/util/UnixShell.php | 47 ++++++++++++++++---- src/SPC/util/executor/UnixCMakeExecutor.php | 15 ++----- 29 files changed, 166 insertions(+), 196 deletions(-) diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index a3d08f09..79c0a957 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -301,10 +301,10 @@ class Extension // prepare configure args shell()->cd($this->source_dir) ->setEnv($env) - ->execWithEnv(BUILD_BIN_PATH . '/phpize') - ->execWithEnv('./configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config --enable-shared --disable-static') - ->execWithEnv('make clean') - ->execWithEnv('make -j' . $this->builder->concurrency); + ->exec(BUILD_BIN_PATH . '/phpize') + ->exec('./configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config --enable-shared --disable-static') + ->exec('make clean') + ->exec('make -j' . $this->builder->concurrency); // copy shared library copy($this->source_dir . '/modules/' . $this->getDistName() . '.so', BUILD_LIB_PATH . '/' . $this->getDistName() . '.so'); diff --git a/src/SPC/builder/linux/library/libffi.php b/src/SPC/builder/linux/library/libffi.php index 9d1c2d79..0324f92c 100644 --- a/src/SPC/builder/linux/library/libffi.php +++ b/src/SPC/builder/linux/library/libffi.php @@ -21,8 +21,8 @@ class libffi extends LinuxLibraryBase $arch = getenv('SPC_ARCH'); shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + ->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . @@ -31,9 +31,9 @@ class libffi extends LinuxLibraryBase '--prefix= ' . "--libdir={$lib}" ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv("make install DESTDIR={$destdir}"); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec("make install DESTDIR={$destdir}"); if (is_file(BUILD_ROOT_PATH . '/lib64/libffi.a')) { copy(BUILD_ROOT_PATH . '/lib64/libffi.a', BUILD_ROOT_PATH . '/lib/libffi.a'); diff --git a/src/SPC/builder/linux/library/libpng.php b/src/SPC/builder/linux/library/libpng.php index 56daee55..fc8c8099 100644 --- a/src/SPC/builder/linux/library/libpng.php +++ b/src/SPC/builder/linux/library/libpng.php @@ -41,15 +41,10 @@ class libpng extends LinuxLibraryBase 'aarch64' => '--enable-arm-neon ', default => '', }; - shell()->cd($this->source_dir) + shell()->cd($this->source_dir)->initLibBuildEnv($this) ->exec('chmod +x ./configure') ->exec('chmod +x ./install-sh') - ->setEnv([ - 'CFLAGS' => trim($this->getLibExtraCFlags() . ' ' . $this->builder->arch_c_flags), - 'LDFLAGS' => $this->getLibExtraLdFlags(), - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv( + ->exec( 'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' . './configure ' . '--disable-shared ' . @@ -59,9 +54,9 @@ class libpng extends LinuxLibraryBase $optimizations . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I{$this->source_dir} -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la") - ->execWithEnv('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I{$this->source_dir} -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la") + ->exec('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libpng16.pc'], PKGCONF_PATCH_PREFIX); $this->cleanLaFiles(); } diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index d57265dd..576396e6 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -64,9 +64,8 @@ class openssl extends LinuxLibraryBase $clang_postfix = SystemUtil::getCCType(getenv('CC')) === 'clang' ? '-clang' : ''; - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $this->builder->arch_c_flags, 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( "{$env} ./Configure no-shared {$extra} " . '--prefix=/ ' . '--libdir=lib ' . @@ -76,7 +75,7 @@ class openssl extends LinuxLibraryBase "linux-{$arch}{$clang_postfix}" ) ->exec('make clean') - ->execWithEnv("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") + ->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") ->exec("make install_sw DESTDIR={$destdir}"); $this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); // patch for openssl 3.3.0+ diff --git a/src/SPC/builder/macos/library/openssl.php b/src/SPC/builder/macos/library/openssl.php index e0e3919f..f4512871 100644 --- a/src/SPC/builder/macos/library/openssl.php +++ b/src/SPC/builder/macos/library/openssl.php @@ -49,8 +49,7 @@ class openssl extends MacOSLibraryBase } $arch = getenv('SPC_ARCH'); - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) + shell()->cd($this->source_dir)->initLibBuildEnv($this) ->exec( "./Configure no-shared {$extra} " . '--prefix=/ ' . // use prefix=/ @@ -59,7 +58,7 @@ class openssl extends MacOSLibraryBase "darwin64-{$arch}-cc" ) ->exec('make clean') - ->execWithEnv("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") + ->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") ->exec("make install_sw DESTDIR={$destdir}"); $this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); // patch for openssl 3.3.0+ diff --git a/src/SPC/builder/unix/library/attr.php b/src/SPC/builder/unix/library/attr.php index ce542ddd..26278cb0 100644 --- a/src/SPC/builder/unix/library/attr.php +++ b/src/SPC/builder/unix/library/attr.php @@ -13,16 +13,12 @@ trait attr */ protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags()), - 'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags()), - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv('libtoolize --force --copy') - ->execWithEnv('./autogen.sh || autoreconf -if') - ->execWithEnv('./configure --prefix= --enable-static --disable-shared --with-pic --disable-nls') - ->execWithEnv("make -j {$this->builder->concurrency}") + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv(['CFLAGS' => "-I{$this->getIncludeDir()}", 'LDFLAGS' => "-L{$this->getLibDir()}"]) + ->exec('libtoolize --force --copy') + ->exec('./autogen.sh || autoreconf -if') + ->exec('./configure --prefix= --enable-static --disable-shared --with-pic --disable-nls') + ->exec("make -j {$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libattr.pc'], PKGCONF_PATCH_PREFIX); diff --git a/src/SPC/builder/unix/library/bzip2.php b/src/SPC/builder/unix/library/bzip2.php index 0241fb1b..7315f4e1 100644 --- a/src/SPC/builder/unix/library/bzip2.php +++ b/src/SPC/builder/unix/library/bzip2.php @@ -16,10 +16,9 @@ trait bzip2 protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv("make PREFIX='" . BUILD_ROOT_PATH . "' clean") - ->execWithEnv("make -j{$this->builder->concurrency} {$this->builder->getEnvString()} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a") + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec("make PREFIX='" . BUILD_ROOT_PATH . "' clean") + ->exec("make -j{$this->builder->concurrency} {$this->builder->getEnvString()} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a") ->exec('cp libbz2.a ' . BUILD_LIB_PATH) ->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH); } diff --git a/src/SPC/builder/unix/library/gettext.php b/src/SPC/builder/unix/library/gettext.php index 69736c36..b3800ac5 100644 --- a/src/SPC/builder/unix/library/gettext.php +++ b/src/SPC/builder/unix/library/gettext.php @@ -16,13 +16,9 @@ trait gettext $cflags = $this->builder->getOption('enable-zts') ? '-lpthread -D_REENTRANT' : ''; $ldflags = $this->builder->getOption('enable-zts') ? '-lpthread' : ''; - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => "{$this->getLibExtraCFlags()} {$cflags}", - 'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags, - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv(['CFLAGS' => $cflags, 'LDFLAGS' => $ldflags]) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . @@ -34,8 +30,8 @@ trait gettext '--with-libiconv-prefix=' . BUILD_ROOT_PATH . ' ' . '--prefix=' . BUILD_ROOT_PATH ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install'); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install'); } } diff --git a/src/SPC/builder/unix/library/gmp.php b/src/SPC/builder/unix/library/gmp.php index 49b207fb..40cf71d5 100644 --- a/src/SPC/builder/unix/library/gmp.php +++ b/src/SPC/builder/unix/library/gmp.php @@ -15,15 +15,14 @@ trait gmp */ protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $this->builder->arch_c_flags, 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static --disable-shared ' . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['gmp.pc']); } diff --git a/src/SPC/builder/unix/library/imagemagick.php b/src/SPC/builder/unix/library/imagemagick.php index 56da92e5..6f39385c 100644 --- a/src/SPC/builder/unix/library/imagemagick.php +++ b/src/SPC/builder/unix/library/imagemagick.php @@ -46,14 +46,9 @@ trait imagemagick // libxml iconv patch $required_libs .= $this instanceof MacOSLibraryBase ? ('-liconv') : ''; - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => $this->getLibExtraCFlags(), - 'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags, - 'LIBS' => $this->getLibExtraLibs() ?: $required_libs, - 'PKG_CONFIG' => '$PKG_CONFIG --static', - ]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv(['LDFLAGS' => $ldflags, 'LIBS' => $required_libs, 'PKG_CONFIG' => '$PKG_CONFIG --static']) + ->exec( './configure ' . '--enable-static --disable-shared ' . $extra . diff --git a/src/SPC/builder/unix/library/ldap.php b/src/SPC/builder/unix/library/ldap.php index 2831f094..0d1b1ad2 100644 --- a/src/SPC/builder/unix/library/ldap.php +++ b/src/SPC/builder/unix/library/ldap.php @@ -26,14 +26,9 @@ trait ldap $alt .= $this->builder->getLib('libsodium') ? '--with-argon2=libsodium ' : '--enable-argon2=no '; f_putenv('PKG_CONFIG=' . BUILD_ROOT_PATH . '/bin/pkg-config'); f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig'); - $ldflags = '-L' . BUILD_LIB_PATH; - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => $this->getLibExtraCFlags(), - 'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags, - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv(['LDFLAGS' => "-L{$this->getLibDir()}"]) + ->exec( $this->builder->makeAutoconfFlags(AUTOCONF_CPPFLAGS) . ' ./configure ' . '--enable-static ' . diff --git a/src/SPC/builder/unix/library/libacl.php b/src/SPC/builder/unix/library/libacl.php index 6abfbb5b..0522786f 100644 --- a/src/SPC/builder/unix/library/libacl.php +++ b/src/SPC/builder/unix/library/libacl.php @@ -29,16 +29,12 @@ trait libacl */ protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags()), - 'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags()), - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv('libtoolize --force --copy') - ->execWithEnv('./autogen.sh || autoreconf -if') - ->execWithEnv('./configure --prefix= --enable-static --disable-shared --disable-tests --disable-nls') - ->execWithEnv("make -j {$this->builder->concurrency}") + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv(['CFLAGS' => "-I{$this->getIncludeDir()}", 'LDFLAGS' => "-L{$this->getLibDir()}"]) + ->exec('libtoolize --force --copy') + ->exec('./autogen.sh || autoreconf -if') + ->exec('./configure --prefix= --enable-static --disable-shared --disable-tests --disable-nls') + ->exec("make -j {$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libacl.pc'], PKGCONF_PATCH_PREFIX); diff --git a/src/SPC/builder/unix/library/libargon2.php b/src/SPC/builder/unix/library/libargon2.php index e91b71f0..e235f575 100644 --- a/src/SPC/builder/unix/library/libargon2.php +++ b/src/SPC/builder/unix/library/libargon2.php @@ -10,11 +10,10 @@ trait libargon2 { protected function build() { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) + shell()->cd($this->source_dir)->initLibBuildEnv($this) ->exec("make PREFIX='' clean") - ->execWithEnv("make -j{$this->builder->concurrency} PREFIX=''") - ->execWithEnv("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); + ->exec("make -j{$this->builder->concurrency} PREFIX=''") + ->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libargon2.pc']); diff --git a/src/SPC/builder/unix/library/libcares.php b/src/SPC/builder/unix/library/libcares.php index d99cc685..3acd9814 100644 --- a/src/SPC/builder/unix/library/libcares.php +++ b/src/SPC/builder/unix/library/libcares.php @@ -24,11 +24,10 @@ trait libcares */ protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv('./configure --prefix= --enable-static --disable-shared --disable-tests --with-pic') - ->execWithEnv("make -j {$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec('./configure --prefix= --enable-static --disable-shared --disable-tests --with-pic') + ->exec("make -j {$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libcares.pc'], PKGCONF_PATCH_PREFIX); } diff --git a/src/SPC/builder/unix/library/libiconv.php b/src/SPC/builder/unix/library/libiconv.php index a587c472..6037d5d0 100644 --- a/src/SPC/builder/unix/library/libiconv.php +++ b/src/SPC/builder/unix/library/libiconv.php @@ -10,18 +10,17 @@ trait libiconv { [,,$destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . '--enable-extra-encodings ' . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . $destdir); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . $destdir); if (file_exists(BUILD_BIN_PATH . '/iconv')) { unlink(BUILD_BIN_PATH . '/iconv'); diff --git a/src/SPC/builder/unix/library/liblz4.php b/src/SPC/builder/unix/library/liblz4.php index 45e803bf..d5283cbe 100644 --- a/src/SPC/builder/unix/library/liblz4.php +++ b/src/SPC/builder/unix/library/liblz4.php @@ -17,11 +17,10 @@ trait liblz4 protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv("make PREFIX='' clean") - ->execWithEnv("make -j{$this->builder->concurrency} PREFIX=''") - ->execWithEnv("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec("make PREFIX='' clean") + ->exec("make -j{$this->builder->concurrency} PREFIX=''") + ->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['liblz4.pc']); diff --git a/src/SPC/builder/unix/library/libtiff.php b/src/SPC/builder/unix/library/libtiff.php index 5d2cb4c1..5561adcb 100644 --- a/src/SPC/builder/unix/library/libtiff.php +++ b/src/SPC/builder/unix/library/libtiff.php @@ -22,9 +22,8 @@ trait libtiff // We disabled lzma, zstd, webp, libdeflate by default to reduce the size of the binary $extra_libs .= ' --disable-lzma --disable-zstd --disable-webp --disable-libdeflate'; - $shell = shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + $shell = shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static --disable-shared ' . "{$extra_libs} " . @@ -34,12 +33,12 @@ trait libtiff // TODO: Remove this check when https://gitlab.com/libtiff/libtiff/-/merge_requests/635 will be merged and released if (file_exists($this->source_dir . '/html')) { - $shell->execWithEnv('make clean'); + $shell->exec('make clean'); } $shell - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libtiff-4.pc']); } } diff --git a/src/SPC/builder/unix/library/libxslt.php b/src/SPC/builder/unix/library/libxslt.php index 799c87c2..f0d2592f 100644 --- a/src/SPC/builder/unix/library/libxslt.php +++ b/src/SPC/builder/unix/library/libxslt.php @@ -24,13 +24,13 @@ trait libxslt $required_libs .= ' ' . $dep->getStaticLibFiles(); } } - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => trim($this->getLibExtraCFlags() . ' -I' . BUILD_INCLUDE_PATH), - 'LDFLAGS' => trim($this->getLibExtraLdFlags() . ' -L' . BUILD_LIB_PATH), - 'LIBS' => trim($this->getLibExtraLibs() . "{$required_libs} -lstdc++"), + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv([ + 'CFLAGS' => "-I{$this->getIncludeDir()}", + 'LDFLAGS' => "-L{$this->getLibDir()}", + 'LIBS' => "{$required_libs} -lstdc++", ]) - ->execWithEnv( + ->exec( "{$this->builder->getOption('library_path')} " . "{$this->builder->getOption('ld_library_path')} " . './configure ' . @@ -43,9 +43,9 @@ trait libxslt '--with-libxml-prefix=' . escapeshellarg(BUILD_ROOT_PATH) . ' ' . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . escapeshellarg(BUILD_ROOT_PATH)); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . escapeshellarg(BUILD_ROOT_PATH)); $this->patchPkgconfPrefix(['libexslt.pc']); } } diff --git a/src/SPC/builder/unix/library/ncurses.php b/src/SPC/builder/unix/library/ncurses.php index a44ac175..42b4f2d3 100644 --- a/src/SPC/builder/unix/library/ncurses.php +++ b/src/SPC/builder/unix/library/ncurses.php @@ -11,9 +11,8 @@ trait ncurses protected function build(): void { $filelist = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true); - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . @@ -33,9 +32,9 @@ trait ncurses '--libdir=' . BUILD_ROOT_PATH . '/lib ' . '--prefix=' . BUILD_ROOT_PATH ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install'); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install'); $final = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true); // Remove the new files diff --git a/src/SPC/builder/unix/library/nghttp2.php b/src/SPC/builder/unix/library/nghttp2.php index 202b2959..d8f4dc29 100644 --- a/src/SPC/builder/unix/library/nghttp2.php +++ b/src/SPC/builder/unix/library/nghttp2.php @@ -40,9 +40,8 @@ trait nghttp2 [,,$destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . @@ -51,9 +50,9 @@ trait nghttp2 $args . ' ' . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv("make install DESTDIR={$destdir}"); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec("make install DESTDIR={$destdir}"); $this->patchPkgconfPrefix(['libnghttp2.pc']); } } diff --git a/src/SPC/builder/unix/library/nghttp3.php b/src/SPC/builder/unix/library/nghttp3.php index 03d4d481..4c1c8284 100644 --- a/src/SPC/builder/unix/library/nghttp3.php +++ b/src/SPC/builder/unix/library/nghttp3.php @@ -15,13 +15,8 @@ trait nghttp3 */ protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => $this->getLibExtraCFlags(), - 'LDFLAGS' => $this->getLibExtraLdFlags(), - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . @@ -29,9 +24,9 @@ trait nghttp3 '--enable-lib-only ' . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libnghttp3.pc']); } } diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php index 8ea280a8..66ba1306 100644 --- a/src/SPC/builder/unix/library/ngtcp2.php +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -30,13 +30,8 @@ trait ngtcp2 $args .= ' --with-libbrotlienc=yes LIBBROTLIENC_CFLAGS="-I' . BUILD_ROOT_PATH . '/include" LIBBROTLIENC_LIBS="' . $brotli->getStaticLibFiles() . '"'; } - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => $this->getLibExtraCFlags(), - 'LDFLAGS' => $this->getLibExtraLdFlags(), - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . @@ -45,9 +40,9 @@ trait ngtcp2 $args . ' ' . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libngtcp2.pc', 'libngtcp2_crypto_ossl.pc']); // on macOS, the static library may contain other static libraries? diff --git a/src/SPC/builder/unix/library/onig.php b/src/SPC/builder/unix/library/onig.php index 60ea84fa..380e05b2 100644 --- a/src/SPC/builder/unix/library/onig.php +++ b/src/SPC/builder/unix/library/onig.php @@ -17,11 +17,10 @@ trait onig { [,,$destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $this->builder->arch_c_flags, 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv('./configure --enable-static --disable-shared --prefix=') - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec('./configure --enable-static --disable-shared --prefix=') + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") ->exec("make install DESTDIR={$destdir}"); $this->patchPkgconfPrefix(['oniguruma.pc']); } diff --git a/src/SPC/builder/unix/library/pkgconfig.php b/src/SPC/builder/unix/library/pkgconfig.php index b489bbba..5fc89113 100644 --- a/src/SPC/builder/unix/library/pkgconfig.php +++ b/src/SPC/builder/unix/library/pkgconfig.php @@ -13,9 +13,9 @@ trait pkgconfig $cflags = PHP_OS_FAMILY !== 'Linux' ? "{$this->builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion" : ''; $ldflags = !($this instanceof LinuxLibraryBase) || getenv('SPC_LIBC') === 'glibc' ? '' : '--static'; - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => "{$this->getLibExtraCFlags()} {$cflags}", 'LDFLAGS' => "{$this->getLibExtraLdFlags()} {$ldflags}", 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv(['CFLAGS' => $cflags, 'LDFLAGS' => $ldflags]) + ->exec( './configure ' . '--disable-shared ' . '--enable-static ' . @@ -29,8 +29,8 @@ trait pkgconfig '--without-pc-path' ) ->exec('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install-exec'); + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install-exec'); shell()->exec('strip ' . BUILD_ROOT_PATH . '/bin/pkg-config'); } } diff --git a/src/SPC/builder/unix/library/readline.php b/src/SPC/builder/unix/library/readline.php index d0369c1a..a7339d60 100644 --- a/src/SPC/builder/unix/library/readline.php +++ b/src/SPC/builder/unix/library/readline.php @@ -15,9 +15,8 @@ trait readline */ protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static=yes ' . '--enable-shared=no ' . @@ -25,9 +24,9 @@ trait readline '--with-curses ' . '--enable-multibyte=yes' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['readline.pc']); } } diff --git a/src/SPC/builder/unix/library/sqlite.php b/src/SPC/builder/unix/library/sqlite.php index ee814702..42e23679 100644 --- a/src/SPC/builder/unix/library/sqlite.php +++ b/src/SPC/builder/unix/library/sqlite.php @@ -8,12 +8,11 @@ trait sqlite { protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv('./configure --enable-static --disable-shared --prefix=') - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec('./configure --enable-static --disable-shared --prefix=') + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['sqlite3.pc']); } } diff --git a/src/SPC/builder/unix/library/zlib.php b/src/SPC/builder/unix/library/zlib.php index f764de91..f2490a6c 100644 --- a/src/SPC/builder/unix/library/zlib.php +++ b/src/SPC/builder/unix/library/zlib.php @@ -17,12 +17,11 @@ trait zlib { [,,$destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv('./configure --static --prefix=') - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv("make install DESTDIR={$destdir}"); + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec('./configure --static --prefix=') + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec("make install DESTDIR={$destdir}"); $this->patchPkgconfPrefix(['zlib.pc']); } } diff --git a/src/SPC/util/UnixShell.php b/src/SPC/util/UnixShell.php index 44e97bfe..9dd779a7 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -4,6 +4,9 @@ declare(strict_types=1); namespace SPC\util; +use SPC\builder\freebsd\library\BSDLibraryBase; +use SPC\builder\linux\library\LinuxLibraryBase; +use SPC\builder\macos\library\MacOSLibraryBase; use SPC\exception\RuntimeException; use ZM\Logger\ConsoleColor; @@ -48,7 +51,41 @@ class UnixShell if (!$this->debug) { $cmd .= ' 1>/dev/null 2>&1'; } - f_passthru($cmd); + $env_str = $this->getEnvString(); + if (!empty($env_str)) { + $env_str = "{$env_str} "; + } + f_passthru("{$env_str}{$cmd}"); + return $this; + } + + /** + * Init the environment variable that common build will be used. + * + * @param BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library Library class + */ + public function initLibBuildEnv(BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library): UnixShell + { + $this->setEnv([ + 'CFLAGS' => $library->getLibExtraCFlags(), + 'LDFLAGS' => $library->getLibExtraLdFlags(), + 'LIBS' => $library->getLibExtraLibs(), + ]); + return $this; + } + + public function appendEnv(array $env): UnixShell + { + foreach ($env as $k => $v) { + if ($v === '') { + continue; + } + if (!isset($this->env[$k])) { + $this->env[$k] = $v; + } else { + $this->env[$k] = "{$v} {$this->env[$k]}"; + } + } return $this; } @@ -80,14 +117,6 @@ class UnixShell return $this; } - /** - * @throws RuntimeException - */ - public function execWithEnv(string $cmd): UnixShell - { - return $this->exec($this->getEnvString() . ' ' . $cmd); - } - private function getEnvString(): string { $str = ''; diff --git a/src/SPC/util/executor/UnixCMakeExecutor.php b/src/SPC/util/executor/UnixCMakeExecutor.php index 71319fa0..9cb0d52d 100644 --- a/src/SPC/util/executor/UnixCMakeExecutor.php +++ b/src/SPC/util/executor/UnixCMakeExecutor.php @@ -33,24 +33,17 @@ class UnixCMakeExecutor extends Executor FileSystem::resetDir($this->build_dir); } - // prepare environment variables - $env = [ - 'CFLAGS' => $this->library->getLibExtraCFlags(), - 'LDFLAGS' => $this->library->getLibExtraLdFlags(), - 'LIBS' => $this->library->getLibExtraLibs(), - ]; - // prepare shell - $shell = shell()->cd($this->build_dir)->setEnv($env); + $shell = shell()->cd($this->build_dir)->initLibBuildEnv($this->library); // config - $this->steps >= 1 && $shell->execWithEnv("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()} {$build_pos}"); + $this->steps >= 1 && $shell->exec("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()} {$build_pos}"); // make - $this->steps >= 2 && $shell->execWithEnv("cmake --build . -j {$this->library->getBuilder()->concurrency}"); + $this->steps >= 2 && $shell->exec("cmake --build . -j {$this->library->getBuilder()->concurrency}"); // install - $this->steps >= 3 && $shell->execWithEnv('make install'); + $this->steps >= 3 && $shell->exec('make install'); } /** From 0558d67240e0304b8ec5ee181e0a22ab1f86a80d Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 11:12:34 +0800 Subject: [PATCH 16/24] Rename initBuildEnv to initializeEnv --- src/SPC/builder/linux/library/libffi.php | 2 +- src/SPC/builder/linux/library/libpng.php | 2 +- src/SPC/builder/linux/library/openssl.php | 2 +- src/SPC/builder/macos/library/openssl.php | 2 +- src/SPC/builder/unix/library/attr.php | 2 +- src/SPC/builder/unix/library/bzip2.php | 2 +- src/SPC/builder/unix/library/gettext.php | 2 +- src/SPC/builder/unix/library/gmp.php | 2 +- src/SPC/builder/unix/library/imagemagick.php | 2 +- src/SPC/builder/unix/library/ldap.php | 2 +- src/SPC/builder/unix/library/libacl.php | 2 +- src/SPC/builder/unix/library/libargon2.php | 2 +- src/SPC/builder/unix/library/libcares.php | 2 +- src/SPC/builder/unix/library/libiconv.php | 2 +- src/SPC/builder/unix/library/liblz4.php | 2 +- src/SPC/builder/unix/library/libtiff.php | 2 +- src/SPC/builder/unix/library/libxslt.php | 2 +- src/SPC/builder/unix/library/ncurses.php | 2 +- src/SPC/builder/unix/library/nghttp2.php | 2 +- src/SPC/builder/unix/library/nghttp3.php | 2 +- src/SPC/builder/unix/library/ngtcp2.php | 2 +- src/SPC/builder/unix/library/onig.php | 2 +- src/SPC/builder/unix/library/pkgconfig.php | 2 +- src/SPC/builder/unix/library/readline.php | 2 +- src/SPC/builder/unix/library/sqlite.php | 2 +- src/SPC/builder/unix/library/zlib.php | 2 +- src/SPC/util/UnixShell.php | 2 +- src/SPC/util/executor/UnixCMakeExecutor.php | 2 +- 28 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/SPC/builder/linux/library/libffi.php b/src/SPC/builder/linux/library/libffi.php index 0324f92c..e64581bc 100644 --- a/src/SPC/builder/linux/library/libffi.php +++ b/src/SPC/builder/linux/library/libffi.php @@ -21,7 +21,7 @@ class libffi extends LinuxLibraryBase $arch = getenv('SPC_ARCH'); shell()->cd($this->source_dir) - ->initLibBuildEnv($this) + ->initializeEnv($this) ->exec( './configure ' . '--enable-static ' . diff --git a/src/SPC/builder/linux/library/libpng.php b/src/SPC/builder/linux/library/libpng.php index fc8c8099..8c33ef0f 100644 --- a/src/SPC/builder/linux/library/libpng.php +++ b/src/SPC/builder/linux/library/libpng.php @@ -41,7 +41,7 @@ class libpng extends LinuxLibraryBase 'aarch64' => '--enable-arm-neon ', default => '', }; - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec('chmod +x ./configure') ->exec('chmod +x ./install-sh') ->exec( diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index 576396e6..11c60067 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -64,7 +64,7 @@ class openssl extends LinuxLibraryBase $clang_postfix = SystemUtil::getCCType(getenv('CC')) === 'clang' ? '-clang' : ''; - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec( "{$env} ./Configure no-shared {$extra} " . '--prefix=/ ' . diff --git a/src/SPC/builder/macos/library/openssl.php b/src/SPC/builder/macos/library/openssl.php index f4512871..d641fc1d 100644 --- a/src/SPC/builder/macos/library/openssl.php +++ b/src/SPC/builder/macos/library/openssl.php @@ -49,7 +49,7 @@ class openssl extends MacOSLibraryBase } $arch = getenv('SPC_ARCH'); - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec( "./Configure no-shared {$extra} " . '--prefix=/ ' . // use prefix=/ diff --git a/src/SPC/builder/unix/library/attr.php b/src/SPC/builder/unix/library/attr.php index 26278cb0..b6254720 100644 --- a/src/SPC/builder/unix/library/attr.php +++ b/src/SPC/builder/unix/library/attr.php @@ -13,7 +13,7 @@ trait attr */ protected function build(): void { - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->appendEnv(['CFLAGS' => "-I{$this->getIncludeDir()}", 'LDFLAGS' => "-L{$this->getLibDir()}"]) ->exec('libtoolize --force --copy') ->exec('./autogen.sh || autoreconf -if') diff --git a/src/SPC/builder/unix/library/bzip2.php b/src/SPC/builder/unix/library/bzip2.php index 7315f4e1..32d87270 100644 --- a/src/SPC/builder/unix/library/bzip2.php +++ b/src/SPC/builder/unix/library/bzip2.php @@ -16,7 +16,7 @@ trait bzip2 protected function build(): void { - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec("make PREFIX='" . BUILD_ROOT_PATH . "' clean") ->exec("make -j{$this->builder->concurrency} {$this->builder->getEnvString()} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a") ->exec('cp libbz2.a ' . BUILD_LIB_PATH) diff --git a/src/SPC/builder/unix/library/gettext.php b/src/SPC/builder/unix/library/gettext.php index b3800ac5..75f50d1b 100644 --- a/src/SPC/builder/unix/library/gettext.php +++ b/src/SPC/builder/unix/library/gettext.php @@ -16,7 +16,7 @@ trait gettext $cflags = $this->builder->getOption('enable-zts') ? '-lpthread -D_REENTRANT' : ''; $ldflags = $this->builder->getOption('enable-zts') ? '-lpthread' : ''; - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->appendEnv(['CFLAGS' => $cflags, 'LDFLAGS' => $ldflags]) ->exec( './configure ' . diff --git a/src/SPC/builder/unix/library/gmp.php b/src/SPC/builder/unix/library/gmp.php index 40cf71d5..2f4ba1a4 100644 --- a/src/SPC/builder/unix/library/gmp.php +++ b/src/SPC/builder/unix/library/gmp.php @@ -15,7 +15,7 @@ trait gmp */ protected function build(): void { - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec( './configure ' . '--enable-static --disable-shared ' . diff --git a/src/SPC/builder/unix/library/imagemagick.php b/src/SPC/builder/unix/library/imagemagick.php index 6f39385c..5ace2296 100644 --- a/src/SPC/builder/unix/library/imagemagick.php +++ b/src/SPC/builder/unix/library/imagemagick.php @@ -46,7 +46,7 @@ trait imagemagick // libxml iconv patch $required_libs .= $this instanceof MacOSLibraryBase ? ('-liconv') : ''; - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->appendEnv(['LDFLAGS' => $ldflags, 'LIBS' => $required_libs, 'PKG_CONFIG' => '$PKG_CONFIG --static']) ->exec( './configure ' . diff --git a/src/SPC/builder/unix/library/ldap.php b/src/SPC/builder/unix/library/ldap.php index 0d1b1ad2..bad3a65b 100644 --- a/src/SPC/builder/unix/library/ldap.php +++ b/src/SPC/builder/unix/library/ldap.php @@ -26,7 +26,7 @@ trait ldap $alt .= $this->builder->getLib('libsodium') ? '--with-argon2=libsodium ' : '--enable-argon2=no '; f_putenv('PKG_CONFIG=' . BUILD_ROOT_PATH . '/bin/pkg-config'); f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig'); - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->appendEnv(['LDFLAGS' => "-L{$this->getLibDir()}"]) ->exec( $this->builder->makeAutoconfFlags(AUTOCONF_CPPFLAGS) . diff --git a/src/SPC/builder/unix/library/libacl.php b/src/SPC/builder/unix/library/libacl.php index 0522786f..8f61be1b 100644 --- a/src/SPC/builder/unix/library/libacl.php +++ b/src/SPC/builder/unix/library/libacl.php @@ -29,7 +29,7 @@ trait libacl */ protected function build(): void { - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->appendEnv(['CFLAGS' => "-I{$this->getIncludeDir()}", 'LDFLAGS' => "-L{$this->getLibDir()}"]) ->exec('libtoolize --force --copy') ->exec('./autogen.sh || autoreconf -if') diff --git a/src/SPC/builder/unix/library/libargon2.php b/src/SPC/builder/unix/library/libargon2.php index e235f575..4c760095 100644 --- a/src/SPC/builder/unix/library/libargon2.php +++ b/src/SPC/builder/unix/library/libargon2.php @@ -10,7 +10,7 @@ trait libargon2 { protected function build() { - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec("make PREFIX='' clean") ->exec("make -j{$this->builder->concurrency} PREFIX=''") ->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); diff --git a/src/SPC/builder/unix/library/libcares.php b/src/SPC/builder/unix/library/libcares.php index 3acd9814..61683bbf 100644 --- a/src/SPC/builder/unix/library/libcares.php +++ b/src/SPC/builder/unix/library/libcares.php @@ -24,7 +24,7 @@ trait libcares */ protected function build(): void { - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec('./configure --prefix= --enable-static --disable-shared --disable-tests --with-pic') ->exec("make -j {$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); diff --git a/src/SPC/builder/unix/library/libiconv.php b/src/SPC/builder/unix/library/libiconv.php index 6037d5d0..89c8e5bf 100644 --- a/src/SPC/builder/unix/library/libiconv.php +++ b/src/SPC/builder/unix/library/libiconv.php @@ -10,7 +10,7 @@ trait libiconv { [,,$destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec( './configure ' . '--enable-static ' . diff --git a/src/SPC/builder/unix/library/liblz4.php b/src/SPC/builder/unix/library/liblz4.php index d5283cbe..73108d95 100644 --- a/src/SPC/builder/unix/library/liblz4.php +++ b/src/SPC/builder/unix/library/liblz4.php @@ -17,7 +17,7 @@ trait liblz4 protected function build(): void { - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec("make PREFIX='' clean") ->exec("make -j{$this->builder->concurrency} PREFIX=''") ->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); diff --git a/src/SPC/builder/unix/library/libtiff.php b/src/SPC/builder/unix/library/libtiff.php index 5561adcb..17862a79 100644 --- a/src/SPC/builder/unix/library/libtiff.php +++ b/src/SPC/builder/unix/library/libtiff.php @@ -22,7 +22,7 @@ trait libtiff // We disabled lzma, zstd, webp, libdeflate by default to reduce the size of the binary $extra_libs .= ' --disable-lzma --disable-zstd --disable-webp --disable-libdeflate'; - $shell = shell()->cd($this->source_dir)->initLibBuildEnv($this) + $shell = shell()->cd($this->source_dir)->initializeEnv($this) ->exec( './configure ' . '--enable-static --disable-shared ' . diff --git a/src/SPC/builder/unix/library/libxslt.php b/src/SPC/builder/unix/library/libxslt.php index f0d2592f..b241d715 100644 --- a/src/SPC/builder/unix/library/libxslt.php +++ b/src/SPC/builder/unix/library/libxslt.php @@ -24,7 +24,7 @@ trait libxslt $required_libs .= ' ' . $dep->getStaticLibFiles(); } } - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->appendEnv([ 'CFLAGS' => "-I{$this->getIncludeDir()}", 'LDFLAGS' => "-L{$this->getLibDir()}", diff --git a/src/SPC/builder/unix/library/ncurses.php b/src/SPC/builder/unix/library/ncurses.php index 42b4f2d3..7d33c76a 100644 --- a/src/SPC/builder/unix/library/ncurses.php +++ b/src/SPC/builder/unix/library/ncurses.php @@ -11,7 +11,7 @@ trait ncurses protected function build(): void { $filelist = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true); - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec( './configure ' . '--enable-static ' . diff --git a/src/SPC/builder/unix/library/nghttp2.php b/src/SPC/builder/unix/library/nghttp2.php index d8f4dc29..03c883bf 100644 --- a/src/SPC/builder/unix/library/nghttp2.php +++ b/src/SPC/builder/unix/library/nghttp2.php @@ -40,7 +40,7 @@ trait nghttp2 [,,$destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec( './configure ' . '--enable-static ' . diff --git a/src/SPC/builder/unix/library/nghttp3.php b/src/SPC/builder/unix/library/nghttp3.php index 4c1c8284..95cc22bf 100644 --- a/src/SPC/builder/unix/library/nghttp3.php +++ b/src/SPC/builder/unix/library/nghttp3.php @@ -15,7 +15,7 @@ trait nghttp3 */ protected function build(): void { - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec( './configure ' . '--enable-static ' . diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php index 66ba1306..97a0a8af 100644 --- a/src/SPC/builder/unix/library/ngtcp2.php +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -30,7 +30,7 @@ trait ngtcp2 $args .= ' --with-libbrotlienc=yes LIBBROTLIENC_CFLAGS="-I' . BUILD_ROOT_PATH . '/include" LIBBROTLIENC_LIBS="' . $brotli->getStaticLibFiles() . '"'; } - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec( './configure ' . '--enable-static ' . diff --git a/src/SPC/builder/unix/library/onig.php b/src/SPC/builder/unix/library/onig.php index 380e05b2..0ff844db 100644 --- a/src/SPC/builder/unix/library/onig.php +++ b/src/SPC/builder/unix/library/onig.php @@ -17,7 +17,7 @@ trait onig { [,,$destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec('./configure --enable-static --disable-shared --prefix=') ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") diff --git a/src/SPC/builder/unix/library/pkgconfig.php b/src/SPC/builder/unix/library/pkgconfig.php index 5fc89113..51fa586b 100644 --- a/src/SPC/builder/unix/library/pkgconfig.php +++ b/src/SPC/builder/unix/library/pkgconfig.php @@ -13,7 +13,7 @@ trait pkgconfig $cflags = PHP_OS_FAMILY !== 'Linux' ? "{$this->builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion" : ''; $ldflags = !($this instanceof LinuxLibraryBase) || getenv('SPC_LIBC') === 'glibc' ? '' : '--static'; - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->appendEnv(['CFLAGS' => $cflags, 'LDFLAGS' => $ldflags]) ->exec( './configure ' . diff --git a/src/SPC/builder/unix/library/readline.php b/src/SPC/builder/unix/library/readline.php index a7339d60..c0fe9078 100644 --- a/src/SPC/builder/unix/library/readline.php +++ b/src/SPC/builder/unix/library/readline.php @@ -15,7 +15,7 @@ trait readline */ protected function build(): void { - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec( './configure ' . '--enable-static=yes ' . diff --git a/src/SPC/builder/unix/library/sqlite.php b/src/SPC/builder/unix/library/sqlite.php index 42e23679..c6219171 100644 --- a/src/SPC/builder/unix/library/sqlite.php +++ b/src/SPC/builder/unix/library/sqlite.php @@ -8,7 +8,7 @@ trait sqlite { protected function build(): void { - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec('./configure --enable-static --disable-shared --prefix=') ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") diff --git a/src/SPC/builder/unix/library/zlib.php b/src/SPC/builder/unix/library/zlib.php index f2490a6c..8accaf66 100644 --- a/src/SPC/builder/unix/library/zlib.php +++ b/src/SPC/builder/unix/library/zlib.php @@ -17,7 +17,7 @@ trait zlib { [,,$destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir)->initLibBuildEnv($this) + shell()->cd($this->source_dir)->initializeEnv($this) ->exec('./configure --static --prefix=') ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") diff --git a/src/SPC/util/UnixShell.php b/src/SPC/util/UnixShell.php index 9dd779a7..957d66a6 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -64,7 +64,7 @@ class UnixShell * * @param BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library Library class */ - public function initLibBuildEnv(BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library): UnixShell + public function initializeEnv(BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library): UnixShell { $this->setEnv([ 'CFLAGS' => $library->getLibExtraCFlags(), diff --git a/src/SPC/util/executor/UnixCMakeExecutor.php b/src/SPC/util/executor/UnixCMakeExecutor.php index 9cb0d52d..ed9331e6 100644 --- a/src/SPC/util/executor/UnixCMakeExecutor.php +++ b/src/SPC/util/executor/UnixCMakeExecutor.php @@ -34,7 +34,7 @@ class UnixCMakeExecutor extends Executor } // prepare shell - $shell = shell()->cd($this->build_dir)->initLibBuildEnv($this->library); + $shell = shell()->cd($this->build_dir)->initializeEnv($this->library); // config $this->steps >= 1 && $shell->exec("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()} {$build_pos}"); From 1c1f7b19dd8ce933354e46084f80e23e2f94424a Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 11:13:54 +0800 Subject: [PATCH 17/24] Add XXX_CXXFLAGS for common build --- src/SPC/builder/traits/UnixLibraryTrait.php | 9 +++++++++ src/SPC/util/UnixShell.php | 1 + 2 files changed, 10 insertions(+) diff --git a/src/SPC/builder/traits/UnixLibraryTrait.php b/src/SPC/builder/traits/UnixLibraryTrait.php index 8e69f6d3..f302bbfa 100644 --- a/src/SPC/builder/traits/UnixLibraryTrait.php +++ b/src/SPC/builder/traits/UnixLibraryTrait.php @@ -118,4 +118,13 @@ trait UnixLibraryTrait { return getenv($this->getSnakeCaseName() . '_LIBS') ?: ''; } + + public function getLibExtraCXXFlags(): string + { + $env = getenv($this->getSnakeCaseName() . '_CXXFLAGS') ?: ''; + if (!str_contains($env, $this->builder->arch_cxx_flags)) { + $env .= $this->builder->arch_cxx_flags; + } + return $env; + } } diff --git a/src/SPC/util/UnixShell.php b/src/SPC/util/UnixShell.php index 957d66a6..be80cb4c 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -70,6 +70,7 @@ class UnixShell 'CFLAGS' => $library->getLibExtraCFlags(), 'LDFLAGS' => $library->getLibExtraLdFlags(), 'LIBS' => $library->getLibExtraLibs(), + 'CXXFLAGS' => $library->getLibExtraCXXFlags(), ]); return $this; } From 936c4d8696476f6463a19d6663d1daf74d5973e6 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 12:12:22 +0800 Subject: [PATCH 18/24] Change env string inject order --- src/SPC/util/UnixShell.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SPC/util/UnixShell.php b/src/SPC/util/UnixShell.php index be80cb4c..a53f423d 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -45,17 +45,17 @@ class UnixShell /* @phpstan-ignore-next-line */ logger()->info(ConsoleColor::yellow('[EXEC] ') . ConsoleColor::green($cmd)); logger()->debug('Executed at: ' . debug_backtrace()[0]['file'] . ':' . debug_backtrace()[0]['line']); + $env_str = $this->getEnvString(); + if (!empty($env_str)) { + $cmd = "{$env_str} {$cmd}"; + } if ($this->cd !== null) { $cmd = 'cd ' . escapeshellarg($this->cd) . ' && ' . $cmd; } if (!$this->debug) { $cmd .= ' 1>/dev/null 2>&1'; } - $env_str = $this->getEnvString(); - if (!empty($env_str)) { - $env_str = "{$env_str} "; - } - f_passthru("{$env_str}{$cmd}"); + f_passthru($cmd); return $this; } From 0ca71b62db421d2d12d891aa26ab4f4c80d5fa50 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 12:13:14 +0800 Subject: [PATCH 19/24] Fix gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 814b9020..8c6b75ac 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ docker/source/ /source/ # default source download directory -/downloads/ +/downloads/* # default source build root directory /buildroot/ From e6c9a82cd3978804557d8f4ec4fb0d085a02c04e Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 12:14:25 +0800 Subject: [PATCH 20/24] Fix gitignore --- .gitignore | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 8c6b75ac..7f5ea9b7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,22 +5,22 @@ docker/extensions/ docker/source/ # Vendor files -/vendor/ +/vendor/** # default source extract directory -/source/ +/source/** # default source download directory -/downloads/* +/downloads/** # default source build root directory -/buildroot/ +/buildroot/** # default package root directory -/pkgroot/ +/pkgroot/** # default pack:lib and release directory -/dist/ +/dist/** packlib_files.txt # tools cache files From f4e1d7d4c1a324f2b656104cd5faf1e5641564c0 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 12:37:50 +0800 Subject: [PATCH 21/24] Trigger tests --- src/globals/test-extensions.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index af59c409..43f41a8b 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -13,9 +13,9 @@ declare(strict_types=1); // test php version (8.1 ~ 8.4 available, multiple for matrix) $test_php_version = [ - // '8.1', - // '8.2', - // '8.3', + '8.1', + '8.2', + '8.3', '8.4', ]; @@ -45,19 +45,19 @@ $prefer_pre_built = false; // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'openssl,curl', + 'Linux', 'Darwin' => 'curl', 'Windows' => 'xlswriter,openssl', }; // If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`). $shared_extensions = match (PHP_OS_FAMILY) { - 'Linux' => 'xdebug', + 'Linux' => '', 'Windows', 'Darwin' => '', }; // If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`). $with_libs = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'nghttp2,nghttp3,ngtcp2', + 'Linux', 'Darwin' => 'brotli,curl,freetype,gmssl,libaom,libavif,libde265,libevent,libheif,libjpeg,librabbitmq,libssh2,libuuid,libuv,libwebp,libxml2,libyaml,libzip,mimalloc,snappy,tidy,zstd', 'Windows' => '', }; From bb37c0058e5665ab5521608ee2ba2ff77240cc28 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 12:49:33 +0800 Subject: [PATCH 22/24] Fix CMake related options --- src/SPC/builder/unix/library/curl.php | 2 +- src/SPC/builder/unix/library/libaom.php | 2 +- src/SPC/builder/unix/library/libevent.php | 1 - src/SPC/util/executor/UnixCMakeExecutor.php | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/SPC/builder/unix/library/curl.php b/src/SPC/builder/unix/library/curl.php index ea8b6320..0d0b8d8d 100644 --- a/src/SPC/builder/unix/library/curl.php +++ b/src/SPC/builder/unix/library/curl.php @@ -19,7 +19,7 @@ trait curl shell()->cd($this->source_dir)->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ./CMakeLists.txt'); 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('openssl', '-DCURL_USE_OPENSSL=ON -DCURL_CA_BUNDLE=OFF -DCURL_CA_PATH=OFF -DCURL_CA_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') diff --git a/src/SPC/builder/unix/library/libaom.php b/src/SPC/builder/unix/library/libaom.php index 57129389..ab5c22b8 100644 --- a/src/SPC/builder/unix/library/libaom.php +++ b/src/SPC/builder/unix/library/libaom.php @@ -18,7 +18,7 @@ trait libaom { UnixCMakeExecutor::create($this) ->setBuildDir("{$this->source_dir}/builddir") - ->addConfigureArgs('-DAOM_TARGET_GPU=generic') + ->addConfigureArgs('-DAOM_TARGET_CPU=generic') ->build(); $this->patchPkgconfPrefix(['aom.pc']); } diff --git a/src/SPC/builder/unix/library/libevent.php b/src/SPC/builder/unix/library/libevent.php index 04c35d18..da726935 100644 --- a/src/SPC/builder/unix/library/libevent.php +++ b/src/SPC/builder/unix/library/libevent.php @@ -45,7 +45,6 @@ trait libevent '-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', ) diff --git a/src/SPC/util/executor/UnixCMakeExecutor.php b/src/SPC/util/executor/UnixCMakeExecutor.php index 71319fa0..91d6e313 100644 --- a/src/SPC/util/executor/UnixCMakeExecutor.php +++ b/src/SPC/util/executor/UnixCMakeExecutor.php @@ -143,7 +143,7 @@ class UnixCMakeExecutor extends Executor "-DCMAKE_INSTALL_PREFIX={$this->library->getBuildRootPath()}", '-DCMAKE_INSTALL_BINDIR=bin', '-DCMAKE_INSTALL_LIBDIR=lib', - '-DCMAKE_INSTALL_INCLUDE_DIR=include', + '-DCMAKE_INSTALL_INCLUDEDIR=include', '-DBUILD_SHARED_LIBS=OFF', "-DCMAKE_TOOLCHAIN_FILE={$this->makeCmakeToolchainFile()}", ]); From 48df491c317d9b5cd0feb50b141082798120ad22 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 13:00:43 +0800 Subject: [PATCH 23/24] Fix brotli build on macOS --- src/SPC/builder/unix/library/brotli.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SPC/builder/unix/library/brotli.php b/src/SPC/builder/unix/library/brotli.php index 7f5f4dbb..34a10086 100644 --- a/src/SPC/builder/unix/library/brotli.php +++ b/src/SPC/builder/unix/library/brotli.php @@ -19,6 +19,7 @@ trait brotli { UnixCMakeExecutor::create($this) ->setBuildDir("{$this->getSourceDir()}/build-dir") + ->addConfigureArgs("-DSHARE_INSTALL_PREFIX={$this->getBuildRootPath()}") ->build(); $this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']); From 13540c8008758ce637fd32eed3da354ba9239c36 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 13:08:28 +0800 Subject: [PATCH 24/24] Remove shared tidy --- src/SPC/builder/unix/library/tidy.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/tidy.php b/src/SPC/builder/unix/library/tidy.php index 1d05a060..d842dc6d 100644 --- a/src/SPC/builder/unix/library/tidy.php +++ b/src/SPC/builder/unix/library/tidy.php @@ -18,7 +18,10 @@ trait tidy { UnixCMakeExecutor::create($this) ->setBuildDir("{$this->source_dir}/build-dir") - ->addConfigureArgs('-DSUPPORT_CONSOLE_APP=OFF') + ->addConfigureArgs( + '-DSUPPORT_CONSOLE_APP=OFF', + '-DBUILD_SHARED_LIB=OFF' + ) ->build(); $this->patchPkgconfPrefix(['tidy.pc']); }