diff --git a/.github/workflows/main-pm-matrix.yml b/.github/workflows/main-pm-matrix.yml index 89b68379..a9ada1f7 100644 --- a/.github/workflows/main-pm-matrix.yml +++ b/.github/workflows/main-pm-matrix.yml @@ -137,22 +137,31 @@ jobs: steps: - uses: actions/checkout@v4 - - - name: Install tools and dependencies - run: choco install wget --no-progress - + + - name: Prepare download cache + id: download-cache + uses: actions/cache@v4 + with: + path: ./download_cache + key: windows-cache-${{ hashFiles('./windows-compile-vs.ps1') }} + restore-keys: windows-cache- + - name: Compile PHP - run: .\windows-compile-vs.bat + run: .\windows-compile-vs.ps1 env: - VS_EDITION: Enterprise SOURCES_PATH: ${{ github.workspace }}\pocketmine-php-sdk PM_VERSION_MAJOR: ${{ inputs.pm-version-major }} - - name: Rename artifacts + - name: Download VC++ Redistributable + run: | + #vs17 allows running anything from VS 2015-2022 + Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vc_redist.x64.exe -OutFile vc_redist.x64.exe + + - name: Prepare artifacts run: | mkdir temp + Compress-Archive -Path .\bin -DestinationPath "PHP-Windows-x64-PM${{ inputs.pm-version-major }}.zip" move php-debug-pack-*.zip temp/PHP-Windows-x64-PM${{ inputs.pm-version-major }}-debugging-symbols.zip - move php-*.zip temp/PHP-Windows-x64-PM${{ inputs.pm-version-major }}.zip move temp\*.zip . - name: Upload artifacts @@ -161,7 +170,8 @@ jobs: with: name: Windows-PM${{ inputs.pm-version-major }} path: | - PHP-Windows-x64*.zip + PHP-Windows-x64-PM${{ inputs.pm-version-major }}*.zip compile.log windows-compile-vs.bat + vc_redist.x64.exe if-no-files-found: error diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1a8dbad9..e213690e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -82,6 +82,7 @@ jobs: ${{ github.workspace }}/Linux-PM*/*.tar.gz ${{ github.workspace }}/MacOS-*-PM*/*.tar.gz ${{ github.workspace }}/Windows-PM*/*.zip + ${{ github.workspace }}/Windows-PM*/*.exe makeLatest: ${{ github.ref_name == github.event.repository.default_branch }} name: PHP ${{ steps.version.outputs.PHP_VERSION }} - Latest (${{ steps.date.outputs.DATE }}) tag: php-${{ steps.version.outputs.PHP_VERSION }}-latest @@ -98,6 +99,7 @@ jobs: ${{ github.workspace }}/Linux-PM*/*.tar.gz ${{ github.workspace }}/MacOS-*-PM*/*.tar.gz ${{ github.workspace }}/Windows-PM*/*.zip + ${{ github.workspace }}/Windows-PM*/*.exe makeLatest: false name: PHP ${{ steps.version.outputs.PHP_VERSION }} (Build ${{ github.run_number }}) tag: php-${{ steps.version.outputs.PHP_VERSION }}-build-${{ github.run_number }} diff --git a/windows-compile-vs.bat b/windows-compile-vs.bat deleted file mode 100644 index 1850d528..00000000 --- a/windows-compile-vs.bat +++ /dev/null @@ -1,470 +0,0 @@ -@echo off - -REM For future users: This file MUST have CRLF line endings. If it doesn't, lots of inexplicable undesirable strange behaviour will result. -REM Also: Don't modify this version with sed, or it will screw up your line endings. -set PHP_MAJOR_VER=8.2 -set PHP_VER=%PHP_MAJOR_VER%.25 -set PHP_GIT_REV=php-%PHP_VER% -set PHP_DISPLAY_VER=%PHP_VER% -set PHP_SDK_VER=2.2.0 -set PATH=C:\Program Files\7-Zip;C:\Program Files (x86)\GnuWin32\bin;%PATH% -set VC_VER=vs16 -set ARCH=x64 -set VS_PATH= -set CMAKE_TARGET= -if "%PHP_DEBUG_BUILD%"=="" ( - set PHP_DEBUG_BUILD=0 -) -set MSBUILD_CONFIGURATION=RelWithDebInfo -set PHP_JIT_ENABLE_ARG=no - -REM NOTE: Tags with "v" prefixes behave weirdly in the GitHub API. They'll be stripped in some places but not others. -REM Use commit hashes to avoid this. - -set LIBYAML_VER=0.2.5 -set PTHREAD_W32_VER=3.0.0 -REM release not tagged -set LEVELDB_MCPE_VER=1c7564468b41610da4f498430e795ca4de0931ff -REM 1.22 - see above note about "v" prefixes -set LIBDEFLATE_VER=2335c047e91cac6fd04cb0fd2769380395149f15 - -set PHP_PMMPTHREAD_VER=6.1.0 -set PHP_YAML_VER=2.2.4 -set PHP_CHUNKUTILS2_VER=0.3.5 -set PHP_IGBINARY_VER=3.2.16 -REM release not tagged -set PHP_LEVELDB_VER=317fdcd8415e1566fc2835ce2bdb8e19b890f9f3 -REM release not tagged -set PHP_CRYPTO_VER=abbe7cbf869f96e69f2ce897271a61d32f43c7c0 -set PHP_RECURSIONGUARD_VER=0.1.0 -set PHP_MORTON_VER=0.1.2 -set PHP_LIBDEFLATE_VER=0.2.1 -set PHP_XXHASH_VER=0.2.0 -set PHP_XDEBUG_VER=3.3.2 -set PHP_ARRAYDEBUG_VER=0.2.0 -set PHP_ENCODING_VER=0.3.0 - -set script_path=%~dp0 -set log_file=%script_path%compile.log -echo.>"%log_file%" - -set "outpath=%cd%" - -where git >nul 2>nul || (call :pm-echo-error "git is required" & exit 1) -where cmake >nul 2>nul || (call :pm-echo-error "cmake is required" & exit 1) -where 7z >nul 2>nul || (call :pm-echo-error "7z is required" & exit 1) -where wget >nul 2>nul || (call :pm-echo-error "wget is required" & exit 1) - -REM to ensure we use the correct version of wget - the SDK provides an outdated one that has outdated SSL certs -set ORIG_PATH=%PATH% - -call :pm-echo "PHP Windows compiler" -call :pm-echo "Setting up environment..." - -if "%PHP_DEBUG_BUILD%"=="0" ( - set OUT_PATH_REL=Release - set PHP_HAVE_DEBUG=enable-debug-pack - call :pm-echo "Building release binaries with debug symbols" -) else ( - set OUT_PATH_REL=Debug - set PHP_HAVE_DEBUG=enable-debug - REM I don't like this, but YAML will crash if it's not built with the same target as PHP - set MSBUILD_CONFIGURATION=Debug - call :pm-echo "Building debug binaries" -) - -if "%PHP_JIT_SUPPORT%"=="1" ( - set PHP_JIT_ENABLE_ARG=yes - call :pm-echo "Compiling JIT support in OPcache (unstable)" -) - -if "%PM_VERSION_MAJOR%"=="" ( - call :pm-echo-error "Please specify PocketMine-MP major version by setting the PM_VERSION_MAJOR environment variable" - exit 1 -) -if "%PM_VERSION_MAJOR%" lss "5" ( - call :pm-echo-error "PocketMine-MP 4.x and older are no longer supported" - exit 1 -) - -call :pm-echo "Compiling with configuration for PocketMine-MP %PM_VERSION_MAJOR%" - -if "%SOURCES_PATH%"=="" ( - if "%PHP_DEBUG_BUILD%"=="0" ( - set SOURCES_PATH=C:\pocketmine-php-%PHP_DISPLAY_VER%-release - ) else ( - set SOURCES_PATH=C:\pocketmine-php-%PHP_DISPLAY_VER%-debug - ) -) -call :pm-echo "Using path %SOURCES_PATH% for build sources" - -call :check-vs-exists 2022 17 "Program Files" || call :check-vs-exists 2019 16 "Program Files (x86)" || call :pm-fatal-error "Please install Visual Studio 2019" - -REM export an env var to override this if you're using something other than the community edition -if "%VS_EDITION%"=="" ( - set VS_EDITION=Community -) - -call "%VS_PATH%\%VS_EDITION%\VC\Auxiliary\Build\vcvarsall.bat" %ARCH% >>"%log_file%" 2>&1 || call :pm-fatal-error "Error initializing Visual Studio environment" -:batchfiles-are-stupid -move "%log_file%" "%log_file%" >nul 2>nul || goto :batchfiles-are-stupid - -cd /D "%outpath%" - -if exist bin ( - call :pm-echo "Deleting old binary folder..." - rmdir /s /q bin >>"%log_file%" 2>&1 || call :pm-fatal-error "Failed to delete old binary folder" -) - -if exist "%SOURCES_PATH%" ( - call :pm-echo "Deleting old workspace..." - rmdir /s /q "%SOURCES_PATH%" >>"%log_file%" 2>&1 || call :pm-fatal-error "Failed to delete old workspace" -) - -call :pm-echo "Getting SDK..." -git clone https://github.com/OSTC/php-sdk-binary-tools.git -b php-sdk-%PHP_SDK_VER% --depth=1 -q "%SOURCES_PATH%" >>"%log_file%" 2>&1 || call :pm-fatal-error "Failed to download SDK" - -cd /D "%SOURCES_PATH%" - -call bin\phpsdk_setvars.bat >>"%log_file%" 2>&1 - -call :pm-echo "Downloading PHP source version %PHP_VER%..." -call :get-zip https://github.com/php/php-src/archive/%PHP_GIT_REV%.zip || call :pm-fatal-error "Failed to download PHP source" -move php-src-%PHP_GIT_REV% php-src >>"%log_file%" 2>&1 || call :pm-fatal-error "Failed to move PHP source to target directory" - -set DEPS_DIR_NAME=deps -set "DEPS_DIR=%SOURCES_PATH%\%DEPS_DIR_NAME%" - -call :pm-echo "Downloading PHP dependencies into %DEPS_DIR%..." -call bin\phpsdk_deps.bat -u -t %VC_VER% -b %PHP_MAJOR_VER% -a %ARCH% -f -d %DEPS_DIR_NAME% >>"%log_file%" 2>&1 || exit 1 - - -call :pm-echo "Getting additional dependencies..." -cd /D "%DEPS_DIR%" - -call :pm-echo "Downloading LibYAML version %LIBYAML_VER%..." -call :get-zip https://github.com/yaml/libyaml/archive/%LIBYAML_VER%.zip || exit 1 -move libyaml-%LIBYAML_VER% libyaml >>"%log_file%" 2>&1 -cd /D libyaml -call :pm-echo "Generating build configuration..." -cmake -G "%CMAKE_TARGET%" -A "%ARCH%"^ - -DCMAKE_PREFIX_PATH="%DEPS_DIR%"^ - -DCMAKE_INSTALL_PREFIX="%DEPS_DIR%"^ - -DBUILD_SHARED_LIBS=ON^ - . >>"%log_file%" 2>&1 || exit 1 -call :pm-echo "Compiling..." -msbuild ALL_BUILD.vcxproj /p:Configuration=%MSBUILD_CONFIGURATION% /m >>"%log_file%" 2>&1 || exit 1 -call :pm-echo "Installing files..." -msbuild INSTALL.vcxproj /p:Configuration=%MSBUILD_CONFIGURATION% /m >>"%log_file%" 2>&1 || exit 1 -copy %MSBUILD_CONFIGURATION%\yaml.pdb "%DEPS_DIR%\bin\yaml.pdb" >>"%log_file%" 2>&1 || exit 1 - -cd /D "%DEPS_DIR%" - -call :pm-echo "Downloading pthread-w32 version %PTHREAD_W32_VER%..." -mkdir pthread-w32 -cd /D pthread-w32 -call :get-zip https://github.com/pmmp/DependencyMirror/releases/download/mirror/pthreads4w-code-v%PTHREAD_W32_VER%.zip || exit 1 -move pthreads4w-code-* pthreads4w-code >>"%log_file%" 2>&1 -cd /D pthreads4w-code - -call :pm-echo "Compiling..." -nmake VC >>"%log_file%" 2>&1 || exit 1 - -call :pm-echo "Copying files..." -copy pthread.h "%DEPS_DIR%\include\pthread.h" >>"%log_file%" 2>&1 || exit 1 -copy sched.h "%DEPS_DIR%\include\sched.h" >>"%log_file%" 2>&1 || exit 1 -copy semaphore.h "%DEPS_DIR%\include\semaphore.h" >>"%log_file%" 2>&1 || exit 1 -copy _ptw32.h "%DEPS_DIR%\include\_ptw32.h" >>"%log_file%" 2>&1 || exit 1 -copy pthreadVC3.lib "%DEPS_DIR%\lib\pthreadVC3.lib" >>"%log_file%" 2>&1 || exit 1 -copy pthreadVC3.dll "%DEPS_DIR%\bin\pthreadVC3.dll" >>"%log_file%" 2>&1 || exit 1 -copy pthreadVC3.pdb "%DEPS_DIR%\bin\pthreadVC3.pdb" >>"%log_file%" 2>&1 || exit 1 - -cd /D "%DEPS_DIR%" - -call :pm-echo "Downloading pmmp/leveldb version %LEVELDB_MCPE_VER%..." -call :get-zip https://github.com/pmmp/leveldb/archive/%LEVELDB_MCPE_VER%.zip || exit 1 -move leveldb-%LEVELDB_MCPE_VER% leveldb >>"%log_file%" 2>&1 -cd /D leveldb - -call :pm-echo "Generating build configuration..." -cmake -G "%CMAKE_TARGET%" -A "%ARCH%"^ - -DCMAKE_PREFIX_PATH="%DEPS_DIR%"^ - -DCMAKE_INSTALL_PREFIX="%DEPS_DIR%"^ - -DBUILD_SHARED_LIBS=ON^ - -DLEVELDB_BUILD_BENCHMARKS=OFF^ - -DLEVELDB_BUILD_TESTS=OFF^ - -DZLIB_LIBRARY="%DEPS_DIR%\lib\zlib_a.lib"^ - . >>"%log_file%" 2>&1 || exit 1 -call :pm-echo "Compiling" -msbuild ALL_BUILD.vcxproj /p:Configuration=%MSBUILD_CONFIGURATION% /m >>"%log_file%" 2>&1 || exit 1 -call :pm-echo "Installing files..." -msbuild INSTALL.vcxproj /p:Configuration=%MSBUILD_CONFIGURATION% >>"%log_file%" 2>&1 || exit 1 -copy %MSBUILD_CONFIGURATION%\leveldb.pdb "%DEPS_DIR%\bin\leveldb.pdb" >>"%log_file%" 2>&1 || exit 1 - -cd /D "%DEPS_DIR%" - -call :pm-echo "Downloading libdeflate version %LIBDEFLATE_VER%..." -call :get-zip https://github.com/ebiggers/libdeflate/archive/%LIBDEFLATE_VER%.zip || exit 1 -move libdeflate-%LIBDEFLATE_VER% libdeflate >>"%log_file%" 2>&1 -cd /D libdeflate - -call :pm-echo "Generating build configuration..." -cmake -G "%CMAKE_TARGET%" -A "%ARCH%"^ - -DCMAKE_PREFIX_PATH="%DEPS_DIR%"^ - -DCMAKE_INSTALL_PREFIX="%DEPS_DIR%"^ - -DLIBDEFLATE_BUILD_GZIP=OFF^ - -DLIBDEFLATE_BUILD_SHARED_LIB=ON^ - -DLIBDEFLATE_BUILD_STATIC_LIB=OFF^ - . >>"%log_file%" 2>&1 || exit 1 -call :pm-echo "Compiling" -msbuild ALL_BUILD.vcxproj /p:Configuration=%MSBUILD_CONFIGURATION% /m >>"%log_file%" 2>&1 || exit 1 -call :pm-echo "Installing files..." -msbuild INSTALL.vcxproj /p:Configuration=%MSBUILD_CONFIGURATION% >>"%log_file%" 2>&1 || exit 1 -copy %MSBUILD_CONFIGURATION%\deflate.pdb "%DEPS_DIR%\bin\deflate.pdb" >>"%log_file%" 2>&1 || exit 1 - -cd /D "%DEPS_DIR%" - -cd /D .. - -call :pm-echo "Getting additional PHP extensions..." -cd /D php-src\ext - -call :get-extension-zip-from-github "pmmpthread" "%PHP_PMMPTHREAD_VER%" "pmmp" "ext-pmmpthread" || exit 1 -call :get-extension-zip-from-github "yaml" "%PHP_YAML_VER%" "php" "pecl-file_formats-yaml" || exit 1 -call :get-extension-zip-from-github "chunkutils2" "%PHP_CHUNKUTILS2_VER%" "pmmp" "ext-chunkutils2" || exit 1 -call :get-extension-zip-from-github "igbinary" "%PHP_IGBINARY_VER%" "igbinary" "igbinary" || exit 1 -call :get-extension-zip-from-github "leveldb" "%PHP_LEVELDB_VER%" "pmmp" "php-leveldb" || exit 1 -call :get-extension-zip-from-github "recursionguard" "%PHP_RECURSIONGUARD_VER%" "pmmp" "ext-recursionguard" || exit 1 -call :get-extension-zip-from-github "morton" "%PHP_MORTON_VER%" "pmmp" "ext-morton" || exit 1 -call :get-extension-zip-from-github "libdeflate" "%PHP_LIBDEFLATE_VER%" "pmmp" "ext-libdeflate" || exit 1 -call :get-extension-zip-from-github "xxhash" "%PHP_XXHASH_VER%" "pmmp" "ext-xxhash" || exit 1 -call :get-extension-zip-from-github "xdebug" "%PHP_XDEBUG_VER%" "xdebug" "xdebug" || exit 1 -call :get-extension-zip-from-github "arraydebug" "%PHP_ARRAYDEBUG_VER%" "pmmp" "ext-arraydebug" || exit 1 -call :get-extension-zip-from-github "encoding" "%PHP_ENCODING_VER%" "pmmp" "ext-encoding" || exit 1 - -call :pm-echo " - crypto: downloading %PHP_CRYPTO_VER%..." -git clone https://github.com/bukka/php-crypto.git crypto >>"%log_file%" 2>&1 || exit 1 -cd /D crypto -git checkout %PHP_CRYPTO_VER% >>"%log_file%" 2>&1 || exit 1 -git submodule update --init --recursive >>"%log_file%" 2>&1 || exit 1 -cd /D .. - -cd /D ..\.. - -:skip -cd /D php-src -call :pm-echo "Configuring PHP..." -call buildconf.bat >>"%log_file%" 2>&1 - -REM https://github.com/php/php-src/pull/6658 - this is needed until 8.0.3 releases because php-sdk gives us dependencies that won't otherwise build -set LDFLAGS="/d2:-AllowCompatibleILVersions" - -call configure^ - --with-mp=auto^ - --with-prefix=pocketmine-php-bin^ - --%PHP_HAVE_DEBUG%^ - --disable-all^ - --disable-cgi^ - --enable-cli^ - --enable-zts^ - --enable-pdo^ - --enable-arraydebug=shared^ - --enable-bcmath^ - --enable-calendar^ - --enable-chunkutils2=shared^ - --enable-com-dotnet^ - --enable-ctype^ - --enable-encoding=shared^ - --enable-fileinfo=shared^ - --enable-filter^ - --enable-hash^ - --enable-igbinary=shared^ - --enable-json^ - --enable-mbstring^ - --enable-morton^ - --enable-opcache^ - --enable-opcache-jit=%PHP_JIT_ENABLE_ARG%^ - --enable-phar^ - --enable-recursionguard=shared^ - --enable-sockets^ - --enable-tokenizer^ - --enable-xmlreader^ - --enable-xmlwriter^ - --enable-xxhash^ - --enable-zip^ - --enable-zlib^ - --with-bz2=shared^ - --with-crypto=shared^ - --with-curl^ - --with-dom^ - --with-gd=shared^ - --with-gmp^ - --with-iconv^ - --with-leveldb=shared^ - --with-libdeflate=shared^ - --with-libxml^ - --with-mysqli=shared^ - --with-mysqlnd^ - --with-openssl^ - --with-pcre-jit^ - --with-pmmpthread=shared^ - --with-pmmpthread-sockets^ - --with-simplexml^ - --with-sodium^ - --with-sqlite3=shared^ - --with-xdebug=shared^ - --with-xdebug-compression^ - --with-xml^ - --with-yaml^ - --with-pdo-mysql^ - --with-pdo-sqlite^ - --without-readline >>"%log_file%" 2>&1 || call :pm-fatal-error "Error configuring PHP" - -call :pm-echo "Compiling PHP..." -nmake >>"%log_file%" 2>&1 || call :pm-fatal-error "Error compiling PHP" - -call :pm-echo "Assembling artifacts..." -nmake snap >>"%log_file%" 2>&1 || call :pm-fatal-error "Error assembling artifacts" - -call :pm-echo "Removing unneeded dependency DLLs..." -REM remove ICU DLLs copied unnecessarily by nmake snap - this needs to be removed if we ever have ext/intl as a dependency -del /q "%SOURCES_PATH%\php-src\%ARCH%\Release_TS\php-%PHP_DISPLAY_VER%\icu*.dll" 2>&1 -REM remove enchant dependencies which are unnecessarily copied - this needs to be removed if we ever have ext/enchant as a dependency -del /q "%SOURCES_PATH%\php-src\%ARCH%\Release_TS\php-%PHP_DISPLAY_VER%\glib-*.dll" 2>&1 -del /q "%SOURCES_PATH%\php-src\%ARCH%\Release_TS\php-%PHP_DISPLAY_VER%\gmodule-*.dll" 2>&1 -rmdir /s /q "%SOURCES_PATH%\php-src\%ARCH%\Release_TS\php-%PHP_DISPLAY_VER%\lib\enchant\" 2>&1 - -call :pm-echo "Copying artifacts..." -cd /D "%outpath%" -mkdir bin -move "%SOURCES_PATH%\php-src\%ARCH%\%OUT_PATH_REL%_TS\php-%PHP_DISPLAY_VER%" bin\php -cd /D bin\php - -set php_ini=php.ini -call :pm-echo "Generating php.ini..." -(echo ;Custom PocketMine-MP php.ini file)>"%php_ini%" -(echo memory_limit=1024M)>>"%php_ini%" -(echo display_errors=1)>>"%php_ini%" -(echo display_startup_errors=1)>>"%php_ini%" -(echo error_reporting=-1)>>"%php_ini%" -(echo zend.assertions=-1)>>"%php_ini%" -(echo extension_dir=ext)>>"%php_ini%" -if "%PM_VERSION_MAJOR%" geq "5" ( - (echo extension=php_pmmpthread.dll)>>"%php_ini%" -) else ( - (echo extension=php_pthreads.dll)>>"%php_ini%" -) -(echo extension=php_openssl.dll)>>"%php_ini%" -(echo extension=php_chunkutils2.dll)>>"%php_ini%" -(echo extension=php_igbinary.dll)>>"%php_ini%" -(echo extension=php_leveldb.dll)>>"%php_ini%" -(echo extension=php_crypto.dll)>>"%php_ini%" -(echo extension=php_libdeflate.dll)>>"%php_ini% -(echo igbinary.compact_strings=0)>>"%php_ini%" -(echo zend_extension=php_opcache.dll)>>"%php_ini%" -(echo opcache.enable=1)>>"%php_ini%" -(echo opcache.enable_cli=1)>>"%php_ini%" -(echo opcache.save_comments=1)>>"%php_ini%" -(echo opcache.validate_timestamps=1)>>"%php_ini%" -(echo opcache.revalidate_freq=0)>>"%php_ini%" -(echo opcache.file_update_protection=0)>>"%php_ini%" -(echo opcache.optimization_level=0x7FFEBFFF)>>"%php_ini%" -(echo opcache.cache_id=PHP_BINARY ;prevent sharing SHM between different binaries - they won't work because of ASLR)>>"%php_ini%" -(echo ;Optional extensions, supplied for plugin use)>>"%php_ini%" -(echo extension=php_fileinfo.dll)>>"%php_ini%" -(echo extension=php_gd.dll)>>"%php_ini%" -(echo extension=php_mysqli.dll)>>"%php_ini%" -(echo extension=php_sqlite3.dll)>>"%php_ini%" -(echo ;Optional extensions, supplied for debugging)>>"%php_ini%" -(echo extension=php_recursionguard.dll)>>"%php_ini%" -(echo recursionguard.enabled=0 ;disabled due to minor performance impact, only enable this if you need it for debugging)>>"%php_ini%" -(echo ;extension=php_arraydebug.dll)>>"%php_ini%" -(echo.)>>"%php_ini%" -if "%PHP_JIT_ENABLE_ARG%"=="on" ( - (echo ; ---- ! WARNING ! ----)>>"%php_ini%" - (echo ; JIT can provide big performance improvements, but as of PHP %PHP_VER% it is still unstable. For this reason, it is disabled by default.)>>"%php_ini%" - (echo ; Enable it at your own risk. See https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.jit for possible options.)>>"%php_ini%" - (echo opcache.jit=off)>>"%php_ini%" - (echo opcache.jit_buffer_size=128M)>>"%php_ini%" - (echo.)>>"%php_ini%" -) -(echo ;WARNING: When loaded, xdebug 3.2.0 will cause segfaults whenever an uncaught error is thrown, even if xdebug.mode=off. Load it at your own risk.)>>"%php_ini%" -(echo ;zend_extension=php_xdebug.dll)>>"%php_ini%" -(echo ;https://xdebug.org/docs/all_settings#mode)>>"%php_ini%" -(echo xdebug.mode=off)>>"%php_ini%" -(echo xdebug.start_with_request=yes)>>"%php_ini%" -(echo ;The following overrides allow profiler, gc stats and traces to work correctly in ZTS)>>"%php_ini%" -(echo xdebug.profiler_output_name=cachegrind.%%s.%%p.%%r)>>"%php_ini%" -(echo xdebug.gc_stats_output_name=gcstats.%%s.%%p.%%r)>>"%php_ini%" -(echo xdebug.trace_output_name=trace.%%s.%%p.%%r)>>"%php_ini%" -(echo ;Optional experimental extensions)>>"%php_ini%" -(echo extension=php_encoding.dll)>>"%php_ini%" - -call :pm-echo "Xdebug is included, but disabled by default. To enable it, change 'xdebug.mode' in your php.ini file." - -REM TODO: more entries - -cd /D ..\.. - -REM this includes all the stuff necessary to run anything needing 2015, 2017 and 2019 in one package -call :pm-echo "Downloading Microsoft Visual C++ Redistributable 2015-2019" -wget https://aka.ms/vs/16/release/vc_redist.x64.exe -nv -O vc_redist.x64.exe >>"%log_file%" 2>&1 || exit 1 - -call :pm-echo "Checking PHP build works..." -bin\php\php.exe --version >>"%log_file%" 2>&1 || call :pm-fatal-error "PHP build isn't working" -bin\php\php.exe -m >>"%log_file%" 2>&1 - -call :pm-echo "Packaging build..." -set package_filename=php-%PHP_DISPLAY_VER%-%VC_VER%-%ARCH%.zip -if exist %package_filename% del /s /q %package_filename% -7z a -bd %package_filename% bin vc_redist.x64.exe >nul || call :pm-fatal-error "Failed to package the build" - -call :pm-echo "Created build package %package_filename%" -call :pm-echo "Moving debugging symbols to output directory..." -move "%SOURCES_PATH%\php-src\%ARCH%\%OUT_PATH_REL%_TS\php-debug-pack*.zip" . -call :pm-echo "Done?" - -exit 0 - -:check-vs-exists -set "VS_PATH=C:\%~3\Microsoft Visual Studio\%~1" -if exist "%VS_PATH%" ( - set CMAKE_TARGET=Visual Studio %~2 %~1 - call :pm-echo "Found Visual Studio %~1 in %VS_PATH%" - exit /B 0 -) else ( - call :pm-echo "DID NOT FIND VS %~1" - set CMAKE_TARGET= - set VS_PATH= - exit /B 1 -) - -:get-extension-zip-from-github: -call :pm-echo " - %~1: downloading %~2..." -call :get-zip https://github.com/%~3/%~4/archive/%~2.zip || exit /B 1 -move %~4-%~2 %~1 >>"%log_file%" 2>&1 || exit /B 1 -exit /B 0 - - -:get-zip -setlocal -PATH=%ORIG_PATH% -wget "%~1" -nv -O temp.zip >>"%log_file%" 2>&1 || call :pm-fatal-error "Failed to download %~1" -7z x -y temp.zip >nul || exit /B 1 -del /s /q temp.zip >nul || exit /B 1 -endlocal -@echo off -exit /B 0 - -:pm-fatal-error -call :pm-echo-error "%~1 - check compile.log for details" -exit 1 - -:pm-echo-error -call :pm-echo "[ERROR] %~1" -exit /B 0 - -:pm-echo -echo [PocketMine] %~1 -echo [PocketMine] %~1 >>"%log_file%" 2>&1 -exit /B 0 diff --git a/windows-compile-vs.ps1 b/windows-compile-vs.ps1 new file mode 100644 index 00000000..fa76534a --- /dev/null +++ b/windows-compile-vs.ps1 @@ -0,0 +1,573 @@ +$ErrorActionPreference="Stop" + +$PHP_MAJOR_VER="8.2" +$PHP_VER="$PHP_MAJOR_VER.25" +$PHP_GIT_REV="php-$PHP_VER" +$PHP_DISPLAY_VER="$PHP_VER" +$PHP_SDK_VER="2.3.0" +$ARCH="x64" + +#TODO: these should be selected by PHP base version +$VC_VER="vs16" +$CMAKE_TARGET="Visual Studio 16 2019" + +#### NOTE: Tags with "v" prefixes behave weirdly in the GitHub API. They'll be stripped in some places but not others. +#### Use commit hashes to avoid this. + +$LIBYAML_VER="0.2.5" +$PTHREAD_W32_VER="3.0.0" +$LEVELDB_MCPE_VER="1c7564468b41610da4f498430e795ca4de0931ff" #release not tagged +$LIBDEFLATE_VER="2335c047e91cac6fd04cb0fd2769380395149f15" #1.22 - see above note about "v" prefixes + +$PHP_PMMPTHREAD_VER="6.1.0" +$PHP_YAML_VER="2.2.4" +$PHP_CHUNKUTILS2_VER="0.3.5" +$PHP_IGBINARY_VER="3.2.16" +$PHP_LEVELDB_VER="317fdcd8415e1566fc2835ce2bdb8e19b890f9f3" #release not tagged +$PHP_CRYPTO_VER="abbe7cbf869f96e69f2ce897271a61d32f43c7c0" #release not tagged +$PHP_RECURSIONGUARD_VER="0.1.0" +$PHP_MORTON_VER="0.1.2" +$PHP_LIBDEFLATE_VER="0.2.1" +$PHP_XXHASH_VER="0.2.0" +$PHP_XDEBUG_VER="3.3.2" +$PHP_ARRAYDEBUG_VER="0.2.0" +$PHP_ENCODING_VER="0.3.0" + +function pm-echo { + param ([string] $message) + + echo "[PocketMine] $message" + echo "[PocketMine] $message" >> "$log_file" +} + +function pm-echo-error { + param ([string] $message) + + pm-echo "[ERROR] $message" +} + +function pm-fatal-error { + param ([string] $message) + + pm-echo-error $message + exit 1 +} + +$library = "" +$library_version = "" +function write-library { + param ([string] $library, [string] $version) + + Write-Host -NoNewline "[$library $version]" + $script:library = $library + $script:library_version = $version +} +function write-status { + param ([string] $status) + + Write-Host -NoNewline " $status..." + echo "[$library $library_version] $status..." >> $log_file +} +function write-download { + write-status "downloading" +} +function write-extracting { + write-status "extracting" +} +function write-configure { + write-status "configuring" +} +function write-compile { + write-status "compiling" +} +function write-install { + write-status "installing" +} +function write-done { + echo " done!" + $script:library = "" + $script:library_version = "" +} + +$log_file="$pwd\compile.log" +echo "" > "$log_file" +$outpath="$pwd" + +pm-echo "PHP compiler for Windows" +date >> "$log_file" + +pm-echo "Checking dependencies" + +$script_dependencies = @("git", "cmake") +foreach ($dep in $script_dependencies) { + $depInfo = Get-Command "$dep" -ErrorAction SilentlyContinue + if ($depInfo -eq $null) { + pm-fatal-error "$dep is required but can't be found in your PATH" + } else { + pm-echo "Found $dep in $($depInfo.Source)" + } +} + + + +pm-echo "Checking configuration options" + +$PHP_DEBUG_BUILD=0 +if ($env:PHP_DEBUG_BUILD -eq 1) { + $PHP_DEBUG_BUILD=1 +} + +$MSBUILD_CONFIGURATION="RelWithDebInfo" +$PHP_JIT_ENABLE_ARG="no" + +if ($PHP_DEBUG_BUILD -eq 0) { + $OUT_PATH_REL="Release" + $PHP_HAVE_DEBUG="enable-debug-pack" + pm-echo "Building release binaries with debugging symbols" +} else { + $OUT_PATH_REL="Debug" + $PHP_HAVE_DEBUG="enable-debug" + + #I don't like this, but YAML will crash if it's not built with the same target as PHP + $MSBUILD_CONFIGURATION="Debug" + pm-echo "Building debug binaries" +} + +if ($env:PHP_JIT_SUPPORT -eq 1) { + $PHP_JIT_ENABLE_ARG="yes" + pm-echo "Compiling JIT support in OPcache (unstable)" +} + +if ($env:PM_VERSION_MAJOR -eq $null) { + pm-fatal-error "Please specify PocketMine-MP major version by setting the PM_VERSION_MAJOR environment variable" +} +if ($env:PM_VERSION_MAJOR -lt 5) { + pm-fatal-error "PocketMine-MP 4.x and older are no longer supported" +} +$PM_VERSION_MAJOR=$env:PM_VERSION_MAJOR +pm-echo "Compiling with configuration for PocketMine-MP $PM_VERSION_MAJOR" + +if ($env:SOURCES_PATH -ne $null) { + $SOURCES_PATH=$env:SOURCES_PATH +} else { + $SOURCES_PATH="C:\pocketmine-php-$PHP_DISPLAY_VER-$($OUT_PATH_REL.ToLower())" +} +pm-echo "Using path $SOURCES_PATH for build sources" + +if (Test-Path "$pwd\bin") { + pm-echo "Deleting old binary folder..." + Remove-Item -Recurse -Force "$pwd\bin" 2>&1 +} +if (Test-Path $SOURCES_PATH) { + pm-echo "Deleting old workspace $SOURCES_PATH..." + Remove-Item -Recurse -Force $SOURCES_PATH 2>&1 +} + +$download_cache="$pwd\download_cache" +function download-file { + param ([string] $url, [string] $prefix) + + $cached_filename="$prefix-$($url.Substring($url.LastIndexOf("/") + 1))" + $cached_path="$download_cache\$cached_filename" + + if (!(Test-Path $download_cache)) { + mkdir $download_cache >> $log_file 2>&1 + } + + if (Test-Path $cached_path) { + echo "Cache hit for URL: $url" >> $log_file + } else { + echo "Downloading file from $url to $cached_path" >> $log_file + Invoke-WebRequest -Uri $url -OutFile $cached_path >> $log_file 2>&1 + } + if (!(Test-Path $cached_path)) { + pm-fatal-error "Failed to download file from $url" + } + + return $cached_path +} + +function append-file-utf8 { + param ([string] $line, [string] $file) + + Out-File -Append -FilePath $file -Encoding utf8 -InputObject $line +} + +function download-sdk { + write-library "PHP SDK" $PHP_SDK_VER + + write-download + $file = download-file "https://github.com/php/php-sdk-binary-tools/archive/refs/tags/php-sdk-$PHP_SDK_VER.zip" "php-sdk" + write-extracting + Expand-Archive -Path $file -DestinationPath $pwd >> $log_file 2>&1 + Move-Item "php-sdk-binary-tools-php-sdk-$PHP_SDK_VER" $SOURCES_PATH + write-done +} + +function sdk-command { + param ([string] $command, [string] $errorMessage = "") + + New-Item task.bat -Value $command >> $log_file 2>&1 + echo "Running SDK command: $command" >> $log_file + $wrap = "`"$SOURCES_PATH\phpsdk-$VC_VER-$ARCH.bat`" -t task.bat 2>&1" + echo "SDK wrapper command: $wrap" >> $log_file + (& cmd.exe /c $wrap) >> $log_file + $result=$LASTEXITCODE + if ($result -ne 0) { + if ($errorMessage -eq "") { + pm-fatal-error "Error code $result running SDK build command" + } else { + pm-fatal-error $errorMessage + } + } + Remove-Item task.bat +} + +function download-php-deps { + write-library "PHP prebuilt deps" "$PHP_MAJOR_VER/$VC_VER" + write-download + sdk-command "phpsdk_deps -u -t $VC_VER -b $PHP_MAJOR_VER -a $ARCH -f -d $DEPS_DIR || exit 1" + write-done +} + +function build-yaml { + write-library "yaml" $LIBYAML_VER + write-download + $file = download-file "https://github.com/yaml/libyaml/archive/$LIBYAML_VER.zip" "yaml" + write-extracting + Expand-Archive -Path $file -DestinationPath $pwd >> $log_file 2>&1 + Move-Item "libyaml-$LIBYAML_VER" libyaml >> $log_file 2>&1 + Push-Location libyaml + + write-configure + sdk-command "cmake -G `"$CMAKE_TARGET`"^` + -DCMAKE_PREFIX_PATH=`"$DEPS_DIR`"^` + -DCMAKE_INSTALL_PREFIX=`"$DEPS_DIR`"^` + -DBUILD_SHARED_LIBS=ON^` + `"$pwd`" || exit 1" + write-compile + sdk-command "msbuild ALL_BUILD.vcxproj /p:Configuration=$MSBUILD_CONFIGURATION /m || exit 1" + write-install + sdk-command "msbuild INSTALL.vcxproj /p:Configuration=$MSBUILD_CONFIGURATION /m || exit 1" + Copy-Item "$MSBUILD_CONFIGURATION\yaml.pdb" "$DEPS_DIR\bin" >> $log_file 2>&1 + write-done + Pop-Location +} + +function build-pthreads4w { + write-library "pthreads4w" $PTHREAD_W32_VER + write-download + $file = download-file "https://github.com/pmmp/DependencyMirror/releases/download/mirror/pthreads4w-code-v$PTHREAD_W32_VER.zip" "pthreads4w" + write-extracting + Expand-Archive -Path $file -DestinationPath $pwd >> $log_file 2>&1 + Move-Item "pthreads4w-code-*" pthreads4w >> $log_file 2>&1 + Push-Location pthreads4w + + write-compile + sdk-command "nmake VC || exit 1" + + write-install + Copy-Item "pthread.h" "$DEPS_DIR\include" >> $log_file 2>&1 + Copy-Item "sched.h" "$DEPS_DIR\include" >> $log_file 2>&1 + Copy-Item "semaphore.h" "$DEPS_DIR\include" >> $log_file 2>&1 + Copy-Item "_ptw32.h" "$DEPS_DIR\include" >> $log_file 2>&1 + Copy-Item "pthreadVC3.lib" "$DEPS_DIR\lib" >> $log_file 2>&1 + Copy-Item "pthreadVC3.dll" "$DEPS_DIR\bin" >> $log_file 2>&1 + Copy-Item "pthreadVC3.pdb" "$DEPS_DIR\bin" >> $log_file 2>&1 + write-done + Pop-Location +} + +function build-leveldb { + write-library "leveldb" $LEVELDB_MCPE_VER + write-download + $file = download-file "https://github.com/pmmp/leveldb/archive/$LEVELDB_MCPE_VER.zip" + write-extracting + Expand-Archive -Path $file -DestinationPath $pwd >> $log_file 2>&1 + Move-Item leveldb-* leveldb >> $log_file 2>&1 + Push-Location leveldb + + write-configure + sdk-command "cmake -G `"$CMAKE_TARGET`"^` + -DCMAKE_PREFIX_PATH=`"$DEPS_DIR`"^` + -DCMAKE_INSTALL_PREFIX=`"$DEPS_DIR`"^` + -DBUILD_SHARED_LIBS=ON^` + -DLEVELDB_BUILD_BENCHMARKS=OFF^` + -DLEVELDB_BUILD_TESTS=OFF^` + -DZLIB_LIBRARY=`"$DEPS_DIR\lib\zlib_a.lib`"^` + `"$pwd`" || exit 1" + + write-compile + sdk-command "msbuild ALL_BUILD.vcxproj /p:Configuration=$MSBUILD_CONFIGURATION /m || exit 1" + write-install + sdk-command "msbuild INSTALL.vcxproj /p:Configuration=$MSBUILD_CONFIGURATION /m || exit 1" + Copy-Item "$MSBUILD_CONFIGURATION\leveldb.pdb" "$DEPS_DIR\bin" >> $log_file 2>&1 + write-done + Pop-Location +} + +function build-libdeflate { + write-library "libdeflate" $LIBDEFLATE_VER + write-download + $file = download-file "https://github.com/ebiggers/libdeflate/archive/$LIBDEFLATE_VER.zip" + write-extracting + Expand-Archive -Path $file -DestinationPath $pwd >> $log_file 2>&1 + Move-Item libdeflate-* libdeflate >> $log_file 2>&1 + Push-Location libdeflate + + write-configure + #TODO: not sure why we have arch here but not on other cmake targets + sdk-command "cmake -G `"$CMAKE_TARGET`" -A `"$ARCH`"^` + -DCMAKE_PREFIX_PATH=`"$DEPS_DIR`"^` + -DCMAKE_INSTALL_PREFIX=`"$DEPS_DIR`"^` + -DLIBDEFLATE_BUILD_GZIP=OFF^` + -DLIBDEFLATE_BUILD_SHARED_LIB=ON^` + -DLIBDEFLATE_BUILD_STATIC_LIB=OFF^` + `"$pwd`" || exit 1" + write-compile + sdk-command "msbuild ALL_BUILD.vcxproj /p:Configuration=$MSBUILD_CONFIGURATION /m || exit 1" + write-install + sdk-command "msbuild INSTALL.vcxproj /p:Configuration=$MSBUILD_CONFIGURATION /m || exit 1" + Copy-Item "$MSBUILD_CONFIGURATION\deflate.pdb" "$DEPS_DIR\bin" >> $log_file 2>&1 + write-done + Pop-Location +} + +function download-php { + write-library "PHP" $PHP_VER + write-download + + $file = download-file "https://github.com/php/php-src/archive/$PHP_GIT_REV.zip" "php" + write-extracting + Expand-Archive -Path $file -DestinationPath $pwd >> $log_file 2>&1 + Move-Item "php-src-$PHP_GIT_REV" php-src >> $log_file 2>&1 + write-done +} + +function get-extension-zip { + param ([string] $name, [string] $version, [string] $url, [string] $extractedName) + + write-library "php-ext $name" $version + write-download + $file = download-file $url "php-ext-$name" + write-extracting + Expand-Archive -Path $file -DestinationPath $pwd >> $log_file 2>&1 + write-done +} + +function get-github-extension { + param ([string] $name, [string] $version, [string] $user, [string] $repo, [string] $versionPrefix) + get-extension-zip $name $version "https://github.com/$user/$repo/archive/$versionPrefix$version.zip" "$repo-$version" +} + +function download-php-extensions { + Push-Location "$SOURCES_PATH\php-src\ext" >> $log_file 2>&1 + get-github-extension "pmmpthread" $PHP_PMMPTHREAD_VER "pmmp" "ext-pmmpthread" + get-github-extension "yaml" $PHP_YAML_VER "php" "pecl-file_formats-yaml" + get-github-extension "chunkutils2" $PHP_CHUNKUTILS2_VER "pmmp" "ext-chunkutils2" + get-github-extension "igbinary" $PHP_IGBINARY_VER "igbinary" "igbinary" + get-github-extension "leveldb" $PHP_LEVELDB_VER "pmmp" "php-leveldb" + get-github-extension "recursionguard" $PHP_RECURSIONGUARD_VER "pmmp" "ext-recursionguard" + get-github-extension "morton" $PHP_MORTON_VER "pmmp" "ext-morton" + get-github-extension "libdeflate" $PHP_LIBDEFLATE_VER "pmmp" "ext-libdeflate" + get-github-extension "xxhash" $PHP_XXHASH_VER "pmmp" "ext-xxhash" + get-github-extension "xdebug" $PHP_XDEBUG_VER "xdebug" "xdebug" + get-github-extension "arraydebug" $PHP_ARRAYDEBUG_VER "pmmp" "ext-arraydebug" + get-github-extension "encoding" $PHP_ENCODING_VER "pmmp" "ext-encoding" + + write-library "php-ext crypto" $PHP_CRYPTO_VER + write-download + (& cmd.exe /c "git clone https://github.com/bukka/php-crypto.git crypto 2>&1") >> $log_file + Push-Location crypto + write-status "preparing" + (& cmd.exe /c "git checkout $PHP_CRYPTO_VER 2>&1") >> $log_file + (& cmd.exe /c "git submodule update --init --recursive 2>&1") >> $log_file + write-done + Pop-Location + + Pop-Location +} + +download-sdk +cd $SOURCES_PATH >> $log_file 2>&1 + +pm-echo "Checking that SDK can find Visual Studio" +#using CMAKE_TARGET for this is a bit meh but it's human readable at least +sdk-command "exit /b 0" "Please install $CMAKE_TARGET" + +$DEPS_DIR="$SOURCES_PATH\deps" +#custom libs depend on some standard libs, so prepare these first +#a bit annoying because this part of the build is slow and makes it take longer to find problems +download-php-deps + +$LIB_BUILD_DIR="$SOURCES_PATH\deps_build" + +mkdir $LIB_BUILD_DIR >> $log_file 2>&1 + +cd $LIB_BUILD_DIR >> $log_file 2>&1 + +build-pthreads4w +build-yaml +#these two both need zlib from the standard deps +build-leveldb +build-libdeflate + +cd $SOURCES_PATH >> $log_file 2>&1 + +download-php +download-php-extensions + +cd "$SOURCES_PATH\php-src" +write-library "PHP" $PHP_VER +write-configure + +sdk-command "buildconf.bat" +sdk-command "configure^` + --with-mp=auto^` + --with-prefix=pocketmine-php-bin^` + --$PHP_HAVE_DEBUG^` + --disable-all^` + --disable-cgi^` + --enable-cli^` + --enable-zts^` + --enable-pdo^` + --enable-arraydebug=shared^` + --enable-bcmath^` + --enable-calendar^` + --enable-chunkutils2=shared^` + --enable-com-dotnet^` + --enable-ctype^` + --enable-encoding=shared^` + --enable-fileinfo=shared^` + --enable-filter^` + --enable-hash^` + --enable-igbinary=shared^` + --enable-json^` + --enable-mbstring^` + --enable-morton^` + --enable-opcache^` + --enable-opcache-jit=$PHP_JIT_ENABLE_ARG^` + --enable-phar^` + --enable-recursionguard=shared^` + --enable-sockets^` + --enable-tokenizer^` + --enable-xmlreader^` + --enable-xmlwriter^` + --enable-xxhash^` + --enable-zip^` + --enable-zlib^` + --with-bz2=shared^` + --with-crypto=shared^` + --with-curl^` + --with-dom^` + --with-gd=shared^` + --with-gmp^` + --with-iconv^` + --with-leveldb=shared^` + --with-libdeflate=shared^` + --with-libxml^` + --with-mysqli=shared^` + --with-mysqlnd^` + --with-openssl^` + --with-pcre-jit^` + --with-pmmpthread=shared^` + --with-pmmpthread-sockets^` + --with-simplexml^` + --with-sodium^` + --with-sqlite3=shared^` + --with-xdebug=shared^` + --with-xdebug-compression^` + --with-xml^` + --with-yaml^` + --with-pdo-mysql^` + --with-pdo-sqlite^` + --without-readline" + +write-compile +sdk-command "nmake" + +write-install +sdk-command "nmake snap" + +#remove ICU DLLs copied unnecessarily by nmake snap - this needs to be removed if we ever have ext/intl as a dependency +Remove-Item "$SOURCES_PATH\php-src\$ARCH\Release_TS\php-$PHP_DISPLAY_VER\icu*.dll" >> $log_file 2>&1 +#remove enchant dependencies which are unnecessarily copied - this needs to be removed if we ever have ext/enchant as a dependency +Remove-Item "$SOURCES_PATH\php-src\$ARCH\Release_TS\php-$PHP_DISPLAY_VER\glib-*.dll" >> $log_file 2>&1 +Remove-Item "$SOURCES_PATH\php-src\$ARCH\Release_TS\php-$PHP_DISPLAY_VER\gmodule-*.dll" >> $log_file 2>&1 +Remove-Item -Recurse "$SOURCES_PATH\php-src\$ARCH\Release_TS\php-$PHP_DISPLAY_VER\lib\enchant\" >> $log_file 2>&1 + +cd $outpath >> $log_file 2>&1 +Move-Item -Force "$SOURCES_PATH\php-src\$ARCH\$($OUT_PATH_REL)_TS\php-debug-pack-*.zip" $outpath +Remove-Item -Recurse bin -ErrorAction Continue >> $log_file 2>&1 +mkdir bin >> $log_file 2>&1 +Move-Item "$SOURCES_PATH\php-src\$ARCH\$($OUT_PATH_REL)_TS\php-$PHP_DISPLAY_VER" bin\php + +$php_exe = "$outpath\bin\php\php.exe" + +if (!(Test-Path $php_exe)) { + pm-fatal-error "Something has gone wrong. php.exe not found" +} +write-status "generating php.ini" + +$php_ini="$outpath\bin\php\php.ini" + +#all this work to make PS output utf-8/ascii instead of utf-16 :( +Out-File -FilePath $php_ini -Encoding ascii -InputObject ";Custom PocketMine-MP php.ini file" +append-file-utf8 "memory_limit=1024M" $php_ini +append-file-utf8 "display_errors=1" $php_ini +append-file-utf8 "display_startup_errors=1" $php_ini +append-file-utf8 "error_reporting=-1" $php_ini +append-file-utf8 "zend.assertions=-1" $php_ini +append-file-utf8 "extension_dir=ext" $php_ini +append-file-utf8 "extension=php_pmmpthread.dll" $php_ini +append-file-utf8 "extension=php_openssl.dll" $php_ini +append-file-utf8 "extension=php_chunkutils2.dll" $php_ini +append-file-utf8 "extension=php_igbinary.dll" $php_ini +append-file-utf8 "extension=php_leveldb.dll" $php_ini +append-file-utf8 "extension=php_crypto.dll" $php_ini +append-file-utf8 "extension=php_libdeflate.dll" $php_ini +append-file-utf8 "igbinary.compact_strings=0" $php_ini +append-file-utf8 "zend_extension=php_opcache.dll" $php_ini +append-file-utf8 "opcache.enable=1" $php_ini +append-file-utf8 "opcache.enable_cli=1" $php_ini +append-file-utf8 "opcache.save_comments=1" $php_ini +append-file-utf8 "opcache.validate_timestamps=1" $php_ini +append-file-utf8 "opcache.revalidate_freq=0" $php_ini +append-file-utf8 "opcache.file_update_protection=0" $php_ini +append-file-utf8 "opcache.optimization_level=0x7FFEBFFF" $php_ini +append-file-utf8 "opcache.cache_id=PHP_BINARY ;prevent sharing SHM between different binaries - they won't work because of ASLR" $php_ini +append-file-utf8 ";Optional extensions, supplied for plugin use" $php_ini +append-file-utf8 "extension=php_fileinfo.dll" $php_ini +append-file-utf8 "extension=php_gd.dll" $php_ini +append-file-utf8 "extension=php_mysqli.dll" $php_ini +append-file-utf8 "extension=php_sqlite3.dll" $php_ini +append-file-utf8 ";Optional extensions, supplied for debugging" $php_ini +append-file-utf8 "extension=php_recursionguard.dll" $php_ini +append-file-utf8 "recursionguard.enabled=0 ;disabled due to minor performance impact, only enable this if you need it for debugging" $php_ini +append-file-utf8 ";extension=php_arraydebug.dll" $php_ini +append-file-utf8 "" $php_ini +if ($PHP_JIT_ENABLE_ARG -eq "on") { + append-file-utf8 "; ---- ! WARNING ! ----" $php_ini + append-file-utf8 "; JIT can provide big performance improvements, but as of PHP %PHP_VER% it is still unstable. For this reason, it is disabled by default." $php_ini + append-file-utf8 "; Enable it at your own risk. See https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.jit for possible options." $php_ini + append-file-utf8 "opcache.jit=off" $php_ini + append-file-utf8 "opcache.jit_buffer_size=128M" $php_ini + append-file-utf8 "" $php_ini +} +append-file-utf8 ";WARNING: When loaded, xdebug 3.2.0 will cause segfaults whenever an uncaught error is thrown, even if xdebug.mode=off. Load it at your own risk." $php_ini +append-file-utf8 ";zend_extension=php_xdebug.dll" $php_ini +append-file-utf8 ";https://xdebug.org/docs/all_settings#mode" $php_ini +append-file-utf8 "xdebug.mode=off" $php_ini +append-file-utf8 "xdebug.start_with_request=yes" $php_ini +append-file-utf8 ";The following overrides allow profiler, gc stats and traces to work correctly in ZTS" $php_ini +append-file-utf8 "xdebug.profiler_output_name=cachegrind.%s.%p.%r" $php_ini +append-file-utf8 "xdebug.gc_stats_output_name=gcstats.%s.%p.%r" $php_ini +append-file-utf8 "xdebug.trace_output_name=trace.%s.%p.%r" $php_ini +append-file-utf8 ";Optional experimental extensions" $php_ini +append-file-utf8 "extension=php_encoding.dll" $php_ini +write-done +pm-echo "Xdebug is included, but disabled by default. To enable it, change 'xdebug.mode' in your php.ini file." + +pm-echo "NOTE: You may need to install VC++ Redistributable for the binaries to work. Download it here: https://aka.ms/vs/16/release/vc_redist.x64.exe" +pm-echo "PHP binary files installed in $outpath\bin" +pm-echo "If the binary doesn't work, please report an issue at https://github.com/pmmp/PHP-Binaries and attach the `"compile.log`" file" \ No newline at end of file