Skip to content

Commit

Permalink
Merge pull request #652 from jingjingxyk/build_native_php
Browse files Browse the repository at this point in the history
Build native php 更新文档
  • Loading branch information
jingjingxyk committed Jun 9, 2024
2 parents 8db1dd0 + 0ed7de6 commit 732b14d
Show file tree
Hide file tree
Showing 18 changed files with 251 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux-aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:
composer install --no-interaction --no-autoloader --no-scripts --profile --no-dev
composer dump-autoload --optimize --profile --no-dev
php prepare.php +inotify +apcu +ds +xlswriter +ssh2 +pgsql +mongodb --with-libavif --with-php-version=${{ env.BUILD_PHP_VERSION }}
php prepare.php +inotify +apcu +ds +xlswriter +ssh2 +pgsql +mongodb --with-build-type=release --with-libavif=1 --with-php-version=${{ env.BUILD_PHP_VERSION }}
bash make-install-deps.sh
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/linux-x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ jobs:
composer install --no-interaction --no-autoloader --no-scripts --profile --no-dev
composer dump-autoload --optimize --profile --no-dev
php prepare.php +inotify +apcu +ds +xlswriter +ssh2 +pgsql +mongodb ${{ inputs.build_type }} ${{ inputs.build_options }} --with-php-version=${{ env.BUILD_PHP_VERSION }} --with-libavif=1
# php prepare.php +inotify +apcu +ds +xlswriter +ssh2 +pgsql +mongodb --with-libavif=1 ${{ inputs.build_type }} ${{ inputs.build_options }} --with-php-version=${{ env.BUILD_PHP_VERSION }}
php prepare.php +inotify +apcu +ds +xlswriter +ssh2 +pgsql +mongodb --with-libavif=1 --with-build-type=release --with-php-version=${{ env.BUILD_PHP_VERSION }}
bash make-install-deps.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos-aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
composer install --no-interaction --no-autoloader --no-scripts --profile
composer dump-autoload --optimize --profile
php prepare.php --without-docker=1 +ds +apcu +xlswriter +ssh2 +pgsql --with-build-type=release --with-php-version=${{ env.BUILD_PHP_VERSION }}
php prepare.php --without-docker=1 +ds +apcu +xlswriter +ssh2 +pgsql --with-build-type=release --with-libavif=1 --with-php-version=${{ env.BUILD_PHP_VERSION }}
- name: Build
run: |
Expand Down
18 changes: 15 additions & 3 deletions build-release-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ while [ $# -gt 0 ]; do
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},127.0.0.1,localhost"
NO_PROXY="${NO_PROXY},::1/128,fe80::/10,fd00::/8,ff00::/8"
NO_PROXY="${NO_PROXY},localhost"
NO_PROXY="${NO_PROXY},.aliyuncs.com,.aliyun.com"
NO_PROXY="${NO_PROXY},.tsinghua.edu.cn,.ustc.edu.cn"
NO_PROXY="${NO_PROXY},.tencent.com"
NO_PROXY="${NO_PROXY},.sourceforge.net"
NO_PROXY="${NO_PROXY},ftpmirror.gnu.org"
NO_PROXY="${NO_PROXY},gitee.com,gitcode.com"
NO_PROXY="${NO_PROXY},.myqcloud.com,.swoole.com"
export NO_PROXY="${NO_PROXY},.npmmirror.com"

