Skip to content

Commit 0777b9f

Browse files
authored
Merge pull request #908 from jingjingxyk/build_native_php
Build native php
2 parents 9f9ac1d + 8e33e2c commit 0777b9f

File tree

10 files changed

+218
-97
lines changed

10 files changed

+218
-97
lines changed

.github/workflows/windows-cygwin.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
cp -f /cygdrive/c/setup.exe /cygdrive/c/cygwin/bin/setup-x86_64.exe
8787
bash ./sapi/scripts/cygwin/install-cygwin.sh
8888
89-
- name: Install Cygwin Packages
89+
- name: Install Cygwin Packages with powershell
9090
if: 1
9191
run: |
9292
Copy-Item -Path "C:\setup.exe" -Destination "${{ github.workspace }}\setup-x86_64.exe"

sapi/quickstart/windows/cygwin-build/README.md

+45-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,57 @@
22

33
## [windows cygwin 环境 构建步骤](../../../../docs/Cygwin.md)
44

5-
## 双击如下两个脚本,自动下载cygwin 和 cygwin安装依赖库
5+
## 自动下载cygwin 和 cygwin安装依赖库
66

77
```shell
88

99
# 自动下载 cygwin
10-
sapi\quickstart\windows\cygwin-build\download-cygwin.bat
10+
.\sapi\quickstart\windows\cygwin-build\download-cygwin.bat
1111
# 自动安装 依赖包
12-
sapi\quickstart\windows\cygwin-build\install-cygwin.bat
12+
.\sapi\quickstart\windows\cygwin-build\install-cygwin.bat
1313

1414

1515
```
1616

17+
### 使用镜像 安装 cygwin 环境依赖包
18+
19+
```
20+
.\sapi\quickstart\windows\cygwin-build\install-cygwin.bat --mirror china
21+
22+
```
23+
24+
### PowerShell 环境中调用批处理命令
25+
26+
```powershell
27+
28+
cmd /c .\sapi\quickstart\windows\cygwin-build\install-cygwin.bat --mirror china
29+
30+
```
31+
32+
## 进入cygwin 环境
33+
34+
```
35+
C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -
36+
37+
38+
# 进入项目所在目录 (USER=Administrator)
39+
cd /cygdrive/c/users/${USER}/swoole-cli
40+
41+
```
42+
43+
### cygwin mirror
44+
45+
https://cygwin.com/mirrors.html
46+
47+
### 搜索包
48+
49+
https://cygwin.com/cgi-bin2/package-grep.cgi?grep=openssl
50+
51+
### windows 软连接例子
52+
53+
```bash
54+
55+
mklink composer composer.phar
56+
57+
```
58+

sapi/quickstart/windows/cygwin-build/download-cygwin.bat

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ cd /d ..\..\..\..\
1212
set "__PROJECT__=%cd%"
1313
echo %cd%
1414

15-
md %__PROJECT__%\var\windows-cygwin-build-deps\
15+
md %__PROJECT__%\var\cygwin-build\
1616

17-
cd /d %__PROJECT__%\var\windows-cygwin-build-deps\
17+
cd /d %__PROJECT__%\var\cygwin-build\
1818

1919
curl.exe -fSLo setup-x86_64.exe https://cygwin.com/setup-x86_64.exe
2020

sapi/quickstart/windows/cygwin-build/install-cygwin.bat

+16-10
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,37 @@ cd /d ..\..\..\..\
1212
set "__PROJECT__=%cd%"
1313
cd /d %__PROJECT__%\
1414
echo %cd%
15-
:: package separate with commas
1615

1716

18-
set SITE="https://mirrors.kernel.org/sourceware/cygwin/"
17+
18+
set "SITE=https://mirrors.kernel.org/sourceware/cygwin/"
1919

2020
:getopt
2121
if /i "%1" equ "--mirror" (
2222
if /i "%2" equ "china" (
23-
set SITE="https://mirrors.ustc.edu.cn/cygwin/"
23+
set "SITE=https://mirrors.ustc.edu.cn/cygwin/"
2424
)
2525
)
2626
shift
2727

2828
if not (%1)==() goto getopt
2929

30-
if "%GITHUB_ACTIONS%"=="" (
31-
setup-x86_64.exe --quiet-mode --disable-buggy-antivirus --site %SITE%
32-
)
30+
set "OPTIONS= --quiet-mode --disable-buggy-antivirus --site %SITE% "
31+
set "PACKAGES="
3332

