Skip to content

Commit 965b8e6

Browse files
authored
Merge pull request #910 from jingjingxyk/build_native_php
增加msys2 环境下构建php
2 parents 0777b9f + 2780ffe commit 965b8e6

15 files changed

+571
-37
lines changed

docs/upgrade.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
## 升级 PHP 版本 步骤
1+
# 升级 PHP 版本 步骤
22

33
> 1、修改 sapi/PHP-VERSION.conf 文件里版本号即可
4-
> 2、执行同步源码脚本, 拉取 PHP 官方源码 到本项目
4+
5+
> 2、修改 sync-source-code.php 文件里 PHP 源码包的 sha256sum 配置
6+
7+
> 3、执行同步源码脚本, 拉取 PHP 官方源码 到本项目
8+
9+
> 4、sapi/cli/ 代码的升级,需要手动确认
510
611
```shell
712

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## 下载msys2
2+
3+
```
4+
.\sapi\quickstart\windows\msys2-build\download-msys2.bat
5+
6+
.\sapi\quickstart\windows\msys2-build\install-msys2.bat
7+
8+
```
9+
10+
## 下载msys2 使用镜像
11+
12+
```
13+
.\sapi\quickstart\windows\msys2-build\download-msys2.bat --mirror china
14+
15+
```
16+
17+
## 进入msys 环境
18+
19+
```
20+
c:\msys64\msys2.exe
21+
22+
# 进入项目目录
23+
cd /c/Users/Administrator/swoole-cli
24+
cd /c/Users/${USERNAME}/swoole-cli
25+
26+
```
27+
28+
## 进入 环境
29+
30+
```shell
31+
32+
c:\msys64\clang64.exe
33+
c:\msys64\clangarm64.exe
34+
c:\msys64\mingw32.exe
35+
c:\msys64\mingw64.exe
36+
c:\msys64\msys2.exe
37+
c:\msys64\ucrt64.exe
38+
39+
```
40+
41+
## msys2 mirror and environment
42+
43+
https://www.msys2.org/dev/mirrors/
44+
https://www.msys2.org/docs/environments/
45+
# MSYS2 包搜索
46+
https://packages.msys2.org/queue
47+
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
@echo off
2+
23
:: msys2 site: https://www.msys2.org/
3-
start https://mirror.msys2.org/distrib/x86_64/msys2-x86_64-20230526.exe
4+
:: start https://mirror.msys2.org/distrib/x86_64/msys2-x86_64-20230526.exe
5+
6+
setlocal enableextensions enabledelayedexpansion
7+
8+
echo %~dp0
9+
cd /d %~dp0
10+
cd /d ..\..\..\..\
11+
12+
set "__PROJECT__=%cd%"
13+
cd /d %__PROJECT__%\
14+
echo %cd%
15+
16+
17+
md %__PROJECT__%\var\msys2-build\
18+
19+
cd /d %__PROJECT__%\var\msys2-build\
20+
21+
22+
set "SITE=https://mirror.msys2.org"
23+
24+
:getopt
25+
if /i "%1" equ "--mirror" (
26+
if /i "%2" equ "china" (
27+
set "SITE=https://mirrors.tuna.tsinghua.edu.cn/msys2/"
28+
)
29+
)
30+
shift
31+
32+
if not (%1)==() goto getopt
33+
34+
:: curl.exe -fSLo msys2-x86_64-20241208.exe https://repo.msys2.org/distrib/x86_64/msys2-x86_64-20241208.exe
35+
:: curl.exe -fSLo msys2-x86_64-20241208.exe https://mirror.msys2.org/distrib/x86_64/msys2-x86_64-20241208.exe
36+
curl.exe -fSLo msys2-x86_64-20241208.exe %SITE%/distrib/x86_64/msys2-x86_64-20241208.exe
37+
38+
copy .\msys2-x86_64-20241208.exe %__PROJECT__%\msys2-x86_64.exe
439

540

41+
endlocal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@echo off
2+
3+
:: cygwin site: https://cygwin.com/
4+
:: start https://cygwin.com/setup-x86_64.exe
5+
6+
setlocal enableextensions enabledelayedexpansion
7+
8+
echo %~dp0
9+
cd /d %~dp0
10+
cd /d ..\..\..\..\
11+
12+
set "__PROJECT__=%cd%"
13+
cd /d %__PROJECT__%\
14+
echo %cd%
15+
16+
msys2-x86_64.exe
17+
18+
endlocal

sapi/quickstart/windows/msys2-build/install-msys2.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@
88
99
> 使用镜像站点 https://mirror.tuna.tsinghua.edu.cn/help/msys2/ 下载 msys2 安装包
1010
11-
> https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/x86_64/msys2-x86_64-20230526.exe
11+
> https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/x86_64/msys2-x86_64-20230526.exe (支持 win7 的最后一版本)
12+
13+
> https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/x86_64/msys2-x86_64-20240507.exe
1214
1315
> 安装 msys2
1416
1517
> 开始菜单,打开 MSYS2 MSYS 控制台,并安装必要的包,命令如下
1618
1719
> MSYS2 包搜索 https://packages.msys2.org/queue
1820
19-
> [ msys2环境信息 ](https://www.msys2.org/docs/environments/)
21+
> [ msys2 各版本环境 区别 ](https://www.msys2.org/docs/environments/)
2022
2123
> msys2 集成了 Mingw 和 Cygwin ,同时还提供了包管理工具 `pacman`
2224
23-
### msys2 终端下
25+
## msys2 安装后初始化
2426

2527
```shell
2628
# 换源 ( 不换源,不需要执行此条命令)
2729
sed -i "s#https\?://mirror.msys2.org/#https://mirrors.tuna.tsinghua.edu.cn/msys2/#g" /etc/pacman.d/mirrorlist*
2830

