mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-03 23:05:41 +08:00
Add libiconv,libssh2,libxml2,xz
This commit is contained in:
@@ -12,16 +12,17 @@ use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
|
||||
#[Library('libiconv')]
|
||||
class libiconv
|
||||
{
|
||||
#[BuildFor('Linux')]
|
||||
#[BuildFor('Darwin')]
|
||||
public function build(LibraryPackage $package): void
|
||||
public function build(LibraryPackage $lib): void
|
||||
{
|
||||
UnixAutoconfExecutor::create($package)
|
||||
UnixAutoconfExecutor::create($lib)
|
||||
->configure(
|
||||
'--enable-extra-encodings',
|
||||
'--enable-year2038',
|
||||
)
|
||||
->make('install-lib', with_install: false)
|
||||
->make('install-lib', with_install: false, dir: "{$package->getSourceDir()}/libcharset");
|
||||
$package->patchLaDependencyPrefix();
|
||||
->make('install-lib', with_install: false, dir: $lib->getSourceDir() . '/libcharset');
|
||||
$lib->patchLaDependencyPrefix();
|
||||
}
|
||||
}
|
||||
|
||||
29
src/Package/Library/libssh2.php
Normal file
29
src/Package/Library/libssh2.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Package\Library;
|
||||
|
||||
use StaticPHP\Attribute\Package\BuildFor;
|
||||
use StaticPHP\Attribute\Package\Library;
|
||||
use StaticPHP\Package\LibraryPackage;
|
||||
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
|
||||
|
||||
#[Library('libssh2')]
|
||||
class libssh2
|
||||
{
|
||||
#[BuildFor('Linux')]
|
||||
#[BuildFor('Darwin')]
|
||||
public function build(LibraryPackage $lib): void
|
||||
{
|
||||
UnixCMakeExecutor::create($lib)
|
||||
->optionalPackage('zlib', ...cmake_boolean_args('ENABLE_ZLIB_COMPRESSION'))
|
||||
->addConfigureArgs(
|
||||
'-DBUILD_EXAMPLES=OFF',
|
||||
'-DBUILD_TESTING=OFF'
|
||||
)
|
||||
->build();
|
||||
|
||||
$lib->patchPkgconfPrefix(['libssh2.pc']);
|
||||
}
|
||||
}
|
||||
@@ -8,47 +8,68 @@ use StaticPHP\Attribute\Package\BuildFor;
|
||||
use StaticPHP\Attribute\Package\Library;
|
||||
use StaticPHP\Package\LibraryPackage;
|
||||
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
|
||||
use StaticPHP\Runtime\SystemTarget;
|
||||
use StaticPHP\Util\FileSystem;
|
||||
|
||||
#[Library('libxml2')]
|
||||
class libxml2
|
||||
{
|
||||
#[BuildFor('Darwin')]
|
||||
public function build(LibraryPackage $package): void
|
||||
#[BuildFor('Linux')]
|
||||
public function buildForLinux(LibraryPackage $lib): void
|
||||
{
|
||||
$cmake = UnixCMakeExecutor::create($package)
|
||||
UnixCMakeExecutor::create($lib)
|
||||
->optionalPackage(
|
||||
'zlib',
|
||||
'-DLIBXML2_WITH_ZLIB=ON ' .
|
||||
"-DZLIB_LIBRARY={$package->getLibDir()}/libz.a " .
|
||||
"-DZLIB_INCLUDE_DIR={$package->getIncludeDir()}",
|
||||
"-DZLIB_LIBRARY={$lib->getLibDir()}/libz.a " .
|
||||
"-DZLIB_INCLUDE_DIR={$lib->getIncludeDir()}",
|
||||
'-DLIBXML2_WITH_ZLIB=OFF',
|
||||
)
|
||||
->optionalPackage('xz', ...cmake_boolean_args('LIBXML2_WITH_LZMA'))
|
||||
->addConfigureArgs(
|
||||
'-DLIBXML2_WITH_ICONV=ON',
|
||||
'-DIconv_IS_BUILT_IN=OFF',
|
||||
'-DLIBXML2_WITH_ICU=OFF', // optional, but discouraged: https://gitlab.gnome.org/GNOME/libxml2/-/blob/master/README.md
|
||||
'-DLIBXML2_WITH_PYTHON=OFF',
|
||||
'-DLIBXML2_WITH_PROGRAMS=OFF',
|
||||
'-DLIBXML2_WITH_TESTS=OFF',
|
||||
);
|
||||
)
|
||||
->build();
|
||||
|
||||
if (SystemTarget::getTargetOS() === 'Linux') {
|
||||
$cmake->addConfigureArgs('-DIconv_IS_BUILT_IN=OFF');
|
||||
}
|
||||
$this->patchPkgConfig($lib);
|
||||
}
|
||||
|
||||
$cmake->build();
|
||||
#[BuildFor('Darwin')]
|
||||
public function buildForDarwin(LibraryPackage $lib): void
|
||||
{
|
||||
UnixCMakeExecutor::create($lib)
|
||||
->optionalPackage(
|
||||
'zlib',
|
||||
'-DLIBXML2_WITH_ZLIB=ON ' .
|
||||
"-DZLIB_LIBRARY={$lib->getLibDir()}/libz.a " .
|
||||
"-DZLIB_INCLUDE_DIR={$lib->getIncludeDir()}",
|
||||
'-DLIBXML2_WITH_ZLIB=OFF',
|
||||
)
|
||||
->optionalPackage('xz', ...cmake_boolean_args('LIBXML2_WITH_LZMA'))
|
||||
->addConfigureArgs(
|
||||
'-DLIBXML2_WITH_ICONV=ON',
|
||||
'-DLIBXML2_WITH_ICU=OFF',
|
||||
'-DLIBXML2_WITH_PYTHON=OFF',
|
||||
'-DLIBXML2_WITH_PROGRAMS=OFF',
|
||||
'-DLIBXML2_WITH_TESTS=OFF',
|
||||
)
|
||||
->build();
|
||||
|
||||
FileSystem::replaceFileStr(
|
||||
BUILD_LIB_PATH . '/pkgconfig/libxml-2.0.pc',
|
||||
'-lxml2 -liconv',
|
||||
'-lxml2'
|
||||
);
|
||||
FileSystem::replaceFileStr(
|
||||
BUILD_LIB_PATH . '/pkgconfig/libxml-2.0.pc',
|
||||
'-lxml2',
|
||||
'-lxml2 -liconv'
|
||||
);
|
||||
$this->patchPkgConfig($lib);
|
||||
}
|
||||
|
||||
private function patchPkgConfig(LibraryPackage $lib): void
|
||||
{
|
||||
$pcFile = "{$lib->getLibDir()}/pkgconfig/libxml-2.0.pc";
|
||||
|
||||
// Remove -liconv from original
|
||||
FileSystem::replaceFileStr($pcFile, '-lxml2 -liconv', '-lxml2');
|
||||
|
||||
// Add -liconv after -lxml2
|
||||
FileSystem::replaceFileStr($pcFile, '-lxml2', '-lxml2 -liconv');
|
||||
}
|
||||
}
|
||||
|
||||
30
src/Package/Library/xz.php
Normal file
30
src/Package/Library/xz.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Package\Library;
|
||||
|
||||
use StaticPHP\Attribute\Package\BuildFor;
|
||||
use StaticPHP\Attribute\Package\Library;
|
||||
use StaticPHP\Package\LibraryPackage;
|
||||
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
|
||||
|
||||
#[Library('xz')]
|
||||
class xz
|
||||
{
|
||||
#[BuildFor('Linux')]
|
||||
#[BuildFor('Darwin')]
|
||||
public function build(LibraryPackage $lib): void
|
||||
{
|
||||
UnixAutoconfExecutor::create($lib)
|
||||
->configure(
|
||||
'--disable-scripts',
|
||||
'--disable-doc',
|
||||
'--with-libiconv',
|
||||
'--bindir=/tmp/xz', // xz binary will corrupt `tar` command, that's really strange.
|
||||
)
|
||||
->make();
|
||||
$lib->patchPkgconfPrefix(['liblzma.pc']);
|
||||
$lib->patchLaDependencyPrefix();
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,10 @@ namespace StaticPHP\Command;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
#[AsCommand('build:libs')]
|
||||
#[AsCommand('build:libs', 'Build specified library packages')]
|
||||
class BuildLibsCommand extends BaseCommand
|
||||
{
|
||||
public function configure()
|
||||
public function configure(): void
|
||||
{
|
||||
$this->addArgument('libraries', InputArgument::REQUIRED, 'The library packages will be compiled, comma separated');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user