34-
setup-x86_64.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode --disable-buggy-antivirus --site %SITE% --packages make,git,curl,wget,tar,libtool,bison,gcc-g++,autoconf,automake,openssl,libpcre2-devel,libssl-devel,libcurl-devel,libxml2-devel,libxslt-devel,libgmp-devel,ImageMagick,libpng-devel,libjpeg-devel,libfreetype-devel,libwebp-devel,libsqlite3-devel,zlib-devel,libbz2-devel,liblz4-devel,liblzma-devel,libzip-devel,libicu-devel,libonig-devel,libcares-devel,libsodium-devel,libyaml-devel,libMagick-devel,libzstd-devel,libbrotli-devel,libreadline-devel,libintl-devel,libpq-devel,libssh2-devel,libidn2-devel,gettext-devel,coreutils
33+
if defined GITHUB_ACTIONS (
34+
set "OPTIONS= %OPTIONS% --no-desktop --no-shortcuts --no-startmenu "
35+
)
3536

36-
setup-x86_64.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode --disable-buggy-antivirus --site %SITE% --packages zip unzip
37+
:: package separate with commas
38+
set "PACKAGES=make,git,curl,wget,tar,libtool,bison,gcc-g++,autoconf,automake,openssl,libpcre2-devel,libssl-devel,libcurl-devel,libxml2-devel,libxslt-devel,libgmp-devel,ImageMagick,libpng-devel,libjpeg-devel,libfreetype-devel,libwebp-devel,libsqlite3-devel,zlib-devel,libbz2-devel,liblz4-devel,liblzma-devel,libzip-devel,libicu-devel,libonig-devel,libcares-devel,libsodium-devel,libyaml-devel,libMagick-devel,libzstd-devel,libbrotli-devel,libreadline-devel,libintl-devel,libpq-devel,libssh2-devel,libidn2-devel,gettext-devel,coreutils"
39+
set "PACKAGES=%PACKAGES%,zip,unzip"
40+
set "PACKAGES=%PACKAGES%,libpq5,libpq-devel"
41+
set "PACKAGES=%PACKAGES%,libzstd-devel"
3742

38-
setup-x86_64.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode --disable-buggy-antivirus --site %SITE% --packages libpq5 libpq-devel
43+
set "OPTIONS=%OPTIONS% --packages %PACKAGES%"
44+
echo %OPTIONS%
3945

40-
setup-x86_64.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode --disable-buggy-antivirus --site %SITE% --packages libzstd-devel
46+
start /b /wait setup-x86_64.exe %OPTIONS%
4147

4248
endlocal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@echo off
2+
3+
4+
setlocal enableextensions enabledelayedexpansion
5+
6+
echo %~dp0
7+
cd /d %~dp0
8+
cd /d ..\..\..\..\
9+
10+
set "__PROJECT__=%cd%"
11+
cd /d %__PROJECT__%\
12+
echo %cd%
13+
14+
15+
SET DIRECTORY_NAME="c:\cygwin64"
16+
C:\windows\system32\TAKEOWN /f %DIRECTORY_NAME% /r /d y
17+
C:\windows\system32\ICACLS %DIRECTORY_NAME% /grant administrators:F /t
18+
19+
rmdir /s %DIRECTORY_NAME%
20+
21+
endlocal

sapi/scripts/cygwin/cygwin-build.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ __PROJECT__=$(
1010
pwd
1111
)
1212
cd ${__PROJECT__}
13-
cd ${__PROJECT__}/php-src
13+
WORK_TEMP_DIR=${__PROJECT__}/var/cygwin-build/
14+
cd ${WORK_TEMP_DIR}/php-src/
1415

1516
mkdir -p bin/.libs
1617
# export LDFLAGS="-all-static"
@@ -29,9 +30,9 @@ else
2930
fi
3031
set -u
3132

32-
${__PROJECT__}/php-src/sapi/cli/php.exe -v
33+
${WORK_TEMP_DIR}/php-src/sapi/cli/php.exe -v
3334

34-
cp -f ${__PROJECT__}/php-src/sapi/cli/php.exe ${__PROJECT__}/bin/
35+
cp -f ${WORK_TEMP_DIR}/php-src/sapi/cli/php.exe ${__PROJECT__}/bin/
3536