2931
# 更新源
30-
pacman -Syy --noconfirm
32+
pacman -Sy --noconfirm
3133
# 无须确认安装包
32-
pacman -Syy --noconfirm git curl wget openssl zip unzip xz gcc gcc-g++ cmake make
33-
34-
pacman -Syy --noconfirm openssl-devel libreadline
34+
pacman -Sy --noconfirm git
3535

3636
# msys2 环境下 拉取 swoole-cli 源码
37-
git clone --recursive https://github.com:swoole/swoole-cli.git
37+
git clone --recursive https://github.com/swoole/swoole-cli.git
3838

39-
```
4039

40+
```
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,91 @@
1-
## msys2 安装
1+
#!/usr/bin/env bash
2+
set -x
23

3-
# 打开站点:
4-
#
5-
# https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/x86_64/
4+
__DIR__=$(
5+
cd "$(dirname "$0")"
6+
pwd
7+
)
8+
__PROJECT__=$(
9+
cd ${__DIR__}/../../../../
10+
pwd
11+
)
12+
cd ${__PROJECT__}
13+
pwd
614

7-
wget https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/x86_64/msys2-x86_64-20230318.exe
815

9-
# msys2 help
10-
# https://mirror.tuna.tsinghua.edu.cn/help/msys2/
16+
MIRROR=''
17+
IS_UPGRADE=0
18+
while [ $# -gt 0 ]; do
19+
case "$1" in
20+
--mirror)
21+
MIRROR="$2"
22+
;;
23+
--upgrade)
24+
IS_UPGRADE=1
25+
;;
26+
--*)
27+
echo "Illegal option $1"
28+
;;
29+
esac
30+
shift $(($# > 0 ? 1 : 0))
31+
done
32+
33+
case "$MIRROR" in
34+
china)
35+
sed -i "s#https\?://mirror.msys2.org/#https://mirrors.tuna.tsinghua.edu.cn/msys2/#g" /etc/pacman.d/mirrorlist*
36+
;;
37+
esac
38+
39+
if [ $IS_UPGRADE == 1 ] ; then
40+
# 升级
41+
pacman -Su --noconfirm
42+
fi
1143

1244

1345
# 搜索包
14-
pacman -Ss curl
15-
# 升级
16-
pacman -Syu
17-
# 安装包
18-
pacman -Sy git curl wget
46+
# pacman -Ss curl
47+
48+
# 将本地的包数据库与远程的仓库进行了同步
49+
pacman -Sy
50+
1951
# 无须确认安装包
20-
pacman -Sy --noconfirm git curl wget openssl
52+
pacman -S --noconfirm git curl wget openssl
53+
54+
pacman -S --noconfirm zip unzip xz gcc cmake make
55+
pacman -S --noconfirm re2c
56+
57+
pacman -S --noconfirm openssl-devel libreadline
58+
59+
pacman -S --noconfirm lzip
60+
pacman -S --noconfirm zip unzip
61+
pacman -S --noconfirm bison automake autoconf libtool coreutils
62+
pacman -S --noconfirm libcurl-devel libxml2-devel libxslt-devel
63+
pacman -S --noconfirm zlib-devel
64+
pacman -S --noconfirm libbz2-devel liblz4-devel liblzma-devel libcares-devel
65+
pacman -S --noconfirm libyaml-devel libzstd-devel libreadline-devel
66+
pacman -S --noconfirm libssh2-devel libidn2-devel gettext-devel
67+
pacman -S --noconfirm libzstd-devel
68+
pacman -S --noconfirm icu-devel
69+
pacman -S --noconfirm libsqlite-devel libsqlite
70+
pacman -S --noconfirm gmp-devel
71+
pacman -S --noconfirm libintl
72+
pacman -S --noconfirm pcre2
73+
pacman -S --noconfirm brotli-devel
74+
75+
:<<EOF
76+
# 不存在的包
77+
pacman -S --noconfirm libpcre2-devel libssl-devel libgmp-devel
78+
pacman -S --noconfirm ImageMagick libpng-devel libjpeg-devel libfreetype-devel libwebp-devel libsqlite3-devel
79+
pacman -S --noconfirm libzip-devel libicu-devel libonig-devel libsodium-devel
80+
pacman -S --noconfirm libMagick-devel libbrotli-devel libintl-devel libpq-devel
81+
pacman -S --noconfirm libpq5 libpq-devel
82+
pacman -S --noconfirm gcc-g++
83+
84+
# msys 环境下 可以安装 re2c
85+
# 不需要执行 bash ./sapi/scripts/cygwin/install-re2c.sh
86+
87+
88+
EOF
89+
90+
# 清理缓存
91+
pacman -Scc --noconfirm

sapi/quickstart/windows/msys2-build/open-msys2-cygwin-website.bat

-5
This file was deleted.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -x
3+
4+
__DIR__=$(
5+
cd "$(dirname "$0")"
6+
pwd
7+
)
8+
__PROJECT__=$(
9+
cd ${__DIR__}/../../../../
10+
pwd
11+
)
12+
cd ${__PROJECT__}
13+
pwd
14+
15+
bash sapi/scripts/msys2/config-ext.sh
16+
bash sapi/scripts/msys2/config.sh
17+
bash sapi/scripts/msys2/build.sh
18+
bash sapi/scripts/msys2/archive.sh

sapi/scripts/cygwin/cygwin-pack.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mkdir -p /tmp/${NAME}/bin/
2525

2626
cd ${__PROJECT__}/
2727
ldd ${__PROJECT__}/bin/php.exe | grep -v '/cygdrive/' | awk '{print $3}'
28-
ldd ${__PROJECT__}/bin/php.exe | grep -v '/cygdrive/' | awk '{print $3}' | xargs -I {} cp {} /tmp/${NAME}/
28+
ldd ${__PROJECT__}/bin/php.exe | grep -v '/cygdrive/' | awk '{print $3}' | xargs -I {} cp {} /tmp/${NAME}/bin/
2929

3030
ls -lh /tmp/${NAME}/
3131

sapi/scripts/download-php-src-archive.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,32 @@
55
# $php_version_tag = trim(file_get_contents($poject_dir . '/sapi/PHP-VERSION.conf'));
66
$php_version_tag = '8.2.23';
77
$php_source_folder = $poject_dir . "/var/php-{$php_version_tag}";
8-
$php_archive_file = $poject_dir . "/pool/php/php-{$php_version_tag}.tar.gz";
9-
8+
$php_archive_file = $poject_dir . "/pool/php-tar/php-{$php_version_tag}.tar.gz";
9+
$php_archive_file_sha256sum = '9c81202e6397d973c89d162e30ab6fe6689dea9cbbb235be5a5366707a38b649';
1010
$download_dir = dirname($php_archive_file);
11+
$download_php_counter = 0;
1112

13+
DOWNLOAD_PHP:
1214
# 下载 PHP 源码
1315
$download_cmd = "curl -fSL https://github.com/php/php-src/archive/refs/tags/php-{$php_version_tag}.tar.gz -o {$php_archive_file}";
1416
echo $download_cmd . PHP_EOL;
1517
if (!file_exists($php_archive_file)) {
1618
`test -d {$download_dir} || mkdir -p {$download_dir}`;
19+
$download_php_counter++;
1720
`{$download_cmd}`;
1821
}
1922

23+
$hash = hash_file('sha256', $php_archive_file);
24+
echo "sha256sum: " . $hash . PHP_EOL;
25+
if ($hash !== $php_archive_file_sha256sum) {
26+
if ($download_php_counter > 3) {
27+
throw new \Exception('curl download php archive Exception!', 500);
28+
}
29+
echo 'archive sha256sum mismatched , will re-download ' . PHP_EOL;
30+
unlink($php_archive_file);
31+
goto DOWNLOAD_PHP;
32+
}
33+
2034
# 若不存在则解压 PHP 源码包
2135
# tar -zxvf 文件名.tar.gz --strip-components=1 -C 指定解压目录
2236

sapi/scripts/msys2/archive.sh

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
3+
set -exu
4+
__DIR__=$(
5+
cd "$(dirname "$0")"
6+
pwd
7+
)
8+
__PROJECT__=$(
9+
cd ${__DIR__}/../../../
10+
pwd
11+
)
12+
cd ${__PROJECT__}
13+
14+
cd ${__PROJECT__}/
15+
ldd ${__PROJECT__}/bin/php.exe
16+
17+
cd ${__PROJECT__}
18+
APP_VERSION=$(${__PROJECT__}/bin/php.exe -v | head -n 1 | awk '{ print $2 }')
19+
NAME="php-cli-v${APP_VERSION}-msys2-x64"
20+
21+
test -d /tmp/${NAME} && rm -rf /tmp/${NAME}
22+
mkdir -p /tmp/${NAME}/
23+
mkdir -p /tmp/${NAME}/etc/
24+
mkdir -p /tmp/${NAME}/bin/
25+
26+
cd ${__PROJECT__}/
27+
ldd ${__PROJECT__}/bin/php.exe | grep -v '/c/Windows/' | awk '{print $3}'
28+
ldd ${__PROJECT__}/bin/php.exe | grep -v '/c/Windows/' | awk '{print $3}' | xargs -I {} cp {} /tmp/${NAME}/
29+
30+
ls -lh /tmp/${NAME}/
31+
32+
cp -f ${__PROJECT__}/bin/php.exe /tmp/${NAME}/bin/
33+
# cp -f ${__PROJECT__}/bin/LICENSE /tmp/${NAME}/
34+
# cp -f ${__PROJECT__}/bin/credits.html /tmp/${NAME}/
35+
36+
cp -rL /etc/pki/ /tmp/${NAME}/etc/
37+
38+
cd /tmp/${NAME}/
39+
40+
test -f ${__PROJECT__}/${NAME}.zip && rm -f ${__PROJECT__}/${NAME}.zip
41+
zip -r ${__PROJECT__}/${NAME}.zip .
42+
43+
cd ${__PROJECT__}
44+

0 commit comments

Comments
 (0)