From 7fb841721680e0b766f23b1291daf9ec2360a681 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 9 Jul 2024 15:05:53 +0800 Subject: [PATCH] Provide libevent, libiconv-win, libsodium, libwebp, libyaml, ncurses, readline, unixodbc, xz pre-built libs --- config/source.json | 9 +++++ src/SPC/builder/unix/library/libevent.php | 44 +++++++++++++++++++++ src/SPC/builder/unix/library/libsodium.php | 7 ++-- src/SPC/builder/unix/library/ncurses.php | 20 ++++++++++ src/SPC/builder/windows/library/libwebp.php | 7 ++++ 5 files changed, 84 insertions(+), 3 deletions(-) diff --git a/config/source.json b/config/source.json index efd8568d..6f7e1cb3 100644 --- a/config/source.json +++ b/config/source.json @@ -291,6 +291,7 @@ "repo": "libevent/libevent", "match": "libevent.+\\.tar\\.gz", "prefer-stable": true, + "provide-pre-built": true, "license": { "type": "file", "path": "LICENSE" @@ -329,6 +330,7 @@ "type": "git", "rev": "master", "url": "https://github.com/static-php/libiconv-win.git", + "provide-pre-built": true, "license": { "type": "file", "path": "source/COPYING" @@ -386,6 +388,7 @@ "repo": "jedisct1/libsodium", "match": "libsodium-\\d+(\\.\\d+)*\\.tar\\.gz", "prefer-stable": true, + "provide-pre-built": true, "license": { "type": "file", "path": "LICENSE" @@ -437,6 +440,7 @@ "libwebp": { "type": "url", "url": "https://github.com/webmproject/libwebp/archive/refs/tags/v1.3.2.tar.gz", + "provide-pre-built": true, "license": { "type": "file", "path": "COPYING" @@ -464,6 +468,7 @@ "repo": "yaml/libyaml", "match": "yaml-.+\\.tar\\.gz", "prefer-stable": true, + "provide-pre-built": true, "license": { "type": "file", "path": "License" @@ -514,6 +519,7 @@ "type": "filelist", "url": "https://ftp.gnu.org/pub/gnu/ncurses/", "regex": "/href=\"(?ncurses-(?[^\"]+)\\.tar\\.gz)\"/", + "provide-pre-built": true, "license": { "type": "file", "path": "COPYING" @@ -629,6 +635,7 @@ "type": "filelist", "url": "https://ftp.gnu.org/pub/gnu/readline/", "regex": "/href=\"(?readline-(?[^\"]+)\\.tar\\.gz)\"/", + "provide-pre-built": true, "license": { "type": "file", "path": "COPYING" @@ -716,6 +723,7 @@ "unixodbc": { "type": "url", "url": "https://www.unixodbc.org/unixODBC-2.3.12.tar.gz", + "provide-pre-built": true, "license": { "type": "file", "path": "COPYING" @@ -746,6 +754,7 @@ "repo": "tukaani-project/xz", "match": "xz.+\\.tar\\.xz", "prefer-stable": true, + "provide-pre-built": true, "license": { "type": "file", "path": "COPYING" diff --git a/src/SPC/builder/unix/library/libevent.php b/src/SPC/builder/unix/library/libevent.php index b3114156..2e80f32e 100644 --- a/src/SPC/builder/unix/library/libevent.php +++ b/src/SPC/builder/unix/library/libevent.php @@ -10,12 +10,36 @@ use SPC\store\FileSystem; trait libevent { + public function beforePack(): void + { + if (file_exists(BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake')) { + FileSystem::replaceFileRegex( + BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake', + '/set\(_IMPORT_PREFIX .*\)/m', + 'set(_IMPORT_PREFIX "{BUILD_ROOT_PATH}")' + ); + + FileSystem::replaceFileRegex( + BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake', + '/INTERFACE_INCLUDE_DIRECTORIES ".*"/m', + 'INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"' + ); + + FileSystem::replaceFileRegex( + BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake', + '/INTERFACE_LINK_LIBRARIES "libevent::core;.*"/m', + 'INTERFACE_LINK_LIBRARIES "libevent::core;${_IMPORT_PREFIX}/lib/libssl.a;${_IMPORT_PREFIX}/lib/libcrypto.a"' + ); + } + } + /** * @throws RuntimeException * @throws FileSystemException */ protected function build(): void { + [$lib, $include, $destdir] = SEPARATED_PATH; // CMake needs a clean build directory FileSystem::resetDir($this->source_dir . '/build'); // Start build @@ -36,5 +60,25 @@ trait libevent ) ->execWithEnv("cmake --build . -j {$this->builder->concurrency}") ->exec('make install'); + + $this->patchPkgconfPrefix(['libevent.pc', 'libevent_core.pc', 'libevent_extra.pc', 'libevent_openssl.pc']); + + $this->patchPkgconfPrefix( + ['libevent_openssl.pc'], + PKGCONF_PATCH_CUSTOM, + [ + '/Libs.private:.*/m', + 'Libs.private: -lssl -lcrypto', + ] + ); + } + + protected function install(): void + { + FileSystem::replaceFileStr( + BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake', + '{BUILD_ROOT_PATH}', + BUILD_ROOT_PATH + ); } } diff --git a/src/SPC/builder/unix/library/libsodium.php b/src/SPC/builder/unix/library/libsodium.php index 555b48d6..b24d52b7 100644 --- a/src/SPC/builder/unix/library/libsodium.php +++ b/src/SPC/builder/unix/library/libsodium.php @@ -8,11 +8,12 @@ trait libsodium { protected function build(): void { - $root = BUILD_ROOT_PATH; shell()->cd($this->source_dir) - ->exec("./configure --enable-static --disable-shared --prefix={$root}") + ->exec('./configure --enable-static --disable-shared --prefix=') ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") - ->exec('make install'); + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + + $this->patchPkgconfPrefix(['libsodium.pc'], PKGCONF_PATCH_PREFIX); } } diff --git a/src/SPC/builder/unix/library/ncurses.php b/src/SPC/builder/unix/library/ncurses.php index 29a80885..721d5de6 100644 --- a/src/SPC/builder/unix/library/ncurses.php +++ b/src/SPC/builder/unix/library/ncurses.php @@ -4,10 +4,13 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\store\FileSystem; + trait ncurses { protected function build(): void { + $filelist = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true); shell()->cd($this->source_dir) ->exec( './configure ' . @@ -32,5 +35,22 @@ trait ncurses ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") ->exec('make install'); + + $final = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true); + // Remove the new files + $new_files = array_diff($final, $filelist); + foreach ($new_files as $file) { + @unlink(BUILD_BIN_PATH . '/' . $file); + } + + shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf share/terminfo'); + shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf lib/terminfo'); + + $pkgconf_list = ['form.pc', 'menu.pc', 'ncurses++.pc', 'ncurses.pc', 'panel.pc', 'tic.pc']; + $this->patchPkgconfPrefix($pkgconf_list); + + foreach ($pkgconf_list as $pkgconf) { + FileSystem::replaceFileStr(BUILD_LIB_PATH . '/pkgconfig/' . $pkgconf, '-L' . BUILD_LIB_PATH, '-L${libdir}'); + } } } diff --git a/src/SPC/builder/windows/library/libwebp.php b/src/SPC/builder/windows/library/libwebp.php index c09b76d6..96813e68 100644 --- a/src/SPC/builder/windows/library/libwebp.php +++ b/src/SPC/builder/windows/library/libwebp.php @@ -41,5 +41,12 @@ class libwebp extends WindowsLibraryBase $this->builder->makeSimpleWrapper('cmake'), "--build build --config Release --target install -j{$this->builder->concurrency}" ); + + // Actually we don't need pkgconf in windows, but for packing, we still need patching prefix. + // for libsharpyuv, libwebp, libwebpdecoder, libwebpdemux + FileSystem::replaceFileRegex(BUILD_LIB_PATH . '\pkgconfig\libsharpyuv.pc', '/^prefix=.*/m', 'prefix=${pcfiledir}/../..'); + FileSystem::replaceFileRegex(BUILD_LIB_PATH . '\pkgconfig\libwebp.pc', '/^prefix=.*/m', 'prefix=${pcfiledir}/../..'); + FileSystem::replaceFileRegex(BUILD_LIB_PATH . '\pkgconfig\libwebpdecoder.pc', '/^prefix=.*/m', 'prefix=${pcfiledir}/../..'); + FileSystem::replaceFileRegex(BUILD_LIB_PATH . '\pkgconfig\libwebpdemux.pc', '/^prefix=.*/m', 'prefix=${pcfiledir}/../..'); } }