3637
${__PROJECT__}/bin/php.exe -v
3738
${__PROJECT__}/bin/php.exe -m

sapi/scripts/cygwin/cygwin-config-ext.sh

+73-60
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ __PROJECT__=$(
1111
)
1212
cd ${__PROJECT__}
1313

14-
ROOT=${__PROJECT__}
15-
1614
PHP_VERSION='8.2.27'
1715
SWOOLE_VERSION='v6.0.0'
1816
X_PHP_VERSION='8.2'
@@ -38,83 +36,98 @@ MONGODB_VERSION=1.17.2
3836
YAML_VERSION=2.2.2
3937
IMAGICK_VERSION=3.7.0
4038

41-
if [ ! -d pool/ext ]; then
42-
mkdir -p pool/ext
43-
fi
44-
45-
test -d ext && rm -rf ext
46-
test -d pool/ext && rm -rf pool/ext
4739
mkdir -p pool/ext
48-
mkdir -p ext
49-
cd pool/ext
50-
51-
if [ ! -d $ROOT/ext/redis ]; then
52-
if [ ! -f redis-${REDIS_VERSION}.tgz ]; then
53-
curl -fSLo redis-${REDIS_VERSION}.tgz https://pecl.php.net/get/redis-${REDIS_VERSION}.tgz
54-
fi
55-
tar xvf redis-${REDIS_VERSION}.tgz
56-
mv redis-${REDIS_VERSION} $ROOT/ext/redis
40+
mkdir -p pool/lib
41+
mkdir -p pool/php-tar
42+
43+
WORK_TEMP_DIR=${__PROJECT__}/var/cygwin-build/
44+
EXT_TEMP_CACHE_DIR=${WORK_TEMP_DIR}/pool/ext/
45+
mkdir -p ${WORK_TEMP_DIR}
46+
mkdir -p ${EXT_TEMP_CACHE_DIR}
47+
test -d ${WORK_TEMP_DIR}/ext/ && rm -rf ${WORK_TEMP_DIR}/ext/
48+
mkdir -p ${WORK_TEMP_DIR}/ext/
49+
50+
cd ${__PROJECT__}/pool/ext
51+
if [ ! -f redis-${REDIS_VERSION}.tgz ]; then
52+
curl -fSLo ${EXT_TEMP_CACHE_DIR}/redis-${REDIS_VERSION}.tgz https://pecl.php.net/get/redis-${REDIS_VERSION}.tgz
53+
mv ${EXT_TEMP_CACHE_DIR}/redis-${REDIS_VERSION}.tgz ${__PROJECT__}/pool/ext
5754
fi
55+
mkdir -p ${WORK_TEMP_DIR}/ext/redis/
56+
tar --strip-components=1 -C ${WORK_TEMP_DIR}/ext/redis/ -xf redis-${REDIS_VERSION}.tgz
5857

59-
# mongodb no support cygwin
60-
if [ ! -d $ROOT/ext/mongodb ]; then
61-
if [ ! -f mongodb-${MONGODB_VERSION}.tgz ]; then
62-
curl -fSLo mongodb-${MONGODB_VERSION}.tgz https://pecl.php.net/get/mongodb-${MONGODB_VERSION}.tgz
63-
fi
64-
tar xvf mongodb-${MONGODB_VERSION}.tgz
65-
mv mongodb-${MONGODB_VERSION} $ROOT/ext/mongodb
58+
: <<EOF
59+
# mongodb 扩展 不支持 cygwin 环境下构建
60+
# 详见: https://github.com/mongodb/mongo-php-driver/issues/1381
61+
62+
cd ${__PROJECT__}/pool/ext
63+
if [ ! -f mongodb-${MONGODB_VERSION}.tgz ]; then
64+
curl -fSLo ${EXT_TEMP_CACHE_DIR}/mongodb-${MONGODB_VERSION}.tgz https://pecl.php.net/get/mongodb-${MONGODB_VERSION}.tgz
65+
mv ${EXT_TEMP_CACHE_DIR}/redis-${REDIS_VERSION}.tgz ${__PROJECT__}/pool/ext
6666
fi
67+
mkdir -p ${WORK_TEMP_DIR}/ext/mongodb/
68+
tar --strip-components=1 -C ${WORK_TEMP_DIR}/ext/mongodb/ -xf redis-${REDIS_VERSION}.tgz
69+
70+
EOF
6771

