diff --git a/.gitignore b/.gitignore index 49acc9f2e1788..c2c77283d96a7 100644 --- a/.gitignore +++ b/.gitignore @@ -297,3 +297,4 @@ tmp-php.ini !/ext/fileinfo/magicdata.patch !/ext/pcre/pcre2lib/config.h !/win32/build/Makefile +php-sdk*/ diff --git a/cmd/compile_x64.bat b/cmd/compile_x64.bat new file mode 100644 index 0000000000000..5e0e3d16ac1dd --- /dev/null +++ b/cmd/compile_x64.bat @@ -0,0 +1,6 @@ +@echo off +if EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" ( + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" && cmd\getopt.bat %* && set ARCH=x64&& cmd\make_php.bat +) else if EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise" ( + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && .\cmd\getopt.bat %* && set ARCH=x64&& .\cmd\make_php.bat +) diff --git a/cmd/compile_x86.bat b/cmd/compile_x86.bat new file mode 100644 index 0000000000000..47c52e88d66bb --- /dev/null +++ b/cmd/compile_x86.bat @@ -0,0 +1,6 @@ +@echo off +if EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" ( + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat" && cmd\getopt.bat %* && set ARCH=x86&& cmd\make_php.bat +) else if EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise" ( + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars32.bat" && .\cmd\getopt.bat %* && set ARCH=x86&& .\cmd\make_php.bat +) diff --git a/cmd/getopt.bat b/cmd/getopt.bat new file mode 100644 index 0000000000000..bad12815ecee2 --- /dev/null +++ b/cmd/getopt.bat @@ -0,0 +1,20 @@ +@echo off +set SNAP= +set OPTIONS= +:parse +if "%~1" == "" goto endparse +if "%~1" == "--php" set PHP_VER=%2 +if "%~1" == "--option" set OPTIONS=%2 %OPTIONS% +if "%~1" == "--snap" set SNAP=snap +if "%~1" == "--ext" ( set EXT=--with-%2&& set EXTNAME=%2 ) +if "%~1" == "--ts" set PHP_TS=_TS +if "%~1" == "--shared" ( set EXT=%EXT%=shared && set SHARE==shared ) +if "%~1" == "--deps" set DEPS=%2 +if "%~1" == "--arch" set ARCH=%2 + +shift +goto parse +:endparse +if not defined PHP_VER ( + set PHP_VER=8.2.5 +) diff --git a/cmd/make_php.bat b/cmd/make_php.bat new file mode 100644 index 0000000000000..52813f494d13b --- /dev/null +++ b/cmd/make_php.bat @@ -0,0 +1,36 @@ +@echo off +if NOT DEFINED PHP_VER set PHP_VER=8.2.5 + +if "%PHP_VER%" == "7.4.33" ( + set CRT=vc15 +) else ( + set CRT=vs16 +) + +if NOT EXIST php-sdk ( + curl -L https://github.com/php/php-sdk-binary-tools/archive/refs/tags/php-sdk-2.2.0.tar.gz | tar xzf - && ren php-sdk-binary-tools-php-sdk-2.2.0 php-sdk +) + +if NOT DEFINED ARCH set ARCH=x64 +if NOT DEFINED PHP_TS set ZTS=--disable-zts + +if NOT EXIST php-sdk\phpdev\%CRT%\%ARCH% (mkdir php-sdk\phpdev\%CRT%\%ARCH%) +if NOT EXIST php-sdk\phpdev\%CRT%\%ARCH%\php-%PHP_VER% ( + mklink /j "php-sdk\phpdev\%CRT%\%ARCH%\php-%PHP_VER%" . +) + +cd php-sdk + +set "VSCMD_START_DIR=%CD%" +set "__VSCMD_ARG_NO_LOGO=yes" +set PHP_SDK_ROOT_PATH=%~dp0 +set PHP_SDK_ROOT_PATH=%PHP_SDK_ROOT_PATH:~0,-1% +set PHP_SDK_RUN_FROM_ROOT=.\php-sdk + +copy /Y ..\cmd\phpsdk_setshell.bat bin\phpsdk_setshell.bat + +bin\phpsdk_setshell.bat %CRT% %ARCH% && bin\phpsdk_setvars.bat && bin\phpsdk_dumpenv.bat && bin\phpsdk_buildtree.bat phpdev && cd php-%PHP_VER% && ..\..\..\..\bin\phpsdk_deps -u --no-backup && if EXIST config.nice.bat ( + config.nice.bat && nmake %SNAP% && cd ..\..\..\..\.. +) else ( + buildconf --force --add-modules-dir=..\pecl\ && configure --enable-cli --with-ffi --with-iconv%SHARE% --enable-phar%SHARE% --enable-filter%SHARE% --with-openssl%SHARE% --enable-sockets%SHARE% --enable-mbstring%SHARE% --with-libxml%SHARE% --enable-fileinfo%SHARE% --enable-xmlwriter%SHARE% --enable-tokenizer%SHARE% --enable-embed %EXT% %ZTS% %OPTIONS% && nmake %SNAP% && cd ..\..\..\..\.. +) diff --git a/cmd/phpsdk_setshell.bat b/cmd/phpsdk_setshell.bat new file mode 100644 index 0000000000000..78dadb0a33b25 --- /dev/null +++ b/cmd/phpsdk_setshell.bat @@ -0,0 +1,175 @@ +@echo off + +if not defined PHP_SDK_RUN_FROM_ROOT ( + echo This script should not be run directly. + echo Use starter scripts looking like phpsdk-^-^.bat in the PHP SDK root instead. + goto out_error +) + + +if "%1"=="" goto :help +if "%1"=="/?" goto :help +if "%1"=="-h" goto :help +if "%1"=="--help" goto :help +if "%2"=="" goto :help + +cmd /c "exit /b 0" + +set PHP_SDK_VS=%1 +if /i not "%PHP_SDK_VS:~0,2%"=="vc" ( + if /i not "%PHP_SDK_VS:~0,2%"=="vs" ( +:malformed_vc_string + echo Malformed CRT string "%1" + set PHP_SDK_VS= + goto out_error + ) +) +if ""=="%PHP_SDK_VS:~2%" ( + goto malformed_vc_string +) +set /a TMP_CHK=%PHP_SDK_VS:~2% +if 14 gtr %TMP_CHK% ( + if "0"=="%TMP_CHK%" ( + if not "0"=="%PHP_SDK_VS:~2%" ( + set TMP_CHK= + goto malformed_vc_string + ) + ) + + echo At least vc14 is required + set PHP_SDK_VS= + set TMP_CHK= + goto out_error +) +set PHP_SDK_VS_NUM=%TMP_CHK% +set TMP_CHK= + +if /i not "%2"=="x64" ( + if /i not "%2"=="x86" ( + echo Unsupported arch "%2" + goto out_error + ) +) + +set PHP_SDK_ARCH=%2 + +rem check OS arch +set TMPKEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion +reg query "%TMPKEY%" /v "ProgramFilesDir (x86)" >nul 2>nul +if not errorlevel 1 ( + set PHP_SDK_OS_ARCH=x64 +) else ( + if /i "%PHP_SDK_ARCH%"=="x64" ( + echo 32-bit OS detected, native 64-bit toolchain is unavailable. + goto out_error + ) + set PHP_SDK_OS_ARCH=x86 +) +set TMPKEY= + +rem get vc base dir +if 15 gtr %PHP_SDK_VS_NUM% ( + if /i "%PHP_SDK_OS_ARCH%"=="x64" ( + set TMPKEY=HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\%PHP_SDK_VS:~2%.0\Setup\VC + ) else ( + set TMPKEY=HKLM\SOFTWARE\Microsoft\VisualStudio\%PHP_SDK_VS:~2%.0\Setup\VC + ) + reg query !TMPKEY! /v ProductDir >nul 2>&1 + if errorlevel 1 ( + echo Couldn't determine VC%PHP_SDK_VS:~2% directory + goto out_error; + ) + for /f "tokens=2*" %%a in ('reg query !TMPKEY! /v ProductDir') do set PHP_SDK_VC_DIR=%%b +) else ( + rem build the version range, e.g. "[15,16]" + set /a PHP_SDK_VS_RANGE=PHP_SDK_VS_NUM + 1 + set PHP_SDK_VS_RANGE="[%PHP_SDK_VS_NUM%,!%PHP_SDK_VS_RANGE%!]" + for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text -prerelease') do ( + set PHP_SDK_VC_DIR=%%b\VC + ) + if not exist "!PHP_SDK_VC_DIR!" ( + for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -products Microsoft.VisualStudio.Product.BuildTools -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do ( + set PHP_SDK_VC_DIR=%%b\VC + ) + if not exist "!PHP_SDK_VC_DIR!" ( + rem check for a preview release + for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -prerelease -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do ( + set PHP_SDK_VC_DIR=%%b\VC + ) + if not exist "!PHP_SDK_VC_DIR!" ( + echo Could not determine '%PHP_SDK_VS%' directory + ) + ) + ) + set VSCMD_ARG_no_logo=nologo +) +set TMPKEY= +set PHP_SDK_VS_RANGE= + +if 15 gtr %PHP_SDK_VS_NUM% ( + rem get sdk dir + rem if 10.0 is available, it's ok + if /i "%PHP_SDK_OS_ARCH%"=="x64" ( + set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0 + ) else ( + set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0 + ) + for /f "tokens=2*" %%a in ('reg query "!TMPKEY!" /v InstallationFolder') do ( + for /f "tokens=2*" %%c in ('reg query "!TMPKEY!" /v ProductVersion') do ( + if exist "%%bInclude\%%d.0\um\Windows.h" ( + goto got_sdk + ) + ) + ) + + rem Otherwise 8.1 should be available anyway + if /i "%PHP_SDK_OS_ARCH%"=="x64" ( + set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.1 + ) else ( + set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.1 + ) + for /f "tokens=2*" %%a in ('reg query "!TMPKEY!" /v InstallationFolder') do ( + if exist "%%b\Include\um\Windows.h" ( + goto got_sdk + ) + ) + + echo Windows SDK not found. + goto out_error; +:got_sdk + set TMPKEY= +) + +if /i "%PHP_SDK_ARCH%"=="x64" ( + if 15 gtr %PHP_SDK_VS_NUM% ( + set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\vcvarsall.bat" amd64 -vcvars_ver=%vcvars_ver% + ) else ( + set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\Auxiliary\Build\vcvarsall.bat" amd64 -vcvars_ver=%vcvars_ver% + ) +) else ( + if 15 gtr %PHP_SDK_VS_NUM% ( + set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\vcvarsall.bat" x86 -vcvars_ver=%vcvars_ver% + ) else ( + set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\Auxiliary\Build\vcvarsall.bat" x86 -vcvars_ver=%vcvars_ver% + ) +) + +rem echo Visual Studio VC path %PHP_SDK_VC_DIR% +rem echo Windows SDK path %PHP_SDK_WIN_SDK_DIR% + + +goto out + +:help + echo "Start Visual Studio command line for PHP SDK" + echo "Usage: %0 vc arch" + echo nul + +:out_error + exit /b 3 + +:out +rem echo Shell configuration complete + exit /b 0 + +goto :eof diff --git a/cmd/windows_run_test.bat b/cmd/windows_run_test.bat new file mode 100644 index 0000000000000..164a80dc4632c --- /dev/null +++ b/cmd/windows_run_test.bat @@ -0,0 +1,21 @@ +@echo off +call cmd\getopt.bat %* + +if "%PHP_VER%" == "7.4.33" ( + set CRT=vc15 +) else ( + set CRT=vs16 +) + +if NOT DEFINED ARCH set ARCH=x64 + +dir php-sdk\phpdev\%CRT%\%ARCH%\php-%PHP_VER%\%ARCH%\Release%PHP_TS% +dir php-sdk\phpdev\%CRT%\%ARCH%\php-%PHP_VER%\%ARCH%\Release%PHP_TS%\php-%PHP_VER% +dir php-sdk\phpdev\%CRT%\%ARCH%\php-%PHP_VER%\%ARCH%\Release%PHP_TS%\pecl-%PHP_VER% +cd php-sdk\phpdev\%CRT%\%ARCH%\php-%PHP_VER%\%ARCH%\Release%PHP_TS%\php-%PHP_VER% +IF EXIST php.exe ( +dir ext +php -m +php -v +php ..\..\..\run-tests.php --offline --show-diff --set-timeout 240 ..\..\..\tests +) diff --git a/ext/skeleton/.github/workflows/CentOS-7-release.yml.skeleton b/ext/skeleton/.github/workflows/CentOS-7-release.yml.skeleton new file mode 100644 index 0000000000000..87da0a8d22fc3 --- /dev/null +++ b/ext/skeleton/.github/workflows/CentOS-7-release.yml.skeleton @@ -0,0 +1,58 @@ +name: CentOS 7 Release + +on: + release: + types: [published, edited] + +jobs: + centos_7: + name: PHP + strategy: + fail-fast: false + matrix: + php-versions: ['74', '80', '81', '82'] + runs-on: ubuntu-latest + container: centos:7 + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Install PHP and Build tools + run: | + yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm https://rpms.remirepo.net/enterprise/remi-release-7.rpm -y + yum update -y + yum-config-manager --disable 'remi-php*' && yum-config-manager --enable remi-php${{ matrix.php-versions }} + yum install git make gcc gcc-c++ binutils glibc-devel autoconf libtool bison re2c automake libxml2-devel sudo php-devel which php-pear -y + - name: Build ext-%EXTNAME% + run: | + phpize + ./configure --with-%EXTNAME%=$(readlink -f `pwd`/%DEPS%) + make + make install + - name: Setup rpm + id: setup-rpm + run: | + mkdir -p .rpmpkg/"$(php-config --extension-dir)" + cp -f modules/%EXTNAME%.so .rpmpkg/"$(php-config --extension-dir)" + chmod +x ./cmd/os_codename.sh + echo "OS_CODENAME=$(./cmd/os_codename.sh)" >> $GITHUB_OUTPUT + - name: Create rpm package + id: build-rpm-action + uses: jiro4989/build-rpm-action@v2 + with: + summary: '%DEPS% PHP wrapper.' + package: ext_%EXTNAME%-php${{ matrix.php-versions }}_${{ steps.setup-rpm.outputs.OS_CODENAME }} + package_root: .rpmpkg + maintainer: github@maintainer + version: ${{ github.ref }} # refs/tags/v*.*.* + arch: 'x86_64' + desc: '%EXTNAME% provides access to underlying %DEPS% functions.' + - name: Upload the rpm binary artifacts + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ./*.rpm + asset_name: ext_%EXTNAME%_php${{ matrix.php-versions }}-${{ github.event.release.tag_name }}_centos7 + tag: ${{ github.ref }} + overwrite: true + file_glob: true + body: ext_%EXTNAME%_php${{ matrix.php-versions }}-${{ github.event.release.tag_name }} for ${{ steps.setup-rpm.outputs.OS_CODENAME }} diff --git a/ext/skeleton/.github/workflows/CentOS-stream-release.yml.skeleton b/ext/skeleton/.github/workflows/CentOS-stream-release.yml.skeleton new file mode 100644 index 0000000000000..eed286136e0eb --- /dev/null +++ b/ext/skeleton/.github/workflows/CentOS-stream-release.yml.skeleton @@ -0,0 +1,69 @@ +name: CentOS Stream Release + +on: + release: + types: [published, edited] + +jobs: + stream_8: + name: PHP + strategy: + fail-fast: false + matrix: + php-versions: ['7.4', '8.0', '8.1', '8.2'] + runs-on: ubuntu-latest + container: centos:latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Install PHP and Build tools + run: | + sed -i "s/mirrorlist/#mirrorlist/g" /etc/yum.repos.d/CentOS-* + sed -i "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-* + dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y + /usr/bin/crb enable + dnf install centos-release-stream -y + dnf swap centos-{linux,stream}-repos -y + dnf distro-sync -y + dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y + dnf update -y + dnf install yum-utils -y + dnf module list php + dnf module reset php + dnf module install -y php:remi-${{ matrix.php-versions }} + dnf install sudo git php-devel libtool php-pear -y + - name: Build ext-%EXTNAME% + run: | + phpize + ./configure --with-%EXTNAME%=$(readlink -f `pwd`/%DEPS%) + make + make install + - name: Setup rpm + id: setup-rpm + run: | + mkdir -p .rpmpkg/"$(php-config --extension-dir)" + cp -f modules/%EXTNAME%.so .rpmpkg/"$(php-config --extension-dir)" + chmod +x ./cmd/os_codename.sh + echo "OS_CODENAME=$(./cmd/os_codename.sh)" >> $GITHUB_OUTPUT + - name: Create rpm package + id: build-rpm-action + uses: jiro4989/build-rpm-action@v2 + with: + summary: '%DEPS% PHP wrapper.' + package: ext_%EXTNAME%-php${{ matrix.php-versions }}_${{ steps.setup-rpm.outputs.OS_CODENAME }} + package_root: .rpmpkg + maintainer: github@maintainer + version: ${{ github.ref }} # refs/tags/v*.*.* + arch: 'x86_64' + desc: '%EXTNAME% provides access to underlying %DEPS% functions.' + - name: Upload the rpm binary artifacts + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ./*.rpm + asset_name: ext_%EXTNAME%_php${{ matrix.php-versions }}-${{ github.event.release.tag_name }}_stream8 + tag: ${{ github.ref }} + overwrite: true + file_glob: true + body: ext_%EXTNAME%_php${{ matrix.php-versions }}-${{ github.event.release.tag_name}} for ${{ steps.setup-rpm.outputs.OS_CODENAME }} diff --git a/ext/skeleton/.github/workflows/Ubuntu-release.yml.skeleton b/ext/skeleton/.github/workflows/Ubuntu-release.yml.skeleton new file mode 100644 index 0000000000000..cd7e2ee4a736a --- /dev/null +++ b/ext/skeleton/.github/workflows/Ubuntu-release.yml.skeleton @@ -0,0 +1,63 @@ +name: Ubuntu Release + +on: + release: + types: [published, edited] + +jobs: + multi: + name: ${{ matrix.operating-system }} CI - PHP ${{ matrix.php-versions }}-${{ matrix.threads }} + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-20.04, ubuntu-22.04] + php-versions: ['7.4', '8.0', '8.1', '8.2'] + threads: [ts, nts] + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + coverage: none + env: + phpts: ${{ matrix.threads }} # specify ts or nts + - name: Build ext-%EXTNAME% + run: | + phpize + ./configure --with-%EXTNAME%=$(readlink -f `pwd`/%DEPS%) + make + sudo make install + - name: Setup deb + id: setup-deb + run: | + mkdir -p .debpkg/"$(php-config --extension-dir)" + cp -f modules/%EXTNAME%.so .debpkg/"$(php-config --extension-dir)" + chmod +x ./cmd/os_codename.sh + echo "OS_CODENAME=$(sudo ./cmd/os_codename.sh)" >> $GITHUB_OUTPUT + # mkdir -p .debpkg/DEBIAN + # echo -e 'echo "extension=%EXTNAME%.so" >> "$(php -r 'echo php_ini_loaded_file();')"' > .debpkg/DEBIAN/postinst + # chmod +x .debpkg/DEBIAN/postinst + - name: Create deb package + id: build-deb-action + uses: jiro4989/build-deb-action@v2 + with: + package: ext-%EXTNAME% + package_root: .debpkg + maintainer: github@maintainer + version: ${{ github.ref }} # refs/tags/v*.*.* + arch: 'amd64' + depends: 'php-common' + desc: '%EXTNAME% provides access to underlying %DEPS% functions.' + - name: Upload the deb binary artifacts + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{steps.build-deb-action.outputs.file_name}} + asset_name: ext_%EXTNAME%_${{ github.event.release.tag_name }}_php${{ matrix.php-versions }}_${{ matrix.threads }}_${{ matrix.operating-system }}_amd64.deb + tag: ${{ github.ref }} + overwrite: true + file_glob: false + body: ${{steps.build-deb-action.outputs.file_name}} for ${{ steps.setup-deb.outputs.OS_CODENAME }} diff --git a/ext/skeleton/.github/workflows/Windows-release.yml b/ext/skeleton/.github/workflows/Windows-release.yml new file mode 100644 index 0000000000000..41a21ab8620d2 --- /dev/null +++ b/ext/skeleton/.github/workflows/Windows-release.yml @@ -0,0 +1,37 @@ +# GitHub Action for PHP with extensions +name: Windows Release + +on: + release: + types: [published, edited] + +jobs: + windows: + name: Windows + defaults: + run: + shell: cmd + runs-on: windows-2019 + strategy: + fail-fast: false + matrix: + php: ['8.0.28', '8.1.18', '8.2.5'] + thread: [nts, ts] + arch: [x86, x64] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Build PHP ${{ matrix.php }}-${{ matrix.thread }} with dependency and extension + run: .\cmd\compile_${{ matrix.arch }}.bat --php ${{ matrix.php }} --${{ matrix.thread }} + - name: Create PHP ${{ matrix.php }}-${{ matrix.thread }} Zip archive with dependency and extension + run: .\cmd\compile_${{ matrix.arch }}.bat --php ${{ matrix.php }} --${{ matrix.thread }} --snap + - name: Upload the windows binary artifacts + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: php-sdk\phpdev\vs16\${{ matrix.arch }}\php-${{matrix.php}}\${{ matrix.arch }}\Release*\*.zip + asset_name: php-${{matrix.php}}-${{ matrix.thread }}-Win32-vs16-${{ matrix.arch }}_static_ext_%EXTNAME%-${{ github.event.release.tag_name }}.zip + tag: ${{ github.ref }} + overwrite: true + file_glob: true + body: "Static PHP-${{matrix.php}}-${{ matrix.thread }} Windows build, includes %DEPS%, %EXTNAME% with all other extensions and Zip archives" diff --git a/ext/skeleton/.github/workflows/macOS-release.yml.skeleton b/ext/skeleton/.github/workflows/macOS-release.yml.skeleton new file mode 100644 index 0000000000000..1b5ad35bc6042 --- /dev/null +++ b/ext/skeleton/.github/workflows/macOS-release.yml.skeleton @@ -0,0 +1,50 @@ +# GitHub Action for PHP with extensions +name: Apple macOS Release + +on: + release: + types: [published, edited] + +jobs: + apple: + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [macos-10.15, macos-11, macos-latest] + php-versions: ['7.4', '8.0', '8.1', '8.2'] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php + with: + php-version: ${{ matrix.php-versions }} + tools: pecl + extensions: curl, fileinfo, mbstring, openssl, simplexml, dom, sockets, sodium, ffi, opcache + - name: Brew install + run: brew install automake + - name: Build ext-%EXTNAME% + run: | + phpize + ./configure + make + make install + - name: Get runner environment variables + id: runner + uses: TheTechsTech/action-environment-info@v1.0.5 + - name: Create binary archive + id: archive + run: | + tar -zcvf ext_%EXTNAME%-${{ github.ref_name }}_php${{ matrix.php-versions }}_macos-${{steps.runner.outputs.version}}.tgz "$(php-config --extension-dir)"/%EXTNAME%.so + echo "OS_LIB=$(php-config --extension-dir)" >> $GITHUB_OUTPUT + - name: Upload the binary artifacts + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ext_%EXTNAME%-${{ github.ref_name }}_php${{ matrix.php-versions }}_macos-${{steps.runner.outputs.version}}.tgz + asset_name: ext_%EXTNAME%-${{ github.ref_name }}_php${{ matrix.php-versions }}_macos-${{steps.runner.outputs.version}}.tgz + tag: ${{ github.ref }} + overwrite: true + file_glob: true + body: "macos binary - ${{ steps.archive.outputs.OS_LIB }}/%EXTNAME%.so" diff --git a/ext/skeleton/.gitignore.in b/ext/skeleton/.gitignore.in index ae434fef9765c..5a5e58ca5401b 100644 --- a/ext/skeleton/.gitignore.in +++ b/ext/skeleton/.gitignore.in @@ -39,3 +39,4 @@ tests/**/*.sh tests/**/*.db tests/**/*.mem tmp-php.ini +php-sdk*/ diff --git a/ext/skeleton/cmd/compile_x64.bat b/ext/skeleton/cmd/compile_x64.bat new file mode 100644 index 0000000000000..ccc61b9250552 --- /dev/null +++ b/ext/skeleton/cmd/compile_x64.bat @@ -0,0 +1,6 @@ +@echo off +if EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" ( + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" && cmd\getopt.bat %* && set ARCH=x64&& cmd\make_module.bat +) else if EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise" ( + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && .\cmd\getopt.bat %* && set ARCH=x64&& .\cmd\make_module.bat +) diff --git a/ext/skeleton/cmd/compile_x86.bat b/ext/skeleton/cmd/compile_x86.bat new file mode 100644 index 0000000000000..007eb3c9eaf71 --- /dev/null +++ b/ext/skeleton/cmd/compile_x86.bat @@ -0,0 +1,6 @@ +@echo off +if EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" ( + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat" && cmd\getopt.bat %* && set ARCH=x86&& cmd\make_module.bat +) else if EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise" ( + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars32.bat" && .\cmd\getopt.bat %* && set ARCH=x86&& .\cmd\make_module.bat +) diff --git a/ext/skeleton/cmd/deps_build.bat b/ext/skeleton/cmd/deps_build.bat new file mode 100644 index 0000000000000..c5b64a28ce673 --- /dev/null +++ b/ext/skeleton/cmd/deps_build.bat @@ -0,0 +1,19 @@ +@echo off +curl -LO https://cytranet.dl.sourceforge.net/project/pthreads4w/pthreads4w-code-v3.0.0.zip +unzip -xoq pthreads4w-code-v3.0.0.zip +ren pthreads4w-code-07053a521b0a9deb6db2a649cde1f828f2eb1f4f pthreads4w +mkdir pthreads4w\cmake +copy /Y ..\..\..\..\cmd\deps_build\*.* pthreads4w\cmake +cd pthreads4w +mkdir build +cd build +cmake .. -D BUILD_TESTING=OFF -G "Visual Studio 16 2019" -A %ARCH% -D CMAKE_BUILD_TYPE=Release +cmake --build . --config Release --target install +copy /Y ..\PTHREADS-BUILT\lib\*.* ..\..\deps\lib\ +copy /Y ..\PTHREADS-BUILT\include\*.* ..\..\deps\include\ +copy /Y ..\PTHREADS-BUILT\bin\*.* ..\..\deps\bin\ +copy /Y ..\PTHREADS-BUILT\bin\*.* ..\..\php-%PHP_VER%\%ARCH%\Release%PHP_TS%\php-%PHP_VER% +cd ..\.. + +del pthreads4w-code-v3.0.0.zip +rmdir /S /Q pthreads4w diff --git a/ext/skeleton/cmd/deps_build/.spacemarker b/ext/skeleton/cmd/deps_build/.spacemarker new file mode 100644 index 0000000000000..2d030d7bc1bbf --- /dev/null +++ b/ext/skeleton/cmd/deps_build/.spacemarker @@ -0,0 +1 @@ +delete me diff --git a/ext/skeleton/cmd/getopt.bat b/ext/skeleton/cmd/getopt.bat new file mode 100644 index 0000000000000..a8b5e3a101120 --- /dev/null +++ b/ext/skeleton/cmd/getopt.bat @@ -0,0 +1,20 @@ +@echo off +set SNAP= +set OPTIONS= +:parse +if "%~1" == "" goto endparse +if "%~1" == "--php" set PHP_VER=%2 +if "%~1" == "--option" set OPTIONS=%2 %OPTIONS% +if "%~1" == "--snap" set SNAP=snap +if "%~1" == "--ext" ( set EXT=--with-%2&& set EXTNAME=%2 ) +if "%~1" == "--ts" set PHP_TS=_TS +if "%~1" == "--shared" ( set EXT=%EXT%=shared && set SHARE==shared ) +if "%~1" == "--deps" set DEPS=%2 +if "%~1" == "--arch" set ARCH=%2 + +shift +goto parse +:endparse +if not defined PHP_VER ( + set PHP_VER=7.4.33 +) diff --git a/ext/skeleton/cmd/make_module.bat b/ext/skeleton/cmd/make_module.bat new file mode 100644 index 0000000000000..79fa20544694d --- /dev/null +++ b/ext/skeleton/cmd/make_module.bat @@ -0,0 +1,40 @@ +@echo off +if "%PHP_VER%" == "7.4.33" ( + set CRT=vc15 +) else ( + set CRT=vs16 +) + +if NOT EXIST php-sdk ( + curl -L https://github.com/php/php-sdk-binary-tools/archive/refs/tags/php-sdk-2.2.0.tar.gz | tar xzf - && ren php-sdk-binary-tools-php-sdk-2.2.0 php-sdk +) + +if NOT DEFINED ARCH set ARCH=x64 +if NOT EXIST php-sdk\phpdev\%CRT%\%ARCH% ( mkdir php-sdk\phpdev\%CRT%\%ARCH% ) +if NOT EXIST php-sdk\phpdev\%CRT%\%ARCH%\pecl ( mkdir php-sdk\phpdev\%CRT%\%ARCH%\pecl ) +if NOT EXIST php-sdk\phpdev\%CRT%\%ARCH%\pecl\%EXTNAME% ( mklink /j "php-sdk\phpdev\%CRT%\%ARCH%\pecl\%EXTNAME%" . ) + +cd php-sdk\phpdev\%CRT%\%ARCH% +IF EXIST php-src-php-%PHP_VER% ren php-src-php-%PHP_VER% php-%PHP_VER% +IF NOT EXIST php-%PHP_VER% ( + curl -L https://github.com/php/php-src/archive/refs/tags/php-%PHP_VER%.tar.gz | tar xzf - + IF EXIST php-src-php-%PHP_VER% ren php-src-php-%PHP_VER% php-%PHP_VER% +) + +cd ..\..\.. + +set "VSCMD_START_DIR=%CD%" +set "__VSCMD_ARG_NO_LOGO=yes" +set PHP_SDK_ROOT_PATH=%~dp0 +set PHP_SDK_ROOT_PATH=%PHP_SDK_ROOT_PATH:~0,-1% +set PHP_SDK_RUN_FROM_ROOT=.\php-sdk + +copy /Y ..\cmd\phpsdk_setshell.bat bin\phpsdk_setshell.bat + +bin\phpsdk_setshell.bat %CRT% %ARCH% && bin\phpsdk_setvars.bat && bin\phpsdk_dumpenv.bat && bin\phpsdk_buildtree.bat phpdev && cd php-%PHP_VER% && ..\..\..\..\bin\phpsdk_deps -u --no-backup && if NOT EXIST "..\deps\include\%DEPS%.h" ( + cd .. && ..\..\..\..\cmd\%DEPS%_build.bat && cd php-%PHP_VER% && buildconf --force --add-modules-dir=..\pecl\ && configure --enable-cli --with-ffi --with-iconv%SHARE% --enable-phar%SHARE% --enable-filter%SHARE% --with-openssl%SHARE% --enable-sockets%SHARE% --enable-mbstring%SHARE% --with-libxml%SHARE% --enable-fileinfo%SHARE% --enable-xmlwriter%SHARE% --enable-tokenizer%SHARE% --enable-embed %EXT% %ZTS% %OPTIONS% && nmake %SNAP% && cd ..\..\..\..\.. && copy /Y php-sdk\phpdev\%CRT%\%ARCH%\deps\bin\%DEPS%*.dll php-sdk\phpdev\%CRT%\%ARCH%\php-%PHP_VER%\%ARCH%\Release%PHP_TS%\php-%PHP_VER% +) else if EXIST config.nice.bat ( + config.nice.bat && nmake %SNAP% && cd ..\..\..\..\.. +) else ( + buildconf --force --add-modules-dir=..\pecl\ && configure --enable-cli --with-ffi --with-iconv%SHARE% --enable-phar%SHARE% --enable-filter%SHARE% --with-openssl%SHARE% --enable-sockets%SHARE% --enable-mbstring%SHARE% --with-libxml%SHARE% --enable-fileinfo%SHARE% --enable-xmlwriter%SHARE% --enable-tokenizer%SHARE% --enable-embed %EXT% %ZTS% %OPTIONS% && nmake %SNAP% && cd ..\..\..\..\.. +) diff --git a/ext/skeleton/cmd/os_codename.sh b/ext/skeleton/cmd/os_codename.sh new file mode 100644 index 0000000000000..dbcbeb6c86b0f --- /dev/null +++ b/ext/skeleton/cmd/os_codename.sh @@ -0,0 +1,24 @@ +#!/bin/bash +lsb_release='/usr/bin/lsb_release' +architecture=`uname -i` +os='unknown' + +if [ -x $lsb_release ]; then + # we pull in default values, should work for both Debian and Ubuntu + os=`$lsb_release -s -i | tr "[:upper:]" "[:lower:]"` + + if [ "$OS" == "centos" ]; then + os_codename=`$lsb_release -s -r | sed -e 's/\..*//'` + else + os_codename=`$lsb_release -s -c | tr "[:upper:]" "[:lower:]"` + fi + +elif [ -r "/etc/redhat-release" ]; then + # it's either RHEL or CentOS, which is fine + os='centos' + + # instead of codename, we pull in release version ('6.3', '6.4', etc) + os_codename=`sed s/.*release\ // /etc/redhat-release | sed s/\ .*//` +fi + +echo $os_codename diff --git a/ext/skeleton/cmd/phpsdk_setshell.bat b/ext/skeleton/cmd/phpsdk_setshell.bat new file mode 100644 index 0000000000000..78dadb0a33b25 --- /dev/null +++ b/ext/skeleton/cmd/phpsdk_setshell.bat @@ -0,0 +1,175 @@ +@echo off + +if not defined PHP_SDK_RUN_FROM_ROOT ( + echo This script should not be run directly. + echo Use starter scripts looking like phpsdk-^-^.bat in the PHP SDK root instead. + goto out_error +) + + +if "%1"=="" goto :help +if "%1"=="/?" goto :help +if "%1"=="-h" goto :help +if "%1"=="--help" goto :help +if "%2"=="" goto :help + +cmd /c "exit /b 0" + +set PHP_SDK_VS=%1 +if /i not "%PHP_SDK_VS:~0,2%"=="vc" ( + if /i not "%PHP_SDK_VS:~0,2%"=="vs" ( +:malformed_vc_string + echo Malformed CRT string "%1" + set PHP_SDK_VS= + goto out_error + ) +) +if ""=="%PHP_SDK_VS:~2%" ( + goto malformed_vc_string +) +set /a TMP_CHK=%PHP_SDK_VS:~2% +if 14 gtr %TMP_CHK% ( + if "0"=="%TMP_CHK%" ( + if not "0"=="%PHP_SDK_VS:~2%" ( + set TMP_CHK= + goto malformed_vc_string + ) + ) + + echo At least vc14 is required + set PHP_SDK_VS= + set TMP_CHK= + goto out_error +) +set PHP_SDK_VS_NUM=%TMP_CHK% +set TMP_CHK= + +if /i not "%2"=="x64" ( + if /i not "%2"=="x86" ( + echo Unsupported arch "%2" + goto out_error + ) +) + +set PHP_SDK_ARCH=%2 + +rem check OS arch +set TMPKEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion +reg query "%TMPKEY%" /v "ProgramFilesDir (x86)" >nul 2>nul +if not errorlevel 1 ( + set PHP_SDK_OS_ARCH=x64 +) else ( + if /i "%PHP_SDK_ARCH%"=="x64" ( + echo 32-bit OS detected, native 64-bit toolchain is unavailable. + goto out_error + ) + set PHP_SDK_OS_ARCH=x86 +) +set TMPKEY= + +rem get vc base dir +if 15 gtr %PHP_SDK_VS_NUM% ( + if /i "%PHP_SDK_OS_ARCH%"=="x64" ( + set TMPKEY=HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\%PHP_SDK_VS:~2%.0\Setup\VC + ) else ( + set TMPKEY=HKLM\SOFTWARE\Microsoft\VisualStudio\%PHP_SDK_VS:~2%.0\Setup\VC + ) + reg query !TMPKEY! /v ProductDir >nul 2>&1 + if errorlevel 1 ( + echo Couldn't determine VC%PHP_SDK_VS:~2% directory + goto out_error; + ) + for /f "tokens=2*" %%a in ('reg query !TMPKEY! /v ProductDir') do set PHP_SDK_VC_DIR=%%b +) else ( + rem build the version range, e.g. "[15,16]" + set /a PHP_SDK_VS_RANGE=PHP_SDK_VS_NUM + 1 + set PHP_SDK_VS_RANGE="[%PHP_SDK_VS_NUM%,!%PHP_SDK_VS_RANGE%!]" + for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text -prerelease') do ( + set PHP_SDK_VC_DIR=%%b\VC + ) + if not exist "!PHP_SDK_VC_DIR!" ( + for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -products Microsoft.VisualStudio.Product.BuildTools -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do ( + set PHP_SDK_VC_DIR=%%b\VC + ) + if not exist "!PHP_SDK_VC_DIR!" ( + rem check for a preview release + for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -prerelease -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do ( + set PHP_SDK_VC_DIR=%%b\VC + ) + if not exist "!PHP_SDK_VC_DIR!" ( + echo Could not determine '%PHP_SDK_VS%' directory + ) + ) + ) + set VSCMD_ARG_no_logo=nologo +) +set TMPKEY= +set PHP_SDK_VS_RANGE= + +if 15 gtr %PHP_SDK_VS_NUM% ( + rem get sdk dir + rem if 10.0 is available, it's ok + if /i "%PHP_SDK_OS_ARCH%"=="x64" ( + set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0 + ) else ( + set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0 + ) + for /f "tokens=2*" %%a in ('reg query "!TMPKEY!" /v InstallationFolder') do ( + for /f "tokens=2*" %%c in ('reg query "!TMPKEY!" /v ProductVersion') do ( + if exist "%%bInclude\%%d.0\um\Windows.h" ( + goto got_sdk + ) + ) + ) + + rem Otherwise 8.1 should be available anyway + if /i "%PHP_SDK_OS_ARCH%"=="x64" ( + set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.1 + ) else ( + set TMPKEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.1 + ) + for /f "tokens=2*" %%a in ('reg query "!TMPKEY!" /v InstallationFolder') do ( + if exist "%%b\Include\um\Windows.h" ( + goto got_sdk + ) + ) + + echo Windows SDK not found. + goto out_error; +:got_sdk + set TMPKEY= +) + +if /i "%PHP_SDK_ARCH%"=="x64" ( + if 15 gtr %PHP_SDK_VS_NUM% ( + set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\vcvarsall.bat" amd64 -vcvars_ver=%vcvars_ver% + ) else ( + set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\Auxiliary\Build\vcvarsall.bat" amd64 -vcvars_ver=%vcvars_ver% + ) +) else ( + if 15 gtr %PHP_SDK_VS_NUM% ( + set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\vcvarsall.bat" x86 -vcvars_ver=%vcvars_ver% + ) else ( + set PHP_SDK_VS_SHELL_CMD="!PHP_SDK_VC_DIR!\Auxiliary\Build\vcvarsall.bat" x86 -vcvars_ver=%vcvars_ver% + ) +) + +rem echo Visual Studio VC path %PHP_SDK_VC_DIR% +rem echo Windows SDK path %PHP_SDK_WIN_SDK_DIR% + + +goto out + +:help + echo "Start Visual Studio command line for PHP SDK" + echo "Usage: %0 vc arch" + echo nul + +:out_error + exit /b 3 + +:out +rem echo Shell configuration complete + exit /b 0 + +goto :eof diff --git a/ext/skeleton/cmd/windows_run_test.bat b/ext/skeleton/cmd/windows_run_test.bat new file mode 100644 index 0000000000000..6d58c560ce8c9 --- /dev/null +++ b/ext/skeleton/cmd/windows_run_test.bat @@ -0,0 +1,21 @@ +@echo off +call cmd\getopt.bat %* + +if "%PHP_VER%" == "7.4.33" ( + set CRT=vc15 +) else ( + set CRT=vs16 +) + +if NOT DEFINED ARCH set ARCH=x64 + +dir php-sdk\phpdev\%CRT%\%ARCH%\php-%PHP_VER%\%ARCH%\Release%PHP_TS% +dir php-sdk\phpdev\%CRT%\%ARCH%\php-%PHP_VER%\%ARCH%\Release%PHP_TS%\php-%PHP_VER% +dir php-sdk\phpdev\%CRT%\%ARCH%\php-%PHP_VER%\%ARCH%\Release%PHP_TS%\pecl-%PHP_VER% +cd php-sdk\phpdev\%CRT%\%ARCH%\php-%PHP_VER%\%ARCH%\Release%PHP_TS%\php-%PHP_VER% +if EXIST php.exe ( + dir ext + php -m + php -v + php ..\..\..\run-tests.php --offline --show-diff --set-timeout 240 ..\..\..\tests +)