Skip to content

single automated Windows build command, ext/skeleton addons #11125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,4 @@ tmp-php.ini
!/ext/fileinfo/magicdata.patch
!/ext/pcre/pcre2lib/config.h
!/win32/build/Makefile
php-sdk*/
6 changes: 6 additions & 0 deletions cmd/compile_x64.bat
Original file line number Diff line number Diff line change
@@ -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
)
Comment on lines +1 to +6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These I simply used the system PATH for and assume the machine has been setup with a PATH to use the correct tooling. I Don't try to own that detail.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you not seeing/realizing everything is setup to be local to the folder you're in. The scripts folder itself can be zipped and extracted, and all building starts there.

The scripts actually downloading PHP if not present in folder current setup.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so in theory a benefit of this approach is that I could run parallel builds without setting up separate users, or messing with the PATH variable.

Is that common for windows development?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? The whole thing is customized from there scripts, the reason it works. So NO! It's not following there current system steps.

And it still seems, that is the part you not realizing, you have to write/edit there steps over. You haven't run my build setup or anything, don't see how you can comment on anything. You don't use Windows daily, otherwise you realize why it's the way it is.

Copy link
Contributor

@Lewiscowles1986 Lewiscowles1986 Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered you are particularly bad at explaining yourself because of these hysterical outbursts?

I Still have no idea why I'd use this methodology, and was asking you a direct question which you've not answered.

6 changes: 6 additions & 0 deletions cmd/compile_x86.bat
Original file line number Diff line number Diff line change
@@ -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
)
20 changes: 20 additions & 0 deletions cmd/getopt.bat
Original file line number Diff line number Diff line change
@@ -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
)
36 changes: 36 additions & 0 deletions cmd/make_php.bat
Original file line number Diff line number Diff line change
@@ -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 ..\..\..\..\..
)
175 changes: 175 additions & 0 deletions cmd/phpsdk_setshell.bat
Original file line number Diff line number Diff line change
@@ -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-^<crt^>-^<arch^>.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
21 changes: 21 additions & 0 deletions cmd/windows_run_test.bat
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

@Lewiscowles1986 Lewiscowles1986 Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 I had no idea this was the syntax for optional environment vars [in batch files]... I Hate windows so much.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the whole issue to begin with. You don't do Windows or like, and trying to understand what's happening.

It might be best you review there official building steps and look at the scripts they have in there.

Copy link
Contributor

@Lewiscowles1986 Lewiscowles1986 Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, but compared to the syntax I am used to which works on multiple operating systems, is much shorter, and has more developer mindshare.
https://stackoverflow.com/a/2013589/1548557

Also this syntax is not present in the existing PHP build system.

I'm not evaluating this simply based upon familiarity. If it is part of a build system used by PHP; I'd like it to at least be internally similar and work towards other mechanisms.

Also while I joked, I added a ticket to my own investigation to see if this syntax could make things more readable.

Edit: I can see how the last part of my response is confrontational here. I apologise for my part in that. Please ignore it if you read it. I've edited it out.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's doesn't matter about your jokes. Most PHP only programmers have that problem. It just seem you trying to come up with a solution when you really don't know Windows at all.

Read there current official Windows process that I changed and the reason it works in a single step. You reading scripts with no Windows background and making judgement callsthen asking at the same time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bro, I don't only code PHP; I don't code exclusively for windows, or tie myself to Microsoft, since maybe 15 years ago, although I do have projects that build on windows.

I know windows enough. Perhaps some darker edges of it, I don't know nearly as well as I know more competent systems that folks deploy to. In a market share, this is not an argument to have.

I like that you've wrapped up several commands, which still happen into one runnable entrypoint. I've asked you about this; because thus far, the official GitHub actions performs more steps than you have aggregated. Someone would need to add Firebase, MSSQL, pgSQL, MySQL, SNMP at least. But you've just littered files with a single example and called it done. This won't move forward without you taking the time to explain what and why you've done things.

Just read the wiki it says to do this. Then why is it editing centos and other OS targets as well? None of this is particularly well explained. Stop being mad, unless you want to be the smartest person that nobody is listening to. You submitted this in April; maybe if you can pause for a minute it can be merged before next April and we'll all recognise how smart a solution this is.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why you still replying/comments on this PR.

I can't help you. Read https://wiki.php.net/internals/windows/stepbystepbuild which is mentioned in this PR. Download those scripts review them, then submit PR to original author.

You should actually read my first post of PR and the reply that went south the moment he mentions about Windows.


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
)
58 changes: 58 additions & 0 deletions ext/skeleton/.github/workflows/CentOS-7-release.yml.skeleton
Original file line number Diff line number Diff line change
@@ -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 }}
Loading