Skip to content

Commit

Permalink
Feature update docs (#149)
Browse files Browse the repository at this point in the history
* 更新文档

* quickstart 添加 可跳过编译依赖库的容器

* fix error

* 允许自定义安装目录

* define php version

* 更新缓存目录

* 调整分布构建依赖库容器镜像默认目录

* update

* update

* update

* update

* update macos lld

* update

* update swoole to v5.0.3

* update macos build yml

* update macos build yml

* add brew install llvm

* 更新README.md

* update dockerfile

* 更新 macos 构建文档
  • Loading branch information
jingjingxyk committed May 21, 2023
1 parent fc1ca40 commit 38327b4
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux-aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
set -eux
# export PATH=/work/bin/runtime:$PATH # 容器已经内置 php 和 composer 容器
composer update --no-dev --optimize-autoloader
php prepare.php +inotify +apcu +ds
php prepare.php +inotify +apcu +ds --with-global-prefix=/usr
chmod a+x make.sh
head -n 20 make.sh
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux-x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
set -eux
# export PATH=/work/bin/runtime:$PATH # 容器已经内置 php 和 composer 容器
composer update --no-dev --optimize-autoloader
php prepare.php +inotify +apcu +ds
php prepare.php +inotify +apcu +ds --with-global-prefix=/usr
chmod a+x make.sh
head -n 20 make.sh
- name: Build
Expand Down
38 changes: 22 additions & 16 deletions .github/workflows/macos-x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
run: |
env
echo $HOME
brew install wget curl libtool automake gettext coreutils re2c binutils
brew install wget curl libtool automake gettext coreutils re2c binutils llvm
brew uninstall --ignore-dependencies oniguruma
brew uninstall --ignore-dependencies brotli
brew uninstall --ignore-dependencies freetype
Expand All @@ -23,40 +23,46 @@ jobs:
ln -sf /usr/local/bin/glibtoolize /usr/local/bin/libtoolize
sudo xcode-select --switch /Applications/Xcode.app
# export MACOSX_DEPLOYMENT_TARGET=12.6
CURRENT_USER=$(whoami)
echo ${CURRENT_USER}
sudo mkdir -p /usr/local/swoole-cli
sudo chown -R ${CURRENT_USER}:staff /usr/local/swoole-cli
git submodule update --init
- name: Prepare runtime
run: |
sudo mkdir -p pool/lib
sudo mkdir -p pool/ext
sudo mkdir -p bin/runtime
sudo bash sapi/quickstart/setup-php-runtime.sh
mkdir -p pool/lib
mkdir -p pool/ext
mkdir -p bin/runtime
bash sapi/quickstart/setup-php-runtime.sh
export PATH=${GITHUB_WORKSPACE}/bin/runtime:$PATH
sudo bash sapi/download-box/download-box-get-archive-from-server.sh
bash sapi/download-box/download-box-get-archive-from-server.sh
- name: prepare
run: |
export PATH=${GITHUB_WORKSPACE}/bin/runtime:$PATH
sudo composer update --no-dev --optimize-autoloader
sudo php prepare.php --without-docker=1 --with-build-type=release +ds +apcu
composer update --no-dev --optimize-autoloader
php prepare.php --without-docker=1 --with-build-type=release +ds +apcu
- name: Cache all-library
uses: actions/cache@v3
id: all-library-cache
with:
path: ~/.swoole-cli
# path: ~/.swoole-cli
path: /usr/local/swoole-cli
key: ${{ runner.os }}-build-all-library
- name: Build all-library
if: ${{ steps.all-library-cache.outputs.cache-hit != 'true' }}
run: |
sudo chmod a+x ./make.sh
sudo ./make.sh all-library
export PATH=${GITHUB_WORKSPACE}/bin/runtime:$PATH
chmod a+x ./make.sh
./make.sh all-library
- name: Build
run: |
sudo chmod a+x ./make.sh
sudo ./make.sh config
sudo ./make.sh build
sudo ./make.sh archive
export PATH=${GITHUB_WORKSPACE}/bin/runtime:$PATH
chmod a+x ./make.sh
./make.sh config
./make.sh build
./make.sh archive
- name: Show Build Result
run: |
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
是全部静态编译打包的,不依赖任何操作系统的`so`动态链接库,具备非常好的移植性,可以在任意 `Linux`/`macOS`/`Windows(CygWin)`
系统之间复制,下载即可使用。

> 作为 PHP 开发者都应该知道 PHP 有两种运行模式:php-fpm和php-cli,那么在 Swoole 5.0中将迎来一种新的运行模式:swoole-cli。
> <strong>Swoole 将像node.js这样作为独立程序提供给用户,而不是作为PHP的一个扩展</strong>。
> 作为 PHP 开发者都应该知道 PHP 有两种运行模式:php-fpm和php-cli,那么在 Swoole 5.0中将迎来一种新的运行模式:swoole-cli。
> <strong>Swoole 将像node.js这样作为独立程序提供给用户,而不是作为PHP的一个扩展</strong>。
> 除此之外swoole-cli会尽可能地对php-src进行裁剪,移除一些不用的机制、模块、扩展、函数、类型、常量、代码,使得整个程序可以在几分钟之内编译完成。
## 相关文章

- [Swoole-Cli 介绍](https://zhuanlan.zhihu.com/p/581695339)
- [Swoole-Cli 使用说明](https://wenda.swoole.com/detail/108876)
- [Swoole v5.0 版本新特性预览之新的运行模式](https://zhuanlan.zhihu.com/p/459983471)
- [Swoole-Cli v5.0.0 版本新特性预览之新的运行模式](https://zhuanlan.zhihu.com/p/459983471)
- [Swoole-Cli v5.0.1 PHP 的二进制发行版](https://zhuanlan.zhihu.com/p/581695339)
- [Swoole-Cli v5.0.2 增加 opcache/readline 扩展,强化 Cli-Server](https://zhuanlan.zhihu.com/p/610014616)

## 下载`swoole-cli`发行版

Expand All @@ -29,6 +31,7 @@
- [swoole-cli 构建选项文档](docs/options.md)
- [打包成二进制可执行文件 文档](sapi/samples/sfx/README.md)
- [swoole-cli 搭建依赖库镜像服务](sapi/download-box/README.md)
- [快速开始构建环境](sapi/quickstart/README.md)

## Clone

Expand Down
4 changes: 2 additions & 2 deletions docs/macOS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 步骤

0. 清理 `brew` 安装的软件
1. 执行 `php prepare.php`
1. 执行 `php prepare.php --without-docker=1`
2. 编译所有依赖的库 `./make.sh all-library`
3. 配置 `./make.sh config`
4. 构建 `./make.sh build`
Expand All @@ -23,7 +23,7 @@ brew uninstall --ignore-dependencies capstone

## 缺少 bison

下载源代码,自行编译安装
下载源代码,自行编译安装 (此问题已解决,安装依赖库时 已经包含bison源码编译)

## 缺少`libtool`

Expand Down
8 changes: 8 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ without-docker

> `macOS` 系统无法使用 `docker`,需指定此参数
with-global-prefix
----
设置依赖库安装目录前缀
默认安装目录前缀: `/usr/local/swoole-cli/`

```shell
./prepare.php --with-global-prefix=/usr/local/swoole-cli/
```

with-dependency-graph
----
Expand Down
8 changes: 7 additions & 1 deletion prepare.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@

use SwooleCli\Preprocessor;

const BUILD_PHP_VERSION = '8.1.12';

$homeDir = getenv('HOME');
$p = Preprocessor::getInstance();
$p->parseArguments($argc, $argv);

// Sync code from php-src
$p->setPhpSrcDir($homeDir . '/.phpbrew/build/php-8.1.12');
$p->setPhpSrcDir($homeDir . '/.phpbrew/build/php-' . BUILD_PHP_VERSION);

// Compile directly on the host machine, not in the docker container
if ($p->getInputOption('without-docker')) {
$p->setWorkDir(__DIR__);
$p->setBuildDir(__DIR__ . '/thirdparty');
}

if ($p->getInputOption('with-global-prefix')) {
$p->setGlobalPrefix($p->getInputOption('with-global-prefix'));
}

if ($p->getOsType() == 'macos') {
$p->setExtraLdflags('-undefined dynamic_lookup');
}
Expand Down
15 changes: 3 additions & 12 deletions sapi/download-box/download-box-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,10 @@ test -d extensions && test -d libraries && zip -6 -r all-archive.zip extensions
cd ${__PROJECT__}/var

TIME=$(date -u '+%Y%m%dT%H%M%SZ')
VERSION="download-box-nginx-alpine-"${TIME}
SWOOLE_CLI_IMAGE="docker.io/phpswoole/swoole-cli-builder:donload-box-v5.0.2"
IMAGE="docker.io/jingjingxyk/build-swoole-cli:${VERSION}"
ALIYUN_IMAGE="registry.cn-beijing.aliyuncs.com/jingjingxyk-public/app:build-swoole-cli-${VERSION}"
VERSION="1.7"
TAG="download-box-nginx-alpine-${VERSION}-${TIME}"
IMAGE="docker.io/phpswoole/swoole-cli-builder:${TAG}"

docker build -t ${IMAGE} -f ./Dockerfile-dowload-box . --progress=plain

docker tag ${IMAGE} ${ALIYUN_IMAGE}
docker tag ${IMAGE} ${SWOOLE_CLI_IMAGE}

echo ${IMAGE} >download-box.txt
echo ${ALIYUN_IMAGE} >download-box-aliyun.txt

docker push ${ALIYUN_IMAGE}
docker push ${IMAGE}
docker push ${SWOOLE_CLI_IMAGE}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositorie
RUN apk update

RUN apk add vim alpine-sdk xz autoconf automake linux-headers clang-dev clang lld libtool cmake bison re2c gettext coreutils
RUN apk add flex pkgconf ca-certificates
RUN apk add bash
RUN apk add flex pkgconf ca-certificates zip unzip 7zip lzip
RUN apk add bash curl wget git tini ca-certificates openssl openssl-dev
WORKDIR /work

Expand Down Expand Up @@ -48,7 +47,7 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositorie
RUN apk update

RUN apk add vim alpine-sdk xz autoconf automake linux-headers clang-dev clang lld libtool cmake bison re2c gettext coreutils
RUN apk add bash
RUN apk add flex pkgconf ca-certificates zip unzip 7zip lzip
RUN apk add bash curl wget git tini ca-certificates openssl openssl-dev
WORKDIR /work

Expand All @@ -63,48 +62,7 @@ RUN chmod a+x /usr/local/bin/swoole-cli
RUN chmod a+x /usr/local/bin/composer.phar
ENV COMPOSER_ALLOW_SUPERUSER=1

COPY --from=builder-all-library /usr/brotli/ /usr/brotli/
COPY --from=builder-all-library /usr/cares /usr/cares
COPY --from=builder-all-library /usr/libiconv /usr/libiconv
# COPY --from=builder-all-library /usr/libidn2 /usr/libidn2
COPY --from=builder-all-library /usr/openssl/ /usr/openssl/

COPY --from=builder-all-library /usr/libxml2/ /usr/libxml2/
COPY --from=builder-all-library /usr/libxslt/ /usr/libxslt/

COPY --from=builder-all-library /usr/bzip2 /usr/bzip2
COPY --from=builder-all-library /usr/zlib /usr/zlib

COPY --from=builder-all-library /usr/nghttp2 /usr/nghttp2
COPY --from=builder-all-library /usr/nghttp3 /usr/nghttp3
COPY --from=builder-all-library /usr/ngtcp2 /usr/ngtcp2
COPY --from=builder-all-library /usr/libssh2 /usr/libssh2

COPY --from=builder-all-library /usr/liblz4 /usr/liblz4
COPY --from=builder-all-library /usr/liblzma /usr/liblzma
COPY --from=builder-all-library /usr/libzstd /usr/libzstd
COPY --from=builder-all-library /usr/libzip/ /usr/libzip/

COPY --from=builder-all-library /usr/curl/ /usr/curl/
COPY --from=builder-all-library /usr/oniguruma/ /usr/oniguruma/
COPY --from=builder-all-library /usr/sqlite3/ /usr/sqlite3/

COPY --from=builder-all-library /usr/icu/ /usr/icu/

COPY --from=builder-all-library /usr/gmp/ /usr/gmp/
COPY --from=builder-all-library /usr/libsodium/ /usr/libsodium/
COPY --from=builder-all-library /usr/ncurses /usr/ncurses
COPY --from=builder-all-library /usr/readline /usr/readline


COPY --from=builder-all-library /usr/libjpeg /usr/libjpeg
COPY --from=builder-all-library /usr/libpng /usr/libpng
COPY --from=builder-all-library /usr/libgif /usr/libgif
COPY --from=builder-all-library /usr/libwebp /usr/libwebp
COPY --from=builder-all-library /usr/freetype /usr/freetype

COPY --from=builder-all-library /usr/libyaml /usr/libyaml
COPY --from=builder-all-library /usr/imagemagick /usr/imagemagick
COPY --from=builder-all-library /usr/local/swoole-cli /usr/local/swoole-cli

# RUN cp -f /etc/apk/repositories.save /etc/apk/repositories

Expand Down
2 changes: 1 addition & 1 deletion sapi/multistage-build-dependencies-container/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ sh make.sh build
## 为了方便分发,把容器镜像导出为文件

> 使用 抢占式 高配置 的云服务器 来构建
> 目的:节省网络流量 (单个容器网络流量超过 1GB)
> 目的:节省网络流量 (单个文件不压缩情况下,大小超过 1GB)
```bash

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ mkdir -p ${__PROJECT__}/var

ARCH=$(uname -m)

TAG="1.7-${ARCH}"
TIME=$(date -u '+%Y%m%dT%H%M%SZ')
VERSION="1.7"
TAG="all-dependencies-alpine-${VERSION}-${ARCH}-${TIME}"
IMAGE="docker.io/phpswoole/swoole-cli-builder:${TAG}"

USE_COMPOSER_MIRROR=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ done
cd ${__PROJECT__}/var

GIT_BRANCH=main
test -d swoole-cli && git -C swoole-cli pull origin ${GIT_BRANCH} --depth=1 --progress --rebase=true --allow-unrelated-histories
test -d swoole-cli || git clone -b ${GIT_BRANCH} --depth=1 https://github.com/swoole/swoole-cli.git
test -d swoole-cli && rm -rf swoole-cli
git clone -b ${GIT_BRANCH} --depth=1 --recursive https://github.com/swoole/swoole-cli.git

cd ${__PROJECT__}/var/swoole-cli

Expand All @@ -65,7 +65,7 @@ mkdir -p pool/ext
cd ${__PROJECT__}/var

awk 'BEGIN { cmd="cp -ri libraries/* swoole-cli/pool/lib" ; print "n" |cmd; }'
awk 'BEGIN { cmd="cp -ri extensions/* swoole-cli/pool/ext"; print "n" |cmd; }'
awk 'BEGIN { cmd="cp -ri extensions/* swoole-cli/pool/ext" ; print "n" |cmd; }'

cd ${__PROJECT__}/var/swoole-cli

Expand Down
8 changes: 4 additions & 4 deletions sapi/quickstart/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
curl -fsSL https://get.docker.com -o get-docker.sh
bash get-docker.sh

# 使用镜像
# 使用 阿里云镜像
bash get-docker.sh --mirror Aliyun

```
Expand Down Expand Up @@ -49,12 +49,12 @@ bash sapi/quickstart/linux/run-alpine-3.16-container.sh
bash sapi/quickstart/linux/connection-swoole-cli-alpine.sh

# 准备构建基础软件
bash sapi/quickstart/linux/alpine-3.16-init.sh
sh sapi/quickstart/linux/alpine-3.16-init.sh


# 准备构建基础软件 使用中科大镜像源

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

```

Expand Down Expand Up @@ -105,7 +105,7 @@ git submodule update --init

```bash

# compser 使用阿里云镜像
# composer 使用阿里云镜像
# composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

composer update --no-dev --optimize-autoloader
Expand Down
2 changes: 1 addition & 1 deletion sapi/quickstart/linux/alpine-3.16-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ esac
apk update

apk add vim alpine-sdk xz autoconf automake linux-headers clang-dev clang lld libtool cmake bison re2c gettext coreutils
apk add bash
apk add bash 7zip zip unzip flex pkgconf ca-certificates

apk add wget git curl
2 changes: 1 addition & 1 deletion sapi/quickstart/linux/debian-11-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ esac
apt update -y
apt install -y git curl wget ca-certificates
apt install -y xz-utils autoconf automake libclang-13-dev clang lld libtool cmake bison re2c gettext coreutils lzip zip unzip
apt install -y pkg-config bzip2 flex
apt install -y pkg-config bzip2 flex p7zip

# apt install build-essential linux-headers-$(uname -r)
10 changes: 5 additions & 5 deletions sapi/quickstart/linux/extra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

# alpine

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

## debian

bash bash sapi/quickstart/linux/extra/debian-php-init.sh
bash sapi/quickstart/linux/extra/debian-php-init.sh

```

Expand All @@ -18,10 +18,10 @@ bash bash sapi/quickstart/linux/extra/debian-php-init.sh

```

## c c++编译器
## c c++编译器 组合

> alpine 使用gcc 默认链接到musl-gcc 不需要把gcc指定为 musl-gcc
> debian 使用gcc 需要指定编译器 musl-gcc
> alpine 使用 gcc 默认链接到musl-gcc 不需要把gcc指定为 musl-gcc
> debian 使用 gcc 需要指定编译器为 musl-gcc
- 组合一 clang clang++
- 组合二 musl-gcc g++
Expand Down
Loading

0 comments on commit 38327b4

Please sign in to comment.