mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 12:54:52 +08:00
Add multiple XML related extensions support for Windows (#349)
* update libxml2 version * use msys2 tar.exe instead of system32/tar.exe * add iconv, xml, dom, xmlreader, xmlwriter, soap, libxml, simplexml support * add test * add sysvshm support * add quote * add debug * use mingw target * fix windows tar * fix windows tar * fix windows tar * fix windows tar * fix windows tar [skip ci]
This commit is contained in:
parent
3945ac037b
commit
f498250001
@ -123,8 +123,12 @@
|
|||||||
"iconv": {
|
"iconv": {
|
||||||
"type": "builtin",
|
"type": "builtin",
|
||||||
"arg-type": "with-prefix",
|
"arg-type": "with-prefix",
|
||||||
"lib-depends": [
|
"arg-type-windows": "with",
|
||||||
|
"lib-depends-unix": [
|
||||||
"libiconv"
|
"libiconv"
|
||||||
|
],
|
||||||
|
"lib-depends-windows": [
|
||||||
|
"libiconv-win"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"igbinary": {
|
"igbinary": {
|
||||||
@ -351,9 +355,11 @@
|
|||||||
"simplexml": {
|
"simplexml": {
|
||||||
"type": "builtin",
|
"type": "builtin",
|
||||||
"arg-type": "custom",
|
"arg-type": "custom",
|
||||||
"arg-type-windows": "with",
|
|
||||||
"lib-depends": [
|
"lib-depends": [
|
||||||
"libxml2"
|
"libxml2"
|
||||||
|
],
|
||||||
|
"ext-depends-windows": [
|
||||||
|
"xml"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"snappy": {
|
"snappy": {
|
||||||
@ -373,6 +379,9 @@
|
|||||||
"arg-type": "custom",
|
"arg-type": "custom",
|
||||||
"lib-depends": [
|
"lib-depends": [
|
||||||
"libxml2"
|
"libxml2"
|
||||||
|
],
|
||||||
|
"ext-depends-windows": [
|
||||||
|
"xml"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"sockets": {
|
"sockets": {
|
||||||
@ -488,8 +497,7 @@
|
|||||||
"unix-only": true
|
"unix-only": true
|
||||||
},
|
},
|
||||||
"sysvshm": {
|
"sysvshm": {
|
||||||
"type": "builtin",
|
"type": "builtin"
|
||||||
"unix-only": true
|
|
||||||
},
|
},
|
||||||
"tidy": {
|
"tidy": {
|
||||||
"type": "builtin",
|
"type": "builtin",
|
||||||
@ -534,6 +542,9 @@
|
|||||||
"arg-type-windows": "with",
|
"arg-type-windows": "with",
|
||||||
"lib-depends": [
|
"lib-depends": [
|
||||||
"libxml2"
|
"libxml2"
|
||||||
|
],
|
||||||
|
"ext-depends-windows": [
|
||||||
|
"iconv"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"xmlreader": {
|
"xmlreader": {
|
||||||
@ -541,6 +552,10 @@
|
|||||||
"arg-type": "custom",
|
"arg-type": "custom",
|
||||||
"lib-depends": [
|
"lib-depends": [
|
||||||
"libxml2"
|
"libxml2"
|
||||||
|
],
|
||||||
|
"ext-depends-windows": [
|
||||||
|
"xml",
|
||||||
|
"dom"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"xmlwriter": {
|
"xmlwriter": {
|
||||||
@ -548,6 +563,9 @@
|
|||||||
"arg-type": "custom",
|
"arg-type": "custom",
|
||||||
"lib-depends": [
|
"lib-depends": [
|
||||||
"libxml2"
|
"libxml2"
|
||||||
|
],
|
||||||
|
"ext-depends-windows": [
|
||||||
|
"xml"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"xsl": {
|
"xsl": {
|
||||||
|
|||||||
@ -245,6 +245,13 @@
|
|||||||
"localcharset.h"
|
"localcharset.h"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"libiconv-win": {
|
||||||
|
"source": "libiconv-win",
|
||||||
|
"static-libs-windows": [
|
||||||
|
"libiconv.lib",
|
||||||
|
"libiconv_a.lib"
|
||||||
|
]
|
||||||
|
},
|
||||||
"libjpeg": {
|
"libjpeg": {
|
||||||
"source": "libjpeg",
|
"source": "libjpeg",
|
||||||
"static-libs-unix": [
|
"static-libs-unix": [
|
||||||
@ -334,21 +341,25 @@
|
|||||||
"libxml2.a"
|
"libxml2.a"
|
||||||
],
|
],
|
||||||
"static-libs-windows": [
|
"static-libs-windows": [
|
||||||
[
|
"libxml2s.lib",
|
||||||
"libxml2s.lib",
|
"libxml2_a.lib"
|
||||||
"libxml2_a.lib"
|
|
||||||
]
|
|
||||||
],
|
],
|
||||||
"headers": [
|
"headers": [
|
||||||
"libxml2"
|
"libxml2"
|
||||||
],
|
],
|
||||||
"lib-depends": [
|
"lib-depends-unix": [
|
||||||
"libiconv"
|
"libiconv"
|
||||||
],
|
],
|
||||||
"lib-suggests": [
|
"lib-suggests-unix": [
|
||||||
"xz",
|
"xz",
|
||||||
"icu",
|
"icu",
|
||||||
"zlib"
|
"zlib"
|
||||||
|
],
|
||||||
|
"lib-depends-windows": [
|
||||||
|
"libiconv-win"
|
||||||
|
],
|
||||||
|
"lib-suggests-windows": [
|
||||||
|
"zlib"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"libxslt": {
|
"libxslt": {
|
||||||
|
|||||||
@ -254,6 +254,15 @@
|
|||||||
"path": "COPYING"
|
"path": "COPYING"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"libiconv-win": {
|
||||||
|
"type": "git",
|
||||||
|
"rev": "master",
|
||||||
|
"url": "https://github.com/static-php/libiconv-win.git",
|
||||||
|
"license": {
|
||||||
|
"type": "file",
|
||||||
|
"path": "source/COPYING"
|
||||||
|
}
|
||||||
|
},
|
||||||
"libjpeg": {
|
"libjpeg": {
|
||||||
"type": "ghtar",
|
"type": "ghtar",
|
||||||
"repo": "libjpeg-turbo/libjpeg-turbo",
|
"repo": "libjpeg-turbo/libjpeg-turbo",
|
||||||
@ -331,7 +340,7 @@
|
|||||||
},
|
},
|
||||||
"libxml2": {
|
"libxml2": {
|
||||||
"type": "url",
|
"type": "url",
|
||||||
"url": "https://github.com/GNOME/libxml2/archive/refs/tags/v2.9.14.tar.gz",
|
"url": "https://github.com/GNOME/libxml2/archive/refs/tags/v2.12.5.tar.gz",
|
||||||
"license": {
|
"license": {
|
||||||
"type": "file",
|
"type": "file",
|
||||||
"path": "Copyright"
|
"path": "Copyright"
|
||||||
|
|||||||
@ -212,7 +212,7 @@ class Extension
|
|||||||
// Trim additional content & escape special characters to allow inline usage
|
// Trim additional content & escape special characters to allow inline usage
|
||||||
$test = str_replace(
|
$test = str_replace(
|
||||||
['<?php', 'declare(strict_types=1);', "\n", '"', '$'],
|
['<?php', 'declare(strict_types=1);', "\n", '"', '$'],
|
||||||
['', '', '', '\"', '\$'],
|
['', '', '', '\"', '$'],
|
||||||
file_get_contents(FileSystem::convertPath(ROOT_DIR . '/src/globals/tests/' . $this->getName() . '.php'))
|
file_get_contents(FileSystem::convertPath(ROOT_DIR . '/src/globals/tests/' . $this->getName() . '.php'))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ namespace SPC\builder\extension;
|
|||||||
|
|
||||||
use SPC\builder\Extension;
|
use SPC\builder\Extension;
|
||||||
use SPC\exception\RuntimeException;
|
use SPC\exception\RuntimeException;
|
||||||
|
use SPC\store\FileSystem;
|
||||||
use SPC\util\CustomExt;
|
use SPC\util\CustomExt;
|
||||||
|
|
||||||
#[CustomExt('xml')]
|
#[CustomExt('xml')]
|
||||||
@ -33,4 +34,25 @@ class xml extends Extension
|
|||||||
$arg .= ' --with-libxml="' . BUILD_ROOT_PATH . '"';
|
$arg .= ' --with-libxml="' . BUILD_ROOT_PATH . '"';
|
||||||
return $arg;
|
return $arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function patchBeforeBuildconf(): bool
|
||||||
|
{
|
||||||
|
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/win32/build/config.w32', 'dllmain.c ', '');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWindowsConfigureArg(): string
|
||||||
|
{
|
||||||
|
$arg = match ($this->name) {
|
||||||
|
'xml' => '--with-xml',
|
||||||
|
'soap' => '--enable-soap',
|
||||||
|
'xmlreader' => '--enable-xmlreader',
|
||||||
|
'xmlwriter' => '--enable-xmlwriter',
|
||||||
|
'dom' => '--with-dom',
|
||||||
|
'simplexml' => '--with-simplexml',
|
||||||
|
default => throw new RuntimeException('Not accept non-xml extension'),
|
||||||
|
};
|
||||||
|
$arg .= ' --with-libxml';
|
||||||
|
return $arg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
35
src/SPC/builder/windows/library/libiconv_win.php
Normal file
35
src/SPC/builder/windows/library/libiconv_win.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SPC\builder\windows\library;
|
||||||
|
|
||||||
|
use SPC\builder\windows\SystemUtil;
|
||||||
|
use SPC\exception\RuntimeException;
|
||||||
|
use SPC\store\FileSystem;
|
||||||
|
|
||||||
|
class libiconv_win extends WindowsLibraryBase
|
||||||
|
{
|
||||||
|
public const NAME = 'libiconv-win';
|
||||||
|
|
||||||
|
protected function build()
|
||||||
|
{
|
||||||
|
$vs_ver_dir = match (SystemUtil::findVisualStudio()['version']) {
|
||||||
|
'vs17' => '/MSVC17',
|
||||||
|
'vs16' => '/MSVC16',
|
||||||
|
default => throw new RuntimeException('Current VS version is not supported yet!'),
|
||||||
|
};
|
||||||
|
|
||||||
|
// start build
|
||||||
|
cmd()->cd($this->source_dir . $vs_ver_dir)
|
||||||
|
->execWithWrapper(
|
||||||
|
$this->builder->makeSimpleWrapper('msbuild'),
|
||||||
|
'libiconv.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64'
|
||||||
|
);
|
||||||
|
FileSystem::createDir(BUILD_LIB_PATH);
|
||||||
|
FileSystem::createDir(BUILD_INCLUDE_PATH);
|
||||||
|
copy($this->source_dir . $vs_ver_dir . '\x64\lib\libiconv.lib', BUILD_LIB_PATH . '\libiconv.lib');
|
||||||
|
copy($this->source_dir . $vs_ver_dir . '\x64\lib\libiconv_a.lib', BUILD_LIB_PATH . '\libiconv_a.lib');
|
||||||
|
copy($this->source_dir . '\source\include\iconv.h', BUILD_INCLUDE_PATH . '\iconv.h');
|
||||||
|
}
|
||||||
|
}
|
||||||
44
src/SPC/builder/windows/library/libxml2.php
Normal file
44
src/SPC/builder/windows/library/libxml2.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SPC\builder\windows\library;
|
||||||
|
|
||||||
|
use SPC\store\FileSystem;
|
||||||
|
|
||||||
|
class libxml2 extends WindowsLibraryBase
|
||||||
|
{
|
||||||
|
public const NAME = 'libxml2';
|
||||||
|
|
||||||
|
protected function build(): void
|
||||||
|
{
|
||||||
|
$zlib = $this->builder->getLib('zlib') ? 'ON' : 'OFF';
|
||||||
|
// reset cmake
|
||||||
|
FileSystem::resetDir($this->source_dir . '\build');
|
||||||
|
|
||||||
|
// start build
|
||||||
|
cmd()->cd($this->source_dir)
|
||||||
|
->execWithWrapper(
|
||||||
|
$this->builder->makeSimpleWrapper('cmake'),
|
||||||
|
'-B build ' .
|
||||||
|
'-A x64 ' .
|
||||||
|
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
||||||
|
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||||
|
'-DBUILD_STATIC_LIBS=ON ' .
|
||||||
|
"-DLIBXML2_WITH_ZLIB={$zlib} " .
|
||||||
|
'-DLIBXML2_WITH_PYTHON=OFF ' .
|
||||||
|
'-DLIBXML2_WITH_ICONV=ON ' .
|
||||||
|
'-DIconv_LIBRARY=' . BUILD_LIB_PATH . ' ' .
|
||||||
|
'-DIconv_INCLUDE_DIR=' . BUILD_INCLUDE_PATH . ' ' .
|
||||||
|
'-DLIBXML2_WITH_LZMA=OFF ' . // xz not supported yet
|
||||||
|
'-DLIBXML2_WITH_PROGRAMS=OFF ' .
|
||||||
|
'-DLIBXML2_WITH_TESTS=OFF ' .
|
||||||
|
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
|
||||||
|
)
|
||||||
|
->execWithWrapper(
|
||||||
|
$this->builder->makeSimpleWrapper('cmake'),
|
||||||
|
"--build build --config Release --target install -j{$this->builder->concurrency}"
|
||||||
|
);
|
||||||
|
copy(BUILD_LIB_PATH . '\libxml2s.lib', BUILD_LIB_PATH . '\libxml2_a.lib');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -219,6 +219,14 @@ class FileSystem
|
|||||||
return str_replace('/', DIRECTORY_SEPARATOR, $path);
|
return str_replace('/', DIRECTORY_SEPARATOR, $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function convertWinPathToMinGW(string $path): string
|
||||||
|
{
|
||||||
|
if (preg_match('/^[A-Za-z]:/', $path)) {
|
||||||
|
$path = '/' . strtolower(substr($path, 0, 1)) . '/' . str_replace('\\', '/', substr($path, 2));
|
||||||
|
}
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 递归或非递归扫描目录,可返回相对目录的文件列表或绝对目录的文件列表
|
* 递归或非递归扫描目录,可返回相对目录的文件列表或绝对目录的文件列表
|
||||||
*
|
*
|
||||||
@ -443,6 +451,9 @@ class FileSystem
|
|||||||
if (f_mkdir(directory: $target, recursive: true) !== true) {
|
if (f_mkdir(directory: $target, recursive: true) !== true) {
|
||||||
throw new FileSystemException('create ' . $target . ' dir failed');
|
throw new FileSystemException('create ' . $target . ' dir failed');
|
||||||
}
|
}
|
||||||
|
if (!file_exists($filename)) {
|
||||||
|
throw new FileSystemException('File not exists');
|
||||||
|
}
|
||||||
|
|
||||||
if (in_array(PHP_OS_FAMILY, ['Darwin', 'Linux', 'BSD'])) {
|
if (in_array(PHP_OS_FAMILY, ['Darwin', 'Linux', 'BSD'])) {
|
||||||
match (self::extname($filename)) {
|
match (self::extname($filename)) {
|
||||||
@ -455,9 +466,15 @@ class FileSystem
|
|||||||
} elseif (PHP_OS_FAMILY === 'Windows') {
|
} elseif (PHP_OS_FAMILY === 'Windows') {
|
||||||
// use php-sdk-binary-tools/bin/7za.exe
|
// use php-sdk-binary-tools/bin/7za.exe
|
||||||
$_7z = self::convertPath(PHP_SDK_PATH . '/bin/7za.exe');
|
$_7z = self::convertPath(PHP_SDK_PATH . '/bin/7za.exe');
|
||||||
|
|
||||||
|
// Windows notes: I hate windows tar.......
|
||||||
|
// When extracting .tar.gz like libxml2, it shows a symlink error and returns code[1].
|
||||||
|
// Related posts: https://answers.microsoft.com/en-us/windows/forum/all/tar-on-windows-fails-to-extract-archive-containing/0ee9a7ea-9b1f-4fef-86a9-5d9dc35cea2f
|
||||||
|
// And MinGW tar.exe cannot work on temporarily storage ??? (GitHub Actions hosted runner)
|
||||||
|
// Yeah, I will be an MS HATER !
|
||||||
match (self::extname($filename)) {
|
match (self::extname($filename)) {
|
||||||
'tar' => f_passthru("tar -xf {$filename} -C {$target} --strip-components 1"),
|
'tar' => f_passthru("tar -xf {$filename} -C {$target} --strip-components 1"),
|
||||||
'xz', 'txz', 'gz', 'tgz', 'bz2' => f_passthru("\"{$_7z}\" x -so {$filename} | tar -f - -x -C {$target} --strip-components 1"),
|
'xz', 'txz', 'gz', 'tgz', 'bz2' => cmd()->execWithResult("\"{$_7z}\" x -so {$filename} | tar -f - -x -C \"{$target}\" --strip-components 1"),
|
||||||
'zip' => f_passthru("\"{$_7z}\" x {$filename} -o{$target} -y"),
|
'zip' => f_passthru("\"{$_7z}\" x {$filename} -o{$target} -y"),
|
||||||
default => throw new FileSystemException("unknown archive format: {$filename}"),
|
default => throw new FileSystemException("unknown archive format: {$filename}"),
|
||||||
};
|
};
|
||||||
|
|||||||
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||||||
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
|
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
|
||||||
$extensions = match (PHP_OS_FAMILY) {
|
$extensions = match (PHP_OS_FAMILY) {
|
||||||
'Linux', 'Darwin' => 'event,gettext',
|
'Linux', 'Darwin' => 'event,gettext',
|
||||||
'Windows' => 'mbstring,curl,ssh2',
|
'Windows' => 'mbstring,iconv,dom,xml,xmlwriter,xmlreader,soap,simplexml',
|
||||||
};
|
};
|
||||||
|
|
||||||
// If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).
|
// If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user