mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 12:54:52 +08:00
Fix windows xlswriter duplicate md5 symbol bug (#719)
* Add missing SOURCE_PATH before making cmake toolchain * Fix windows xlswriter duplicate md5 symbol bug * Add detection for patchFile to prevent duplicate patches * Add tests
This commit is contained in:
parent
f755d66342
commit
e7d6f37e98
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace SPC\builder\extension;
|
namespace SPC\builder\extension;
|
||||||
|
|
||||||
use SPC\builder\Extension;
|
use SPC\builder\Extension;
|
||||||
|
use SPC\store\SourcePatcher;
|
||||||
use SPC\util\CustomExt;
|
use SPC\util\CustomExt;
|
||||||
|
|
||||||
#[CustomExt('xlswriter')]
|
#[CustomExt('xlswriter')]
|
||||||
@ -27,14 +28,15 @@ class xlswriter extends Extension
|
|||||||
public function patchBeforeMake(): bool
|
public function patchBeforeMake(): bool
|
||||||
{
|
{
|
||||||
if (PHP_OS_FAMILY === 'Windows') {
|
if (PHP_OS_FAMILY === 'Windows') {
|
||||||
|
// fix windows build with openssl extension duplicate symbol bug
|
||||||
|
SourcePatcher::patchFile('spc_fix_xlswriter_win32.patch', $this->source_dir);
|
||||||
$content = file_get_contents($this->source_dir . '/library/libxlsxwriter/src/theme.c');
|
$content = file_get_contents($this->source_dir . '/library/libxlsxwriter/src/theme.c');
|
||||||
$bom = pack('CCC', 0xEF, 0xBB, 0xBF);
|
$bom = pack('CCC', 0xEF, 0xBB, 0xBF);
|
||||||
if (substr($content, 0, 3) !== $bom) {
|
if (substr($content, 0, 3) !== $bom) {
|
||||||
file_put_contents($this->source_dir . '/library/libxlsxwriter/src/theme.c', $content);
|
file_put_contents($this->source_dir . '/library/libxlsxwriter/src/theme.c', $bom . $content);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -99,6 +99,9 @@ SET(CMAKE_EXE_LINKER_FLAGS "{$ldflags}")
|
|||||||
SET(CMAKE_FIND_ROOT_PATH "{$buildroot}")
|
SET(CMAKE_FIND_ROOT_PATH "{$buildroot}")
|
||||||
SET(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
|
SET(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
|
||||||
CMAKE;
|
CMAKE;
|
||||||
|
if (!is_dir(SOURCE_PATH)) {
|
||||||
|
FileSystem::createDir(SOURCE_PATH);
|
||||||
|
}
|
||||||
FileSystem::writeFile(SOURCE_PATH . '\toolchain.cmake', $toolchain);
|
FileSystem::writeFile(SOURCE_PATH . '\toolchain.cmake', $toolchain);
|
||||||
return realpath(SOURCE_PATH . '\toolchain.cmake');
|
return realpath(SOURCE_PATH . '\toolchain.cmake');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -181,16 +181,30 @@ class SourcePatcher
|
|||||||
$patch_file = ROOT_DIR . "/src/globals/patch/{$patch_name}";
|
$patch_file = ROOT_DIR . "/src/globals/patch/{$patch_name}";
|
||||||
$patch_str = str_replace('/', DIRECTORY_SEPARATOR, $patch_file);
|
$patch_str = str_replace('/', DIRECTORY_SEPARATOR, $patch_file);
|
||||||
|
|
||||||
// copy patch from phar
|
// Copy patch from phar
|
||||||
if (\Phar::running() !== '') {
|
if (\Phar::running() !== '') {
|
||||||
file_put_contents(SOURCE_PATH . '/' . $patch_name, file_get_contents($patch_file));
|
file_put_contents(SOURCE_PATH . '/' . $patch_name, file_get_contents($patch_file));
|
||||||
$patch_str = str_replace('/', DIRECTORY_SEPARATOR, SOURCE_PATH . '/' . $patch_name);
|
$patch_str = str_replace('/', DIRECTORY_SEPARATOR, SOURCE_PATH . '/' . $patch_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
f_passthru(
|
// detect
|
||||||
'cd ' . $cwd . ' && ' .
|
$detect_reverse = !$reverse;
|
||||||
(PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . $patch_str . ' | patch -p1 ' . ($reverse ? '-R' : '')
|
$detect_cmd = 'cd ' . escapeshellarg($cwd) . ' && '
|
||||||
);
|
. (PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . escapeshellarg($patch_str)
|
||||||
|
. ' | patch --dry-run -p1 -s -f ' . ($detect_reverse ? '-R' : '')
|
||||||
|
. ' > ' . (PHP_OS_FAMILY === 'Windows' ? 'NUL' : '/dev/null') . ' 2>&1';
|
||||||
|
exec($detect_cmd, $output, $detect_status);
|
||||||
|
|
||||||
|
if ($detect_status === 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// apply patch
|
||||||
|
$apply_cmd = 'cd ' . escapeshellarg($cwd) . ' && '
|
||||||
|
. (PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . escapeshellarg($patch_str)
|
||||||
|
. ' | patch -p1 ' . ($reverse ? '-R' : '');
|
||||||
|
|
||||||
|
f_passthru($apply_cmd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
30
src/globals/patch/spc_fix_xlswriter_win32.patch
Normal file
30
src/globals/patch/spc_fix_xlswriter_win32.patch
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
diff --git a/library/libxlsxwriter/third_party/md5/md5.c b/library/libxlsxwriter/third_party/md5/md5.c
|
||||||
|
index b235e17..ce98e18 100644
|
||||||
|
--- a/library/libxlsxwriter/third_party/md5/md5.c
|
||||||
|
+++ b/library/libxlsxwriter/third_party/md5/md5.c
|
||||||
|
@@ -35,7 +35,11 @@
|
||||||
|
* compile-time configuration.
|
||||||
|
*/
|
||||||
|
|
||||||
|
-#ifndef HAVE_OPENSSL
|
||||||
|
+#ifdef PHP_WIN32
|
||||||
|
+#include "config.w32.h"
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
+#ifndef HAVE_OPENSSL_EXT
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
diff --git a/library/libxlsxwriter/third_party/md5/md5.h b/library/libxlsxwriter/third_party/md5/md5.h
|
||||||
|
index 2da44bf..3cb0a98 100644
|
||||||
|
--- a/library/libxlsxwriter/third_party/md5/md5.h
|
||||||
|
+++ b/library/libxlsxwriter/third_party/md5/md5.h
|
||||||
|
@@ -23,7 +23,7 @@
|
||||||
|
* See md5.c for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
-#ifdef HAVE_OPENSSL
|
||||||
|
+#ifdef HAVE_OPENSSL_EXT
|
||||||
|
#include <openssl/md5.h>
|
||||||
|
#elif !defined(_MD5_H)
|
||||||
|
#define _MD5_H
|
||||||
@ -46,7 +46,7 @@ $prefer_pre_built = false;
|
|||||||
// 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' => 'pgsql',
|
'Linux', 'Darwin' => 'pgsql',
|
||||||
'Windows' => 'xlswriter',
|
'Windows' => 'xlswriter,openssl',
|
||||||
};
|
};
|
||||||
|
|
||||||
// If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`).
|
// If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`).
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user