Skip to content

Commit

Permalink
Merge pull request #861 from jingjingxyk/build_native_php
Browse files Browse the repository at this point in the history
Build native php
  • Loading branch information
jingjingxyk authored Dec 7, 2024
2 parents f6f6446 + e3678c1 commit af479c2
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 19 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/artifact-hash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: artifact-hash

on:
workflow_dispatch:
inputs:
version:
required: true
description: "发版 版本号 tag"
default: 'v1.6.0'
type: string
php-version:
required: true
description: "PHP 版本号 "
default: 'v8.1.30,v8.2.25,v8.3.13,v8.4.1'
type: string

jobs:
generate-artifact-hash:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Show Release File Hash
run:
bash sapi/scripts/generate-artifact-hash.sh --version ${{ inputs.version }} --php-version ${{ inputs.php-version }}

- name: production artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.version }}-sha256sum
retention-days: 90
path: |
${{ inputs.version }}-sha256sum
1 change: 1 addition & 0 deletions docs/Cygwin.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ libpq-devel (如果编译pgsql扩展)
libpq5 (如果编译pgsql扩展)
libicu-devel
icu
libzstd-devel
```

Expand Down
9 changes: 9 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,12 @@ show-tarball-hash
----
计算并显示已下载的源码包 HASH 值


with-libavif
----
GD库支持 AVIF图片格式

with-iouring
----
swoole 启用支持 iouring 特性

6 changes: 4 additions & 2 deletions sapi/quickstart/windows/install-cygwin.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

setup-x86_64.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode --disable-buggy-antivirus --site https://mirrors.ustc.edu.cn/cygwin/ --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,openssl-devel

setup-x86_64.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode --disable-buggy-antivirus --site https://mirrors.ustc.edu.cn/cygwin/ --packages zip unzip
setup-x86_64.exe --quiet-mode --disable-buggy-antivirus --site https://mirrors.ustc.edu.cn/cygwin/ --packages zip unzip

setup-x86_64.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode --disable-buggy-antivirus --site https://mirrors.ustc.edu.cn/cygwin/ --packages libpq5 libpq-devel
setup-x86_64.exe --quiet-mode --disable-buggy-antivirus --site https://mirrors.ustc.edu.cn/cygwin/ --packages libpq5 libpq-devel

setup-x86_64.exe --quiet-mode --disable-buggy-antivirus --site https://mirrors.ustc.edu.cn/cygwin/ --packages libzstd-devel


7 changes: 6 additions & 1 deletion sapi/scripts/cygwin/cygwin-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ fi
./buildconf --force
test -f Makefile && make clean
./configure --prefix=/usr --disable-all \
--enable-opcache \
--disable-fiber-asm \
--without-pcre-jit \
--with-openssl --enable-openssl \
Expand Down Expand Up @@ -83,6 +82,12 @@ test -f Makefile && make clean
--enable-swoole --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-cares \
--enable-swoole-pgsql \
--enable-swoole-sqlite \
--enable-swoole-thread \
--enable-brotli \
--enable-zstd \
--enable-redis \
--enable-opcache \
--disable-opcache-jit \
--enable-redis \
--with-imagick \
--with-yaml \
Expand Down
13 changes: 5 additions & 8 deletions sapi/scripts/cygwin/install-cygwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ ROOT=${__PROJECT__}
# cp -f /cygdrive/c/setup-x86_64.exe /cygdrive/c/cygwin/bin/setup-x86_64.exe
# cp -f /cygdrive/c/setup.exe /cygdrive/c/cygwin/bin/setup-x86_64.exe


# download cygwin
# wget https://cygwin.com/setup-x86_64.exe

Expand All @@ -28,12 +27,11 @@ ROOT=${__PROJECT__}
## https://mirrors.tuna.tsinghua.edu.cn/cygwin/
## 多个包之间,用逗号分隔


SITE='https://mirrors.kernel.org/sourceware/cygwin/'
while [ $# -gt 0 ]; do
case "$1" in
--mirror)
if [ "$2" = 'china' ] ; then
if [ "$2" = 'china' ]; then
SITE='https://mirrors.ustc.edu.cn/cygwin/'
fi
;;
Expand All @@ -47,8 +45,7 @@ done
# setup-x86_64.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode --disable-buggy-antivirus --site http://mirrors.ustc.edu.cn/cygwin/ --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,openssl-devel,zip,unzip
#setup-x86_64.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode --disable-buggy-antivirus --site http://mirrors.ustc.edu.cn/cygwin/ --packages


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,openssl-devel,zip,unzip
setup-x86_64.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode --disable-buggy-antivirus --site $SITE --packages zip unzip icu libicu-devel
setup-x86_64.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode --disable-buggy-antivirus --site $SITE --packages libpq5 libpq-devel

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,openssl-devel,zip,unzip
setup-x86_64.exe --quiet-mode --disable-buggy-antivirus --site $SITE --packages zip unzip icu libicu-devel
setup-x86_64.exe --quiet-mode --disable-buggy-antivirus --site $SITE --packages libpq5 libpq-devel
setup-x86_64.exe --quiet-mode --disable-buggy-antivirus --site $SITE --packages libzstd-devel
164 changes: 164 additions & 0 deletions sapi/scripts/generate-artifact-hash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#!/usr/bin/env bash

set -xu
__DIR__=$(
cd "$(dirname "$0")"
pwd
)
__PROJECT__=$(
cd ${__DIR__}/../../
pwd
)

cd ${__PROJECT__}

OS=$(uname -s)
case $OS in
'Linux')
OS="linux"
;;
'Darwin')
OS="macos"
;;
*)
case $OS in
'MSYS_NT'*)
OS="windows"
;;
'MINGW64_NT'*)
OS="windows"
;;
*)
echo '暂未配置的 OS '
exit 0
;;
esac
;;
esac

APP_VERSION='v8.3.13'
APP_NAME='php-cli'
VERSION='v1.6.0'

while [ $# -gt 0 ]; do
case "$1" in
--proxy)
export HTTP_PROXY="$2"
export HTTPS_PROXY="$2"
NO_PROXY="127.0.0.0/8,10.0.0.0/8,100.64.0.0/10,172.16.0.0/12,192.168.0.0/16"
NO_PROXY="${NO_PROXY},::1/128,fe80::/10,fd00::/8,ff00::/8"
NO_PROXY="${NO_PROXY},localhost"
export NO_PROXY="${NO_PROXY},.myqcloud.com,.swoole.com"
;;
--version)
# 指定发布 TAG
if [ $OS = "macos" ]; then
X_VERSION=$(echo "$2" | grep -E '^v\d\.\d{1,2}\.\d{1,2}$')
elif [ $OS = "linux" ]; then
X_VERSION=$(echo "$2" | grep -P '^v\d\.\d{1,2}\.\d{1,2}$')
else
X_VERSION=''
fi

if [[ -n $X_VERSION ]]; then
{
VERSION=$X_VERSION
}
else
{
echo '--version vx.x.x error !'
exit 0
}
fi
;;
--php-version)
# 指定 PHP 版本
if [ $OS = "macos" ]; then
X_APP_VERSION=$(echo "$2" | grep -Eo '^v\d\.\d{1,2}\.\d{1,2}')
elif [ $OS = "linux" ]; then
X_APP_VERSION=$(echo "$2" | grep -Po '^v\d\.\d{1,2}\.\d{1,2}')
else
X_VERSION=''
X_APP_VERSION=''
fi

if [[ -n $X_APP_VERSION ]]; then
{
APP_VERSION=$X_APP_VERSION
}
else
{
echo '--php-version vx.x.x error !'
exit 0
}
fi
;;
--*)
echo "Illegal option $1"
exit 0
;;
esac
shift $(($# > 0 ? 1 : 0))
done

mkdir -p ${__PROJECT__}/var/artifact-hash/${VERSION}
cd ${__PROJECT__}/var/artifact-hash/${VERSION}

UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME() {
OS="$1"
ARCH="$2"
APP_VERSION="$3"
APP_DOWNLOAD_URL="https://github.com/swoole/build-static-php/releases/download/${VERSION}/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}.tar.xz"
APP_RUNTIME="${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}"
test -f ${APP_RUNTIME}.tar.xz || curl -LSo ${APP_RUNTIME}.tar.xz ${APP_DOWNLOAD_URL}

APP_DOWNLOAD_URL="https://github.com/swoole/build-static-php/releases/download/${VERSION}/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}-debug.tar.xz"
APP_RUNTIME="${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}-debug"
test -f ${APP_RUNTIME}.tar.xz || curl -LSo ${APP_RUNTIME}.tar.xz ${APP_DOWNLOAD_URL}
}

UNIX_DOWNLOAD() {
APP_VERSION="$1"
UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME "linux" "x64" "${APP_VERSION}"
UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME "linux" "arm64" "${APP_VERSION}"
UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME "macos" "x64" "${APP_VERSION}"
UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME "macos" "arm64" "${APP_VERSION}"
}

WINDOWS_DOWNLOAD_SWOOLE_CLIE_RUNTIME() {
APP_VERSION="$1"
ARCH="x64"
APP_DOWNLOAD_URL="https://github.com/swoole/build-static-php/releases/download/${VERSION}/${APP_NAME}-${APP_VERSION}-cygwin-${ARCH}.zip"

APP_RUNTIME="${APP_NAME}-${APP_VERSION}-cygwin-${ARCH}"
test -f ${APP_RUNTIME}.zip || curl -LSo ${APP_RUNTIME}.zip ${APP_DOWNLOAD_URL}
test -f all-deps.zip || curl -LSo all-deps.zip https://github.com/swoole/swoole-cli/releases/download/v5.1.5.1/all-deps.zip

}
WINDOWS_DOWNLOAD() {
WINDOWS_DOWNLOAD_SWOOLE_CLIE_RUNTIME "$1"
}

RUN_DOWNLOAD() {
UNIX_DOWNLOAD "$1"
WINDOWS_DOWNLOAD "$1"
}

DOWNLOAD() {
declare -A PHP_VERSIONS
PHP_VERSIONS[0]="v8.2.25"
PHP_VERSIONS[1]="v8.1.30"
PHP_VERSIONS[2]="v8.3.13"
PHP_VERSIONS[3]="v8.4.1"
for i in "${!PHP_VERSIONS[@]}"; do
# echo ${PHP_VERSIONS[$i]}
RUN_DOWNLOAD "${PHP_VERSIONS[$i]}"
done

}

DOWNLOAD

ls -p | grep -v '/$' | xargs sha256sum

ls -p | grep -v '/$' | xargs sha256sum >${__PROJECT__}/${VERSION}-sha256sum
15 changes: 11 additions & 4 deletions sapi/src/builder/extension/swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
use SwooleCli\Extension;

return function (Preprocessor $p) {

$options = [];

$dependentLibraries = ['curl', 'openssl', 'cares', 'zlib', 'brotli', 'nghttp2', 'sqlite3', 'unix_odbc', 'pgsql'];
$dependentExtensions = ['curl', 'openssl', 'sockets', 'mysqlnd', 'pdo'];

$swoole_tag = 'v5.1.6';
if (BUILD_CUSTOM_PHP_VERSION_ID >= 8040) {
// v5.1.x 不支持 PHP 8.4
// swoole 支持计划 https://wiki.swoole.com/zh-cn/#/version/supported?id=%e6%94%af%e6%8c%81%e8%ae%a1%e5%88%92
$swoole_tag = 'v6.0.0-rc1';
$swoole_tag = 'master';
$options[] = '--enable-swoole-thread';
$options[] = '--enable-zts';
$options[] = '--disable-opcache-jit';
$options[] = '--enable-brotli';
$options[] = '--enable-zstd';
$dependentLibraries[] = 'libzstd';
$p->withExportVariable('ZSTD_CFLAGS', '$(pkg-config --cflags --static libzstd)');
$p->withExportVariable('ZSTD_LIBS', '$(pkg-config --libs --static libzstd)');
}
$file = "swoole-{$swoole_tag}.tar.gz";

Expand All @@ -28,8 +36,6 @@
//call_user_func_array([$ext, 'withDependentLibraries'], $dependentLibraries);
//call_user_func_array([$ext, 'withDependentExtensions'], $dependentExtensions);

$dependentLibraries = ['curl', 'openssl', 'cares', 'zlib', 'brotli', 'nghttp2', 'sqlite3', 'unix_odbc', 'pgsql'];
$dependentExtensions = ['curl', 'openssl', 'sockets', 'mysqlnd', 'pdo'];

$options[] = '--enable-swoole';
$options[] = '--enable-sockets';
Expand All @@ -42,6 +48,7 @@
$options[] = '--enable-swoole-sqlite';
$options[] = '--with-swoole-odbc=unixODBC,' . UNIX_ODBC_PREFIX;


$p->addExtension((new Extension('swoole'))
->withHomePage('https://github.com/swoole/swoole-src')
->withLicense('https://github.com/swoole/swoole-src/blob/master/LICENSE', Extension::LICENSE_APACHE2)
Expand Down
15 changes: 11 additions & 4 deletions sapi/src/builder/extension/swoole_latest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
$options[] = ' --enable-swoole-coro-time ';
}

$dependentLibraries = ['curl', 'openssl', 'cares', 'zlib', 'brotli', 'nghttp2', 'sqlite3', 'unix_odbc', 'pgsql'];
$dependentLibraries = ['curl', 'openssl', 'cares', 'zlib', 'brotli', 'nghttp2', 'sqlite3', 'unix_odbc', 'pgsql', 'libzstd'];

$dependentExtensions = ['curl', 'openssl', 'sockets', 'mysqlnd', 'pdo'];

$options[] = '--enable-swoole';
Expand All @@ -28,6 +29,9 @@
$options[] = '--with-swoole-odbc=unixODBC,' . UNIX_ODBC_PREFIX;
$options[] = '--enable-swoole-thread';
$options[] = '--enable-zts';
$options[] = '--enable-brotli';
$options[] = '--enable-zstd';

$options[] = '--disable-opcache-jit';

if ($p->isLinux() && $p->getInputOption('with-iouring')) {
Expand All @@ -37,7 +41,7 @@
$p->withExportVariable('URING_LIBS', '$(pkg-config --libs --static liburing)');
}

$ext = (new Extension('swoole'))
$p->addExtension((new Extension('swoole'))
->withHomePage('https://github.com/swoole/swoole-src')
->withLicense('https://github.com/swoole/swoole-src/blob/master/LICENSE', Extension::LICENSE_APACHE2)
->withManual('https://wiki.swoole.com/#/')
Expand All @@ -53,13 +57,16 @@
->withBuildCached(false)
->withAutoUpdateFile()
->withDependentLibraries(...$dependentLibraries)
->withDependentExtensions(...$dependentExtensions);
->withDependentExtensions(...$dependentExtensions)
);

//call_user_func_array([$ext, 'withDependentLibraries'], $dependentLibraries);
//call_user_func_array([$ext, 'withDependentExtensions'], $dependentExtensions);
$p->addExtension($ext);

$p->withVariable('LIBS', '$LIBS ' . ($p->isMacos() ? '-lc++' : '-lstdc++'));
$p->withExportVariable('CARES_CFLAGS', '$(pkg-config --cflags --static libcares)');
$p->withExportVariable('CARES_LIBS', '$(pkg-config --libs --static libcares)');

$p->withExportVariable('ZSTD_CFLAGS', '$(pkg-config --cflags --static libzstd)');
$p->withExportVariable('ZSTD_LIBS', '$(pkg-config --libs --static libzstd)');
};
1 change: 1 addition & 0 deletions setup-swoole-cli-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ while [ $# -gt 0 ]; do
X_VERSION=''
X_APP_VERSION=''
fi

if [[ -n $X_VERSION ]] && [[ -n $X_APP_VERSION ]]; then
{
VERSION=$X_VERSION
Expand Down

0 comments on commit af479c2

Please sign in to comment.