WITH_HTTP_PROXY=1
Expand Down Expand Up @@ -98,6 +101,15 @@ while [ $# -gt 0 ]; do
shift $(($# > 0 ? 1 : 0))
done

if [ "$OS" = 'linux' ] ; then
if [ ! "$BASH_VERSION" ] ; then
echo "Please use bash to run this script ($0) " 1>&2
echo "fix : " 1>&2
echo "apk add bash' or sh sapi/quickstart/linux/alpine-init.sh " 1>&2
exit 1
fi
fi

# 构建环境依赖检查
CMDS_NUMS=0
CMDS=("flex" "pkg-config" "cmake" "re2c" "bison" "curl" "automake" "libtool" "clang" "xz" "zip" "unzip" "autoconf")
Expand Down Expand Up @@ -231,7 +243,7 @@ fi


# 定制构建选项
OPTIONS='+apcu +ds +xlswriter +ssh2'
OPTIONS="${OPTIONS} +apcu +ds +xlswriter +ssh2 +uuid "
OPTIONS="${OPTIONS} "
OPTIONS="${OPTIONS} --with-libavif=1"
OPTIONS="${OPTIONS} --with-global-prefix=${LIBRARY_INSTALL_PREFIX}"
Expand Down
46 changes: 29 additions & 17 deletions docs/Cygwin.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,19 @@
## 安装cygwin 和 cygwin 依赖项

> 打开 windows 控制台,并找到 setup-x86_64.exe 所在目录, 执行如下命令
> 打开 windows 控制台,并找到 setup-x86_64.exe 所在目录, 将 setup-x86_64.exe 复制到 `sapi\quickstart\windows\` 目录
> 执行如下命令
```bash
# 安装 cygwin
setup-x86_64.exe --site https://mirrors.ustc.edu.cn/cygwin/

# 安装 cygwin 依赖项
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 icu libicu-devel

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
# 自动安装 cygwin 和 cygwin 依赖项
sapi\quickstart\windows\install-cygwin.bat


# 打开 cygwin64 Terminal
```

构建步骤
------
首先需要安装上述工具和库,然后 Clone 项目,并切换 `ext/swoole`
到对应的分支,如 `4.8.x``master` (`5.0.x`)
构建步骤 - 执行的命令
====
> 运行如下步骤,需要先 打开 cygwin64 Terminal
```shell

Expand All @@ -44,15 +36,15 @@ git clone --recursive https://github.com/swoole/swoole-cli.git

cd swoole-cli

# git submodule update --init
# git submodule update --init -f

bash ./sapi/scripts/cygwin/install-re2c.sh

bash ./sapi/scripts/cygwin/cygwin-config-ext.sh
bash ./sapi/scripts/cygwin/cygwin-config.sh
bash ./sapi/scripts/cygwin/cygwin-build.sh
bash ./sapi/scripts/cygwin/cygwin-archive.sh


```

构建步骤说明
Expand Down Expand Up @@ -126,3 +118,23 @@ libicu-devel
icu
```

## 安装 cygwin 和 安装 cygwin 依赖项 具体执行的命令

> `sapi\quickstart\windows\install-cygwin.bat` 脚本包含的内容
```bash
# 安装 cygwin
setup-x86_64.exe --site https://mirrors.ustc.edu.cn/cygwin/

# 安装 cygwin 依赖项
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 icu libicu-devel

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


# 打开 cygwin64 Terminal
```

62 changes: 61 additions & 1 deletion docs/linux.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
# linux 环境下构建 swoole-cli

## 运行环境要求

1. 容器 docker 运行环境

构建步骤 - 运行命令
====

```shell

git clone --recursive https://github.com/swoole/swoole-cli.git
cd swoole-cli

bash setup-php-runtime.sh
composer install --no-interaction --no-autoloader --no-scripts --profile
composer dump-autoload --optimize --profile

php prepare.php +inotify +apcu +ds +xlswriter +ssh2 +uuid
bash ./make.sh docker-build
bash ./make.sh docker-bash

bash sapi/quickstart/linux/alpine-init.sh

# 进入容器后需要再一次执行此命令
php prepare.php +inotify +apcu +ds +xlswriter +ssh2 +uuid
bash ./make.sh all-library
bash ./make.sh config
bash ./make.sh build
bash ./make.sh archive

./bin/swoole-cli -m
./bin/swoole-cli --ri swoole
file ./bin/swoole-cli

```

构建镜像
====
`Linux` 下需要在容器中构建,因此需要先构建 `swoole-cli-builder:base` 基础镜像。
Expand All @@ -16,7 +53,7 @@
快速初始化构建环境
====

不执行 `./make.sh docker-build [china|ustc|tuna] ` 生成基础镜像
跳过生成容器基础镜像
使用如下命令快速进入容器环境
便捷调整构建环境

Expand Down Expand Up @@ -73,3 +110,26 @@ make: ext/opcache/minilua: No such file or directory
rm ext/opcache/minilua
./make.sh build
```

docker no found
----
> 快速安装 docker 运行环境
```bash

bash sapi/quickstart/linux/install-docker.sh

# 使用中国镜像
bash sapi/quickstart/linux/install-docker.sh --mirror china


```

fix slow alpine apk installations
----

```bash

bash sapi/quickstart/linux/alpine-init.sh --mirror china

```
36 changes: 34 additions & 2 deletions docs/macOS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
# 步骤
# macOS 环境下构建 swoole-cli

构建步骤 - 运行命令
====

```shell

git clone --recursive https://github.com/swoole/swoole-cli.git
cd swoole-cli

bash setup-php-runtime.sh
composer install --no-interaction --no-autoloader --no-scripts --profile
composer dump-autoload --optimize --profile

php prepare.php --without-docker=1 +inotify +apcu +ds +xlswriter +ssh2 +uuid

bash sapi/quickstart/macos/macos-init.sh

bash ./make.sh all-library
bash ./make.sh config
bash ./make.sh build
bash ./make.sh archive

./bin/swoole-cli -m
./bin/swoole-cli --ri swoole
xattr -cr ./bin/swoole-cli
otool -L ./bin/swoole-cli


```

构建步骤简述
====

0. 清理 `brew` 安装的软件
1. 执行 `php prepare.php --without-docker=1`
1. 执行 `php prepare.php --without-docker=1` 生成构建shell 脚本
2. 编译所有依赖的库 `./make.sh all-library`
3. 配置 `./make.sh config`
4. 构建 `./make.sh build`
Expand Down
23 changes: 13 additions & 10 deletions prepare.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,19 @@
EOF;
$proxyConfig .= PHP_EOL;
$proxyConfig .= <<<'EOF'
export 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"
export NO_PROXY="${NO_PROXY},127.0.0.1,localhost"
export NO_PROXY="${NO_PROXY},.aliyuncs.com,.aliyun.com,.tencent.com"
export NO_PROXY="${NO_PROXY},.tsinghua.edu.cn,.ustc.edu.cn,.npmmirror.com"
export NO_PROXY="${NO_PROXY},dl-cdn.alpinelinux.org"
export NO_PROXY="${NO_PROXY},deb.debian.org,security.debian.org"
export NO_PROXY="${NO_PROXY},archive.ubuntu.com,security.ubuntu.com"
export NO_PROXY="${NO_PROXY},pypi.python.org,bootstrap.pypa.io"
export NO_PROXY="${NO_PROXY},.sourceforge.net"
export NO_PROXY="${NO_PROXY},.gitee.com"
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},.aliyuncs.com,.aliyun.com,.tencent.com"
NO_PROXY="${NO_PROXY},.tsinghua.edu.cn,.ustc.edu.cn,.npmmirror.com"
NO_PROXY="${NO_PROXY},ftpmirror.gnu.org"
NO_PROXY="${NO_PROXY},gitee.com,gitcode.com"
NO_PROXY="${NO_PROXY},.myqcloud.com,.swoole.com"
NO_PROXY="${NO_PROXY},dl-cdn.alpinelinux.org"
NO_PROXY="${NO_PROXY},deb.debian.org,security.debian.org"
NO_PROXY="${NO_PROXY},archive.ubuntu.com,security.ubuntu.com"
NO_PROXY="${NO_PROXY},pypi.python.org,bootstrap.pypa.io"
export NO_PROXY="${NO_PROXY},localhost"


EOF;
$p->setProxyConfig($proxyConfig, $http_proxy);
Expand Down
7 changes: 3 additions & 4 deletions sapi/download-box/download-box-get-archive-from-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ mkdir -p ${__PROJECT__}/var/download-box/
cd ${__PROJECT__}/var/download-box/

if [ -f "${__PROJECT__}/sapi/PHP-VERSION.conf" ] ; then
DOMAIN='https://github.com/swoole/swoole-cli/releases/download/v5.1.1.0/'
ALL_DEPS_HASH="1b8bbd1b64e196b1d56c940fc62079fac8c2cd106867f9534fadb40ee02beaec"
DOMAIN='https://github.com/swoole/swoole-cli/releases/download/v5.1.3.0/'
ALL_DEPS_HASH="5fa1485c2408f05cbc548712917e6dbb8ecd5a631b558d6d512d4a6671f071e5"
else
DOMAIN='https://github.com/swoole/build-static-php/releases/download/v1.1.0/'
ALL_DEPS_HASH="49fc4e76422c3b182258c95def6c2cbb45d952bde39cec958f3a17ec0e579116"
Expand All @@ -44,8 +44,7 @@ while [ $# -gt 0 ]; do
done


URL="${DOMAIN}/all-archive.zip"
# URL="${DOMAIN}/all-deps.zip" # 下一个版本启用此命名
URL="${DOMAIN}/all-deps.zip"

test -f all-deps.zip || curl -Lo all-deps.zip ${URL}

Expand Down
4 changes: 2 additions & 2 deletions sapi/quickstart/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
```shell

# 自动下载 cygwin
sapi/quickstart/windows/download-cygwin.bat
sapi\quickstart\windows\download-cygwin.bat
# 自动安装 cygwin
sapi/quickstart/windows/install-cygwin.bat
sapi\quickstart\windows\install-cygwin.bat


```
Expand Down
3 changes: 3 additions & 0 deletions sapi/src/builder/extension/swoole_latest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@
$p->addExtension($ext);
$libs = $p->isMacos() ? '-lc++' : ' -lstdc++ ';
$p->withVariable('LIBS', '$LIBS ' . $libs);

$p->withExportVariable('CARES_CFLAGS', '$(pkg-config --cflags --static libcares)');
$p->withExportVariable('CARES_LIBS', '$(pkg-config --libs --static libcares)');
};
3 changes: 3 additions & 0 deletions sapi/src/builder/extension/swoole_v4080.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@
$p->addExtension($ext);
$libs = $p->isMacos() ? '-lc++' : ' -lstdc++ ';
$p->withVariable('LIBS', '$LIBS ' . $libs);

$p->withExportVariable('CARES_CFLAGS', '$(pkg-config --cflags --static libcares)');
$p->withExportVariable('CARES_LIBS', '$(pkg-config --libs --static libcares)');
};
14 changes: 6 additions & 8 deletions sapi/src/builder/extension/swoole_v5000.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
$swoole_tag = 'v5.0.3';
$file = "swoole-{$swoole_tag}.tar.gz";

$dependentLibraries = ['curl', 'openssl', 'cares', 'zlib', 'brotli', 'nghttp2'];
$dependentLibraries = ['curl', 'openssl', 'cares', 'zlib', 'brotli', 'nghttp2', 'pgsql'];
$dependentExtensions = ['curl', 'openssl', 'sockets', 'mysqlnd', 'pdo'];
$options = ' --enable-swoole --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-cares ';
$options = ' --enable-swoole --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-cares --enable-swoole-pgsql ';
$options .= ' --enable-swoole-coro-time --enable-thread-context ';

$options .= ' --with-brotli-dir=' . BROTLI_PREFIX;
$options .= ' --with-nghttp2-dir=' . NGHTTP2_PREFIX;

if ($p->getInputOption('with-swoole-pgsql')) {
$dependentLibraries[] = 'pgsql';
}

$ext = (new Extension('swoole_v5000'))
->withAliasName('swoole')
->withHomePage('https://github.com/swoole/swoole-src')
Expand All @@ -32,13 +28,15 @@
git clone -b {$swoole_tag} --depth=1 https://github.com/swoole/swoole-src.git
EOF
)
->withBuildCached(false);
;
->withBuildCached(false);;

call_user_func_array([$ext, 'withDependentLibraries'], $dependentLibraries);
call_user_func_array([$ext, 'withDependentExtensions'], $dependentExtensions);

$p->addExtension($ext);
$libs = $p->isMacos() ? '-lc++' : ' -lstdc++ ';
$p->withVariable('LIBS', '$LIBS ' . $libs);

$p->withExportVariable('CARES_CFLAGS', '$(pkg-config --cflags --static libcares)');
$p->withExportVariable('CARES_LIBS', '$(pkg-config --libs --static libcares)');
};
Loading

0 comments on commit 732b14d

Please sign in to comment.