diff --git a/.github/actions/setup-windows/action.yml b/.github/actions/setup-windows/action.yml index 4786242455a1a..a79f0eba540dd 100644 --- a/.github/actions/setup-windows/action.yml +++ b/.github/actions/setup-windows/action.yml @@ -7,6 +7,8 @@ runs: run: | choco install mysql -y --no-progress --params="/port:3306" mysql.exe --port=3306 --user=root --password="" -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password12!'; FLUSH PRIVILEGES;" + mysql.exe --port=3306 --user=root --password="Password12!" -e "DROP DATABASE IF EXISTS test;" + mysql.exe --port=3306 --user=root --password="Password12!" -e "CREATE DATABASE IF NOT EXISTS test;" - name: Setup MSSQL shell: pwsh run: | @@ -16,3 +18,5 @@ runs: run: | Set-Service -Name "postgresql-x64-14" -StartupType manual -Status Running pwsh -Command { $env:PGPASSWORD="root"; & "$env:PGBIN\psql" -U postgres -c "ALTER USER postgres WITH PASSWORD 'Password12!';" } + pwsh -Command { $env:PGPASSWORD="Password12!"; & "$env:PGBIN\psql" -U postgres -c "DROP SCHEMA IF EXISTS test;" } + pwsh -Command { $env:PGPASSWORD="Password12!"; & "$env:PGBIN\psql" -U postgres -c "CREATE SCHEMA IF NOT EXISTS test;" } diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 4b69154d150bf..996de5fad400e 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -884,6 +884,12 @@ jobs: - name: Setup uses: ./.github/actions/setup-windows - name: Build - run: .github/scripts/windows/build.bat + run: | + call ./scripts/windows/env.bat + call ./scripts/windows/build.bat + shell: cmd - name: Test - run: .github/scripts/windows/test.bat + run: | + call ./scripts/windows/env.bat + call ./scripts/windows/test.bat + shell: cmd diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 51751c1fc52d8..a9ec845c00fd1 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -189,9 +189,15 @@ jobs: - name: Setup uses: ./.github/actions/setup-windows - name: Build - run: .github/scripts/windows/build.bat + run: | + call ./scripts/windows/env.bat + call ./scripts/windows/build.bat + shell: cmd - name: Test - run: .github/scripts/windows/test.bat + run: | + call ./scripts/windows/env.bat + call ./scripts/windows/test.bat + shell: cmd BENCHMARKING: name: BENCHMARKING if: github.repository_owner == 'php' || github.event_name == 'pull_request' diff --git a/.gitignore b/.gitignore index 49acc9f2e1788..4c074febccbf7 100644 --- a/.gitignore +++ b/.gitignore @@ -297,3 +297,5 @@ tmp-php.ini !/ext/fileinfo/magicdata.patch !/ext/pcre/pcre2lib/config.h !/win32/build/Makefile +Firebird.zip +hMailServer.exe diff --git a/scripts/windows/README.md b/scripts/windows/README.md new file mode 100644 index 0000000000000..43416e7af9d01 --- /dev/null +++ b/scripts/windows/README.md @@ -0,0 +1,63 @@ +# Windows build scripts + +Originally used only for GitHub actions, these scripts can help windows users to be able to build locally. +While still very new (and open to feedback and [pull requests](https://github.com/php/php-src/fork)) + +## Pre-requisites + +- Windows 2019 or newer [Microsoft](https://www.microsoft.com/en-us/evalcenter/download-windows-server-2019) +- Administrative access +- Chocolatey installed to use as a package manager [Install instructions](https://chocolatey.org/install) +- MySQL installed [see our CI setup](.github/actions/setup-windows/action.yml) +- SQL Server Installed [see our CI setup](.github/actions/setup-windows/action.yml) +- Postgres Installed [see our CI setup](.github/actions/setup-windows/action.yml) +- Git installed +- Unzip utility installed +- 7zip utility installed +- Mirosoft Visual Studio 2019 Community or newer [Microsoft](https://visualstudio.microsoft.com/vs/older-downloads/) + +## Intended order of operations + +1. Setup pre-requisites +2. Setup environment [env.bat](./scripts/windows/env.bat) +3. Build PHP [build.bat](./scripts/windows/build.bat) +4. Run PHP Tests [test.bat](./scripts/windows/test.bat) +5. Cleanup [cleanup.bat](./scripts/windows/cleanup.bat) + +## env.bat + +The purpose of this script is simply to setup environment. It is intended to be run via command-line `cmd` under windows as an administrator. +You can adjust values in this script to: + +- Get more workers (theoretically runs tests faster) +- Adjust temporary and working diretories (although It is untested) +- Change between platform target (32-bit vs 64-bit) +- Change Branch +- Change PHP build SDK +- Masquerades as being inside a CI environment so the scripts do not exit early + +In the future, it would be nice if some configuration for removing extension enabling and disabling, and selecting components, such as `mysql`, `mssql`, `psql`, `firebird`, `snmp` became optional via this script. + +## build.bat + +The purpose of this script is to compile PHP, after setting up environment. It is intended to be run via command-line `cmd` under windows as an administrator. + +It coordinates running `build_task.bat`. The reason for that separation is unclear at this time, but build does pre-flight checks and downloads things according to the env. `build_task.bat` then performs the build. + +## test.bat + +The purpose of this script is to test PHP, after setting up environment, and compiling. It is intended to be run via command-line `cmd` under windows as an administrator. + +It coordinates running `test_task.bat`. The reason for that separation is unclear at this time. + +## test_task.bat + +The purpose of this script is to test PHP, after setting up environment, and compiling. It is intended to be run via test.bat and requires administrative privileges to operate successfully. + +This file has a lot of logic. In addition to building the tests, it performs setup of PHP ini, modifications to configuration files for tests, and even fetching dependencies. + +## cleanup.bat + +The purpose of this script is to shutdown less common services which tests instantiate. Test instance of Firebird and SNMPTrap, as well as clearing temporary files. + +The script is a work in progress based on one engineer machine. Please contribute to improve this. diff --git a/.github/scripts/windows/build.bat b/scripts/windows/build.bat similarity index 90% rename from .github/scripts/windows/build.bat rename to scripts/windows/build.bat index 65f40fb9462a7..ba6b16bc8563f 100644 --- a/.github/scripts/windows/build.bat +++ b/scripts/windows/build.bat @@ -1,8 +1,11 @@ -if /i "%GITHUB_ACTIONS%" neq "True" ( +if /i "%CI%" neq "True" ( echo for CI only exit /b 3 ) +echo WIN_SCRIPTS_DIR=%WIN_SCRIPTS_DIR% +echo SCRIPT_DRIVE=%SCRIPT_DRIVE% + set SDK_REMOTE=https://github.com/php/php-sdk-binary-tools.git set SDK_BRANCH=%PHP_BUILD_SDK_BRANCH% set SDK_RUNNER=%PHP_BUILD_CACHE_SDK_DIR%\phpsdk-%PHP_BUILD_CRT%-%PLATFORM%.bat @@ -41,7 +44,7 @@ if not exist "%SDK_RUNNER%" ( exit /b 3 ) -cmd /c %SDK_RUNNER% -t .github\scripts\windows\build_task.bat +cmd /c %SDK_RUNNER% -t %WIN_SCRIPTS_DIR%\build_task.bat if %errorlevel% neq 0 exit /b 3 exit /b 0 diff --git a/.github/scripts/windows/build_task.bat b/scripts/windows/build_task.bat similarity index 91% rename from .github/scripts/windows/build_task.bat rename to scripts/windows/build_task.bat index e8d84b8c0bfd6..265d3e701ddc9 100644 --- a/.github/scripts/windows/build_task.bat +++ b/scripts/windows/build_task.bat @@ -1,16 +1,19 @@ @echo off -if /i "%GITHUB_ACTIONS%" neq "True" ( +if /i "%CI%" neq "True" ( echo for CI only exit /b 3 ) +echo WIN_SCRIPTS_DIR=%WIN_SCRIPTS_DIR% +echo SCRIPT_DRIVE=%SCRIPT_DRIVE% + del /f /q C:\Windows\System32\libcrypto-1_1-x64.dll >NUL 2>NUL if %errorlevel% neq 0 exit /b 3 del /f /q C:\Windows\System32\libssl-1_1-x64.dll >NUL 2>NUL if %errorlevel% neq 0 exit /b 3 -call %~dp0find-target-branch.bat +call %WIN_SCRIPTS_DIR%\find-target-branch.bat set STABILITY=staging set DEPS_DIR=%PHP_BUILD_CACHE_BASE_DIR%\deps-%BRANCH%-%PHP_SDK_VS%-%PHP_SDK_ARCH% rem SDK is cached, deps info is cached as well diff --git a/scripts/windows/cleanup.bat b/scripts/windows/cleanup.bat new file mode 100644 index 0000000000000..bb9d5e671f861 --- /dev/null +++ b/scripts/windows/cleanup.bat @@ -0,0 +1,24 @@ +@echo off +echo "Stopping Firebird Server..." +sc query FirebirdServerTestInstance >nul 2>&1 +if errorlevel 1 ( + echo "FirebirdServerTestInstance Service does not exist. Nothing to do." +) else ( + sc stop FirebirdServerTestInstance + sc delete FirebirdServerTestInstance + echo "Stopped FirebirdServerTestInstance" +) + +echo "Stopping SNMPTrap..." +sc query SNMPTrap >nul 2>&1 +if errorlevel 1 ( + echo "SNMPTrap Service does not exist. Nothing to do." +) else ( + sc stop SNMPTrap + sc delete SNMPTrap + echo "Stopped SNMPTrap" +) + +if EXIST C:\tests_tmp rmdir /s /q C:\tests_tmp +if EXIST %PHP_BUILD_DIR%\test_file_cache rmdir /s /q %PHP_BUILD_DIR%\test_file_cache + diff --git a/scripts/windows/env.bat b/scripts/windows/env.bat new file mode 100644 index 0000000000000..e4dfa2bb586d1 --- /dev/null +++ b/scripts/windows/env.bat @@ -0,0 +1,22 @@ +@echo off + +set WIN_SCRIPTS_DIR=%~dp0 +set SCRIPT_DRIVE=%~d0 +echo WIN_SCRIPTS_DIR=%WIN_SCRIPTS_DIR% +echo SCRIPT_DRIVE=%SCRIPT_DRIVE% + +if /i "%LOCALBUILD%" equ "True" ( + set PHP_BUILD_CACHE_BASE_DIR=C:\build-cache + set PHP_BUILD_OBJ_DIR=C:\obj + set PHP_BUILD_CACHE_SDK_DIR=C:\build-cache\sdk + set PHP_BUILD_SDK_BRANCH=php_src-2.2.1-dev + set PHP_BUILD_CRT=vs16 + set PLATFORM=x64 + set THREAD_SAFE=1 + set INTRINSICS=AVX2 + set PARALLEL= -j2 + set OPCACHE=1 + + set CI=True + set BRANCH=master +) diff --git a/.github/scripts/windows/find-target-branch.bat b/scripts/windows/find-target-branch.bat similarity index 100% rename from .github/scripts/windows/find-target-branch.bat rename to scripts/windows/find-target-branch.bat diff --git a/.github/scripts/windows/test.bat b/scripts/windows/test.bat similarity index 50% rename from .github/scripts/windows/test.bat rename to scripts/windows/test.bat index 1a24564697219..052d8ed10f2c9 100644 --- a/.github/scripts/windows/test.bat +++ b/scripts/windows/test.bat @@ -1,15 +1,19 @@ -if /i "%GITHUB_ACTIONS%" neq "True" ( +if /i "%CI%" neq "True" ( echo for CI only exit /b 3 ) +echo WIN_SCRIPTS_DIR=%WIN_SCRIPTS_DIR% +echo SCRIPT_DRIVE=%SCRIPT_DRIVE% + set SDK_RUNNER=%PHP_BUILD_CACHE_SDK_DIR%\phpsdk-%PHP_BUILD_CRT%-%PLATFORM%.bat +rem SDK_RUNNER=%PHP_BUILD_CACHE_SDK_DIR%\phpsdk-%PHP_BUILD_CRT%-%PLATFORM%.bat if not exist "%SDK_RUNNER%" ( echo "%SDK_RUNNER%" doesn't exist exit /b 3 ) -cmd /c %SDK_RUNNER% -t .github\scripts\windows\test_task.bat +cmd /c %SDK_RUNNER% -t %WIN_SCRIPTS_DIR%\test_task.bat if %errorlevel% neq 0 exit /b 3 exit /b 0 diff --git a/.github/scripts/windows/test_task.bat b/scripts/windows/test_task.bat similarity index 82% rename from .github/scripts/windows/test_task.bat rename to scripts/windows/test_task.bat index dfe9eff9cba8c..8cb7c6a17da99 100644 --- a/.github/scripts/windows/test_task.bat +++ b/scripts/windows/test_task.bat @@ -1,13 +1,16 @@ -if /i "%GITHUB_ACTIONS%" neq "True" ( +if /i "%CI%" neq "True" ( echo for CI only exit /b 3 ) +echo WIN_SCRIPTS_DIR=%WIN_SCRIPTS_DIR% +echo SCRIPT_DRIVE=%SCRIPT_DRIVE% + set NO_INTERACTION=1 set REPORT_EXIT_STATUS=1 set SKIP_IO_CAPTURE_TESTS=1 -call %~dp0find-target-branch.bat +call %WIN_SCRIPTS_DIR%\find-target-branch.bat if "%BRANCH%" neq "master" ( set STABILITY=stable ) else ( @@ -30,18 +33,15 @@ set PDO_MYSQL_TEST_PASS=%MYSQL_PWD% set PDO_MYSQL_TEST_HOST=%MYSQL_TEST_HOST% set PDO_MYSQL_TEST_PORT=%MYSQL_TEST_PORT% set PDO_MYSQL_TEST_DSN=mysql:host=%PDO_MYSQL_TEST_HOST%;port=%PDO_MYSQL_TEST_PORT%;dbname=test -set TMP_MYSQL_BIN=C:\mysql\bin -"%TMP_MYSQL_BIN%\mysql.exe" --host=%PDO_MYSQL_TEST_HOST% --port=%MYSQL_TEST_PORT% --user=%MYSQL_TEST_USER% --password=%MYSQL_TEST_PASSWD% -e "CREATE DATABASE IF NOT EXISTS test" if %errorlevel% neq 0 exit /b 3 rem setup PostgreSQL related exts set PGUSER=postgres set PGPASSWORD=Password12! rem set PGSQL_TEST_CONNSTR=host=127.0.0.1 dbname=test port=5432 user=postgres password=Password12! +git checkout "./ext/pgsql/tests/config.inc" echo ^ >> "./ext/pgsql/tests/config.inc" set PDO_PGSQL_TEST_DSN=pgsql:host=127.0.0.1 port=5432 dbname=test user=%PGUSER% password=%PGPASSWORD% -set TMP_POSTGRESQL_BIN=%PGBIN% -"%TMP_POSTGRESQL_BIN%\createdb.exe" test if %errorlevel% neq 0 exit /b 3 rem setup ODBC related exts @@ -52,7 +52,7 @@ set PDOTEST_DSN=odbc:%ODBC_TEST_DSN% rem setup Firebird related exts curl -sLo Firebird.zip https://github.com/FirebirdSQL/firebird/releases/download/v3.0.9/Firebird-3.0.9.33560-0_x64.zip -7z x -oC:\Firebird Firebird.zip +7z x -y -oC:\Firebird Firebird.zip set PDO_FIREBIRD_TEST_DATABASE=C:\test.fdb set PDO_FIREBIRD_TEST_DSN=firebird:dbname=%PDO_FIREBIRD_TEST_DATABASE% set PDO_FIREBIRD_TEST_USER=SYSDBA @@ -72,10 +72,10 @@ if "%PLATFORM%" == "x64" ( ) else ( set OPENSSLDIR="C:\Program Files (x86)\Common Files\SSL" ) -if /i "%GITHUB_ACTIONS%" equ "True" ( +if /i "%CI%" equ "True" ( rmdir /s /q %OPENSSLDIR% >nul 2>&1 ) -mkdir %OPENSSLDIR% +if NOT exist %OPENSSLDIR% mkdir %OPENSSLDIR% if %errorlevel% neq 0 exit /b 3 copy %DEPS_DIR%\template\ssl\openssl.cnf %OPENSSLDIR% if %errorlevel% neq 0 exit /b 3 @@ -84,21 +84,21 @@ set OPENSSL_CONF= rem set SSLEAY_CONF= rem prepare for OPcache -if "%OPCACHE%" equ "1" set OPCACHE_OPTS=-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.protect_memory=1 -d opcache.jit_buffer_size=16M +if "%OPCACHE%" equ "1" set OPCACHE_OPTS=-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.protect_memory=1 -d opcache.jit_buffer_size=64M -d opcache.jit_max_root_traces=1000000 -d opcache.jit_max_side_traces=1000000 -d opcache.jit_max_exit_counters=1000000 -d opcache.jit_hot_loop=1 -d opcache.jit_hot_func=1 -d opcache.jit_hot_return=1 -d opcache.jit_hot_side_exit=1 -d opcache.jit=tracing rem work-around for failing to dl(mysqli) with OPcache (https://github.com/php/php-src/issues/8508) if "%OPCACHE%" equ "1" set OPCACHE_OPTS=%OPCACHE_OPTS% -d extension=mysqli rem prepare for enchant -mkdir %~d0\usr\local\lib\enchant-2 +if NOT EXIST %SCRIPT_DRIVE%\usr\local\lib\enchant-2 mkdir %SCRIPT_DRIVE%\usr\local\lib\enchant-2 if %errorlevel% neq 0 exit /b 3 -copy %DEPS_DIR%\bin\libenchant2_hunspell.dll %~d0\usr\local\lib\enchant-2 +copy %DEPS_DIR%\bin\libenchant2_hunspell.dll %SCRIPT_DRIVE%\usr\local\lib\enchant-2 if %errorlevel% neq 0 exit /b 3 -mkdir %~d0\usr\local\share\enchant\hunspell +if NOT EXIST %SCRIPT_DRIVE%\usr\local\share\enchant\hunspell mkdir %SCRIPT_DRIVE%\usr\local\share\enchant\hunspell if %errorlevel% neq 0 exit /b 3 echo Fetching enchant dicts -pushd %~d0\usr\local\share\enchant\hunspell +pushd %SCRIPT_DRIVE%\usr\local\share\enchant\hunspell powershell -Command wget http://windows.php.net/downloads/qa/appveyor/ext/enchant/dict.zip -OutFile dict.zip -unzip dict.zip +unzip -o dict.zip del /q dict.zip popd @@ -115,6 +115,7 @@ hMailServer.exe /verysilent cd %APPVEYOR_BUILD_FOLDER% %PHP_BUILD_DIR%\php.exe -dextension_dir=%PHP_BUILD_DIR% -dextension=com_dotnet appveyor\setup_hmailserver.php +if EXIST %PHP_BUILD_DIR%\test_file_cache rmdir /s /q %PHP_BUILD_DIR%\test_file_cache mkdir %PHP_BUILD_DIR%\test_file_cache rem generate php.ini echo extension_dir=%PHP_BUILD_DIR% > %PHP_BUILD_DIR%\php.ini @@ -130,6 +131,7 @@ for %%i in (ldap oci8_12c pdo_oci) do ( set TEST_PHPDBG_EXECUTABLE=%PHP_BUILD_DIR%\phpdbg.exe +if EXIST C:\tests_tmp rmdir /s /q C:\tests_tmp mkdir c:\tests_tmp set TEST_PHP_JUNIT=c:\junit.out.xml