From 842e0add29abcd6badc533ec51d0a919fc5723da Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Thu, 29 Feb 2024 15:34:06 +0800 Subject: [PATCH] Add ffi support for windows x64 (#357) * add ffi support for windows x64 * add ffi test --- config/ext.json | 5 +- config/lib.json | 11 +++++ config/source.json | 9 ++++ src/SPC/builder/extension/ffi.php | 5 ++ .../builder/windows/library/libffi_win.php | 46 +++++++++++++++++++ src/globals/test-extensions.php | 2 +- 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/SPC/builder/windows/library/libffi_win.php diff --git a/config/ext.json b/config/ext.json index 87a11ba3..0106f6e5 100644 --- a/config/ext.json +++ b/config/ext.json @@ -63,8 +63,11 @@ "ffi": { "arg-type": "custom", "type": "builtin", - "lib-depends": [ + "lib-depends-unix": [ "libffi" + ], + "lib-depends-windows": [ + "libffi-win" ] }, "fileinfo": { diff --git a/config/lib.json b/config/lib.json index f4d48e88..4d656ae0 100644 --- a/config/lib.json +++ b/config/lib.json @@ -233,6 +233,17 @@ "ffitarget.h" ] }, + "libffi-win": { + "source": "libffi-win", + "static-libs-windows": [ + "libffi.lib" + ], + "headers-windows": [ + "ffi.h", + "ffitarget.h", + "fficonfig.h" + ] + }, "libiconv": { "source": "libiconv", "static-libs-unix": [ diff --git a/config/source.json b/config/source.json index d9287da2..d59f5c54 100644 --- a/config/source.json +++ b/config/source.json @@ -245,6 +245,15 @@ "path": "LICENSE" } }, + "libffi-win": { + "type": "git", + "rev": "master", + "url": "https://github.com/static-php/libffi-win.git", + "license": { + "type": "file", + "path": "LICENSE" + } + }, "libiconv": { "type": "filelist", "url": "https://ftp.gnu.org/gnu/libiconv/", diff --git a/src/SPC/builder/extension/ffi.php b/src/SPC/builder/extension/ffi.php index f0cf9fe6..6f294481 100644 --- a/src/SPC/builder/extension/ffi.php +++ b/src/SPC/builder/extension/ffi.php @@ -14,4 +14,9 @@ public function getUnixConfigureArg(): string { return '--with-ffi --enable-zend-signals'; } + + public function getWindowsConfigureArg(): string + { + return '--with-ffi'; + } } diff --git a/src/SPC/builder/windows/library/libffi_win.php b/src/SPC/builder/windows/library/libffi_win.php new file mode 100644 index 00000000..07bc909a --- /dev/null +++ b/src/SPC/builder/windows/library/libffi_win.php @@ -0,0 +1,46 @@ + '/win32/vs17_x64', + 'vs16' => '/win32/vs16_x64', + 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'), + 'libffi-msvc.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\Release\libffi.lib', BUILD_LIB_PATH . '\libffi.lib'); + copy($this->source_dir . $vs_ver_dir . '\x64\Release\libffi.pdb', BUILD_LIB_PATH . '\libffi.pdb'); + copy($this->source_dir . '\include\ffi.h', BUILD_INCLUDE_PATH . '\ffi.h'); + + FileSystem::replaceFileStr(BUILD_INCLUDE_PATH . '\ffi.h', '#define LIBFFI_H', "#define LIBFFI_H\n#define FFI_BUILDING"); + copy($this->source_dir . '\src\x86\ffitarget.h', BUILD_INCLUDE_PATH . '\ffitarget.h'); + copy($this->source_dir . '\fficonfig.h', BUILD_INCLUDE_PATH . '\fficonfig.h'); + + // copy($this->source_dir . '\msvc_build\out\static-Release\X64\libffi.lib', BUILD_LIB_PATH . '\libffi.lib'); + // copy($this->source_dir . '\msvc_build\include\ffi.h', BUILD_INCLUDE_PATH . '\ffi.h'); + // copy($this->source_dir . '\msvc_build\include\fficonfig.h', BUILD_INCLUDE_PATH . '\fficonfig.h'); + // copy($this->source_dir . '\src\x86\ffitarget.h', BUILD_INCLUDE_PATH . '\ffitarget.h'); + + // FileSystem::replaceFileStr(BUILD_INCLUDE_PATH . '\ffi.h', '..\..\src\x86\ffitarget.h', 'ffitarget.h'); + } +} diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 0f93a9ea..d342e8f6 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -14,7 +14,7 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { 'Linux', 'Darwin' => 'pgsql,pdo_pgsql', - 'Windows' => 'mbstring,pdo_sqlite,mbregex', + 'Windows' => 'mbstring,pdo_sqlite,mbregex,ffi', }; // If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).