68-
if [ ! -d $ROOT/ext/yaml ]; then
69-
if [ ! -f yaml-${YAML_VERSION}.tgz ]; then
70-
curl -fSLo yaml-${YAML_VERSION}.tgz https://pecl.php.net/get/yaml-${YAML_VERSION}.tgz
71-
fi
72-
tar xvf yaml-${YAML_VERSION}.tgz
73-
mv yaml-${YAML_VERSION} $ROOT/ext/yaml
72+
cd ${__PROJECT__}/pool/ext
73+
if [ ! -f yaml-${YAML_VERSION}.tgz ]; then
74+
curl -fSLo ${EXT_TEMP_CACHE_DIR}/yaml-${YAML_VERSION}.tgz https://pecl.php.net/get/yaml-${YAML_VERSION}.tgz
75+
mv ${EXT_TEMP_CACHE_DIR}/yaml-${YAML_VERSION}.tgz ${__PROJECT__}/pool/ext
7476
fi
77+
mkdir -p ${WORK_TEMP_DIR}/ext/yaml/
78+
tar --strip-components=1 -C ${WORK_TEMP_DIR}/ext/yaml/ -xf yaml-${YAML_VERSION}.tgz
7579

76-
if [ ! -d $ROOT/ext/imagick ]; then
77-
if [ ! -f imagick-${IMAGICK_VERSION}.tgz ]; then
78-
curl -fSLo imagick-${IMAGICK_VERSION}.tgz https://pecl.php.net/get/imagick-${IMAGICK_VERSION}.tgz
79-
fi
80-
tar xvf imagick-${IMAGICK_VERSION}.tgz
81-
mv imagick-${IMAGICK_VERSION} $ROOT/ext/imagick
82-
if [ "$X_PHP_VERSION" = "8.4" ]; then
83-
sed -i.backup "s/php_strtolower(/zend_str_tolower(/" $ROOT/ext/imagick/imagick.c
84-
fi
80+
cd ${__PROJECT__}/pool/ext
81+
if [ ! -f imagick-${IMAGICK_VERSION}.tgz ]; then
82+
curl -fSLo ${EXT_TEMP_CACHE_DIR}/imagick-${IMAGICK_VERSION}.tgz https://pecl.php.net/get/imagick-${IMAGICK_VERSION}.tgz
83+
mv ${EXT_TEMP_CACHE_DIR}/imagick-${IMAGICK_VERSION}.tgz ${__PROJECT__}/pool/ext
8584
fi
85+
mkdir -p ${WORK_TEMP_DIR}/ext/imagick/
86+
tar --strip-components=1 -C ${WORK_TEMP_DIR}/ext/imagick/ -xf imagick-${IMAGICK_VERSION}.tgz
8687

88+
cd ${__PROJECT__}/pool/ext
8789
if [ ! -f swoole-${SWOOLE_VERSION}.tgz ]; then
88-
test -d /tmp/swoole && rm -rf /tmp/swoole
89-
git clone -b ${SWOOLE_VERSION} https://github.com/swoole/swoole-src.git /tmp/swoole
90-
cd /tmp/swoole
91-
tar -czvf $ROOT/pool/ext/swoole-${SWOOLE_VERSION}.tgz .
92-
cd $ROOT/pool/ext/
90+
test -d ${WORK_TEMP_DIR}/swoole && rm -rf ${WORK_TEMP_DIR}/swoole
91+
git clone -b ${SWOOLE_VERSION} https://github.com/swoole/swoole-src.git ${WORK_TEMP_DIR}/swoole
92+
cd ${WORK_TEMP_DIR}/swoole
93+
tar -czvf ${EXT_TEMP_CACHE_DIR}/swoole-${SWOOLE_VERSION}.tgz .
94+
mv ${EXT_TEMP_CACHE_DIR}/swoole-${SWOOLE_VERSION}.tgz ${__PROJECT__}/pool/ext
95+
cd ${__PROJECT__}/pool/ext
9396
fi
94-
mkdir -p swoole-${SWOOLE_VERSION}
95-
tar --strip-components=1 -C swoole-${SWOOLE_VERSION} -xf swoole-${SWOOLE_VERSION}.tgz
96-
test -d $ROOT/ext/swoole && rm -rf $ROOT/ext/swoole
97-
mv swoole-${SWOOLE_VERSION} $ROOT/ext/swoole
97+
mkdir -p ${WORK_TEMP_DIR}/ext/swoole/
98+
tar --strip-components=1 -C ${WORK_TEMP_DIR}/ext/swoole/ -xf swoole-${SWOOLE_VERSION}.tgz
9899

