From debb432926a6c9e9beeb088439659058f89201b7 Mon Sep 17 00:00:00 2001 From: Martins Lazdans Date: Tue, 2 May 2023 02:29:01 +0300 Subject: [PATCH] Add windows build scripts --- win_build_scripts/README.md | 25 +++++++++ win_build_scripts/php-fb-build-all.bat | 8 +++ win_build_scripts/php-fb-build.bat | 78 ++++++++++++++++++++++++++ win_build_scripts/php-fb-config.bat | 16 ++++++ win_build_scripts/php-fb-sdk-build.bat | 57 +++++++++++++++++++ win_build_scripts/php-fb-sdk-init.bat | 30 ++++++++++ 6 files changed, 214 insertions(+) create mode 100644 win_build_scripts/README.md create mode 100644 win_build_scripts/php-fb-build-all.bat create mode 100644 win_build_scripts/php-fb-build.bat create mode 100644 win_build_scripts/php-fb-config.bat create mode 100644 win_build_scripts/php-fb-sdk-build.bat create mode 100644 win_build_scripts/php-fb-sdk-init.bat diff --git a/win_build_scripts/README.md b/win_build_scripts/README.md new file mode 100644 index 0000000..5253401 --- /dev/null +++ b/win_build_scripts/README.md @@ -0,0 +1,25 @@ +# Scripts building php-firebird extension on Windows + +## How it works + +These scripts will clone or pull corresponding PHP version(s) from the PHP source repo and build 4 .dll files per PHP version: x86, x64 and ts and non-ts for each architecture. + +Do not run scripts with ``-sdk-`` in their files names directly. These are called from php-sdk environment. + +Make sure you got ~20GB free disk space to build for all PHP versions. + +## Set up + +Make sure ``git`` is in you PATH + +1. Set up Microsoft Visual Studio vc15 and vs16. +2. Set up Firebird 32-bit and 64-bit installations or libraries. +3. Set up PHP-SDK according to https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2 +4. Clone php-firebird extension source somewhere. +4. Copy these build scripts to C:\php-sdk\ +5. Adjust php-fb-config.bat. + + ``Note: PFB_SOURCE_DIR should point one level up. For example + PFB_SOURCE_DIR=D:\php-firebird\ then your source should reside in D:\php-firebird\php-firebird\ + `` +6. Run ``php-fb-build-all.bat`` to build for all PHP versions or run ``php-fb-build.bat 7.4 vc15`` to build for particular version. diff --git a/win_build_scripts/php-fb-build-all.bat b/win_build_scripts/php-fb-build-all.bat new file mode 100644 index 0000000..fdfa8c2 --- /dev/null +++ b/win_build_scripts/php-fb-build-all.bat @@ -0,0 +1,8 @@ +@echo off + +call php-fb-build.bat 7.3 vc15 || exit /B %ERRORLEVEL% +call php-fb-build.bat 7.4 vc15 || exit /B %ERRORLEVEL% +call php-fb-build.bat 8.0 vs16 || exit /B %ERRORLEVEL% +call php-fb-build.bat 8.1 vs16 || exit /B %ERRORLEVEL% +call php-fb-build.bat 8.2 vs16 || exit /B %ERRORLEVEL% +call php-fb-build.bat master vs16 || exit /B %ERRORLEVEL% diff --git a/win_build_scripts/php-fb-build.bat b/win_build_scripts/php-fb-build.bat new file mode 100644 index 0000000..41ac12c --- /dev/null +++ b/win_build_scripts/php-fb-build.bat @@ -0,0 +1,78 @@ +@echo off + +@REM config ====================================================================================== +call php-fb-config.bat + +goto :MAIN + +@REM log ========================================================================================= +@REM log +@REM example> call :log "" +:log + set msg=%~1 + echo --------------------------------------------------------------------- + echo %msg% + echo --------------------------------------------------------------------- +exit /B + +:usage + call :log "Usage: %~nx0 php_vers cpp_vers" +exit /B + +:MAIN +set pfb_php_vers=%1 +set pfb_cpp_vers=%2 + +if [%pfb_php_vers%] == [] ( + call :usage + echo pfb_php_vers varible not set + exit 1 +) + +if [%pfb_cpp_vers%] == [] ( + call :usage + echo pfb_cpp_vers varible not set + exit 1 +) + +set pfb_build_root=php%pfb_php_vers%\%pfb_cpp_vers%\ + +(for %%a in (x86 x64) do ( + @REM check out or pull PHP version of interest + if exist %pfb_build_root%\%%a\php-src\.git\ ( + call :log "Checking out PHP-%pfb_php_vers% %%a" + git -C %pfb_build_root%\%%a\php-src pull || goto :error + ) else ( + call :log "Cloning PHP-%pfb_php_vers% %%a" + call phpsdk-%pfb_cpp_vers%-%%a.bat -t php-fb-sdk-init.bat || goto :error + ) + + if %%a EQU x86 ( set pfb_x86=1 ) else ( set pfb_x86=0 ) + + (for %%n in (0 1) do ( + set pfb_nts=%%n + call phpsdk-%pfb_cpp_vers%-%%a.bat -t php-fb-sdk-build.bat || goto :error + )) +)) + +@REM check if ibase_connect() function exists in newly compiled extension +set check_code="if(!function_exists('ibase_connect'))exit(1);" +"%pfb_build_root%x64\php-src\x64\Release_TS\php.exe" -dextension=.\php_interbase.dll -r %check_code% || goto :error +"%pfb_build_root%x64\php-src\x64\Release\php.exe" -dextension=.\php_interbase.dll -r %check_code% || goto :error +"%pfb_build_root%x86\php-src\Release_TS\php.exe" -dextension=.\php_interbase.dll -r %check_code% || goto :error +"%pfb_build_root%x86\php-src\Release\php.exe" -dextension=.\php_interbase.dll -r %check_code% || goto :error + +call :log "PHP %pfb_php_vers% build OK" + +@REM copy compiled extension to target directory +copy %pfb_build_root%x64\php-src\x64\Release_TS\php_interbase.dll %PFB_OUTPUT_DIR%php_interbase-%PFB_VERS%-%pfb_php_vers%-%pfb_cpp_vers%-x86_64.dll>nul +copy %pfb_build_root%x64\php-src\x64\Release\php_interbase.dll %PFB_OUTPUT_DIR%php_interbase-%PFB_VERS%-%pfb_php_vers%-%pfb_cpp_vers%-nts-x86_64.dll>nul +copy %pfb_build_root%x86\php-src\Release_TS\php_interbase.dll %PFB_OUTPUT_DIR%php_interbase-%PFB_VERS%-%pfb_php_vers%-%pfb_cpp_vers%.dll>nul +copy %pfb_build_root%x86\php-src\Release\php_interbase.dll %PFB_OUTPUT_DIR%php_interbase-%PFB_VERS%-%pfb_php_vers%-%pfb_cpp_vers%-nts.dll>nul + +exit /B 0 + +:error + call :log "PHP %pfb_php_vers% build FAILED" + +exit /B 1 diff --git a/win_build_scripts/php-fb-config.bat b/win_build_scripts/php-fb-config.bat new file mode 100644 index 0000000..0c8dd70 --- /dev/null +++ b/win_build_scripts/php-fb-config.bat @@ -0,0 +1,16 @@ +@REM +@REM git command must be in PATH +@REM + +@REM sets php-firebird version part in extension file, for example, php_interbase-<<3.0.1-ba8e63b>>-7.3-vc15.dll +set PFB_VERS=3.0.1-ba8e63b + +@REM Directory where all compiled files will be copied +set PFB_OUTPUT_DIR=D:\php-firebird\releases\ + +@REM FB 32-bit and 64-bit libraries +set PFB_FB32_DIR=C:\Program Files\Firebird\Firebird_3_0-x86\ +set PFB_FB64_DIR=C:\Program Files\Firebird\Firebird_3_0\ + +@REM php-firebird source directory +set PFB_SOURCE_DIR=D:\php-firebird\ba8e63b\ diff --git a/win_build_scripts/php-fb-sdk-build.bat b/win_build_scripts/php-fb-sdk-build.bat new file mode 100644 index 0000000..6b4c1ef --- /dev/null +++ b/win_build_scripts/php-fb-sdk-build.bat @@ -0,0 +1,57 @@ +@echo off +@REM +@REM Must be called under phpsdk--.bat +@REM +@REM Calling script should set variables: +@REM [pfb_nts] [pfb_x86] +@REM +@REM set pfb_php_vers=7.4 +@REM set pfb_nts=1 if nts expected, 0 if ts +@REM set pfb_x86=1 if linking to x86 fbclient, o if x64 +@REM +@REM all set in php-fb-config.bat +@REM + +goto :MAIN + +@REM log ========================================================================================= +@REM log +@REM example> call :log "" +:log + set msg=%~1 + echo --------------------------------------------------------------------- + echo %msg% + echo --------------------------------------------------------------------- +exit /B + +:MAIN + if [%pfb_php_vers%] == [] ( + echo pfb_php_vers varible not set + exit 1 + ) + + set build_msg=Building PHP-%pfb_php_vers% + + if "%pfb_nts%" gtr "0" ( + set build_msg=%build_msg% non-TS + set extra_args=--disable-zts + ) else ( + set build_msg=%build_msg% TS + set extra_args= + ) + + if "%pfb_x86%" gtr "0" ( + set with_interbase="shared,%PFB_FB32_DIR%lib;%PFB_FB32_DIR%include" + set build_msg=%build_msg% x86 + ) else ( + set with_interbase="shared,%PFB_FB64_DIR%lib;%PFB_FB64_DIR%include" + set build_msg=%build_msg% x86_64 + ) + + call :log "%build_msg%" + + call phpsdk_buildtree php%pfb_php_vers% + cd /D php-src + call buildconf.bat --force --add-modules-dir=%PFB_SOURCE_DIR% + call configure.bat --disable-all --enable-cli %extra_args% --with-interbase=%with_interbase% + nmake diff --git a/win_build_scripts/php-fb-sdk-init.bat b/win_build_scripts/php-fb-sdk-init.bat new file mode 100644 index 0000000..f655a40 --- /dev/null +++ b/win_build_scripts/php-fb-sdk-init.bat @@ -0,0 +1,30 @@ +@echo off +@REM +@REM Must be called under phpsdk--.bat +@REM +@REM Calling script should set variables: +@REM +@REM set pfb_php_vers=7.4 + +if [%pfb_php_vers%] == [] ( + echo pfb_php_vers varible not set + exit 1 +) + +@REM Handle current master branch +if "%pfb_php_vers%" == "master" ( + set pfb_git_args= +) else ( + set pfb_git_args=--branch PHP-%pfb_php_vers% +) + +call phpsdk_buildtree php%pfb_php_vers% +git clone --depth 1 %pfb_git_args% https://github.com/php/php-src.git +cd php-src + +@REM Remove built-in extension +if "%pfb_php_vers%" == "7.3" ( + rd /Q /S ext\interbase +) + +call phpsdk_deps --update