99-
cd $ROOT
100+
cd ${__PROJECT__}
101+
# clean extension folder
102+
NO_BUILT_IN_EXTENSIONS=$(ls ${WORK_TEMP_DIR}/ext/)
103+
for EXT_NAME in $NO_BUILT_IN_EXTENSIONS; do
104+
echo "EXTENSION_NAME: $EXT_NAME "
105+
test -d ${__PROJECT__}/ext/${EXT_NAME} && rm -rf ${__PROJECT__}/ext/${EXT_NAME}
106+
done
100107

101108
# download php-src source code
102-
109+
cd ${__PROJECT__}/pool/php-tar
103110
if [ ! -f php-${PHP_VERSION}.tar.gz ]; then
104111
curl -fSLo php-${PHP_VERSION}.tar.gz https://github.com/php/php-src/archive/refs/tags/php-${PHP_VERSION}.tar.gz
105112
fi
106-
test -d php-src && rm -rf php-src
107-
mkdir -p php-src
108-
tar --strip-components=1 -C php-src -xf php-${PHP_VERSION}.tar.gz
113+
test -d ${WORK_TEMP_DIR}/php-src && rm -rf ${WORK_TEMP_DIR}/php-src
114+
mkdir -p ${WORK_TEMP_DIR}/php-src
115+
tar --strip-components=1 -C ${WORK_TEMP_DIR}/php-src -xf php-${PHP_VERSION}.tar.gz
109116

110-
cd $ROOT
117+
cd ${__PROJECT__}
118+
# copy extension
119+
# cp -rf var/cygwin-build/ext/* var/cygwin-build/php-src/ext/
120+
cp -rf ${WORK_TEMP_DIR}/ext/* ${WORK_TEMP_DIR}/php-src/ext/
111121

112-
if [ ! -d $ROOT/ext/pgsql ]; then
113-
mv $ROOT/php-src/ext/pgsql $ROOT/ext/pgsql
122+
# extension hook
123+
if [ "$X_PHP_VERSION" = "8.4" ]; then
124+
sed -i.backup "s/php_strtolower(/zend_str_tolower(/" ${WORK_TEMP_DIR}/php-src/ext/imagick/imagick.c
114125
fi
115126

116-
cd $ROOT
127+
# php source code hook
128+
cd ${WORK_TEMP_DIR}/php-src
129+
if [ "$X_PHP_VERSION" = "8.4" ] || [ "$X_PHP_VERSION" = "8.3" ] || [ "$X_PHP_VERSION" = "8.2" ] || [ "$X_PHP_VERSION" = "8.1" ]; then
130+
sed -i.backup 's/!defined(__HAIKU__)/!defined(__HAIKU__) \&\& !defined(__CYGWIN__)/' TSRM/TSRM.c
131+
fi
117132

118-
ls -lh $ROOT
119-
ls -lh $ROOT/ext/
120-
cd $ROOT
133+
cd ${__PROJECT__}

sapi/scripts/cygwin/cygwin-config.sh

+2-7
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,9 @@ while [ $# -gt 0 ]; do
3636
done
3737

3838
mkdir -p ${__PROJECT__}/bin/
39-
# cp -f ${__PROJECT__}/php-src/ext/openssl/config0.m4 ${__PROJECT__}/php-src/ext/openssl/config.m4
4039

41-
cp -rf ${__PROJECT__}/ext/* ${__PROJECT__}/php-src/ext/
42-
43-
cd ${__PROJECT__}/php-src/
44-
if [ "$X_PHP_VERSION" = "8.4" ] || [ "$X_PHP_VERSION" = "8.3" ] || [ "$X_PHP_VERSION" = "8.2" ] || [ "$X_PHP_VERSION" = "8.1" ]; then
45-
sed -i.backup 's/!defined(__HAIKU__)/!defined(__HAIKU__) \&\& !defined(__CYGWIN__)/' TSRM/TSRM.c
46-
fi
40+
WORK_TEMP_DIR=${__PROJECT__}/var/cygwin-build/
41+
cd ${WORK_TEMP_DIR}/php-src/
4742

4843
# export CPPFLAGS="-I/usr/include"
4944
# export CFLAGS=""

0 commit comments

Comments
 (0)