mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
Update gnu-docker and fix icu build on glibc
This commit is contained in:
parent
23bfad6f87
commit
4eeb48cdc2
5
bin/spc
5
bin/spc
@ -4,6 +4,11 @@
|
||||
use SPC\ConsoleApplication;
|
||||
use SPC\exception\ExceptionHandler;
|
||||
|
||||
// Load custom php if exists
|
||||
if (PHP_OS_FAMILY !== 'Windows' && PHP_BINARY !== (__DIR__ . '/php') && file_exists(__DIR__ . '/php') && is_executable(__DIR__ . '/php')) {
|
||||
pcntl_exec(__DIR__ . '/php', $argv);
|
||||
}
|
||||
|
||||
if (file_exists(dirname(__DIR__) . '/vendor/autoload.php')) {
|
||||
// Current: ./bin (git/project mode)
|
||||
require_once dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
@ -119,4 +119,8 @@ MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot"
|
||||
# shellcheck disable=SC2068
|
||||
# shellcheck disable=SC2086
|
||||
# shellcheck disable=SC2090
|
||||
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-v2 bin/spc $@
|
||||
if [ "$SPC_DOCKER_DEBUG" = "yes" ]; then
|
||||
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-v2
|
||||
else
|
||||
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-v2 bin/spc $@
|
||||
fi
|
||||
|
||||
@ -59,6 +59,22 @@ RUN yum clean all && \
|
||||
yum makecache && \
|
||||
yum update -y
|
||||
|
||||
RUN yum install -y centos-release-scl
|
||||
|
||||
RUN if [ "$BASE_ARCH" = "aarch64" ]; then \
|
||||
sed -i 's|mirror.centos.org/centos|vault.centos.org/altarch|g' /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo ; \
|
||||
sed -i 's|mirror.centos.org/centos|vault.centos.org/altarch|g' /etc/yum.repos.d/CentOS-SCLo-scl.repo ; \
|
||||
else \
|
||||
sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo ; \
|
||||
fi
|
||||
RUN sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/*.repo && \
|
||||
sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo
|
||||
|
||||
RUN yum update -y && \
|
||||
yum install -y devtoolset-7-gcc-*
|
||||
RUN echo "source scl_source enable devtoolset-7" >> /etc/bashrc
|
||||
RUN source /etc/bashrc
|
||||
|
||||
RUN curl -o cmake.tgz -fsSL https://github.com/Kitware/CMake/releases/download/v3.31.4/cmake-3.31.4-linux-$BASE_ARCH.tar.gz && \
|
||||
mkdir /cmake && \
|
||||
tar -xzf cmake.tgz -C /cmake --strip-components 1
|
||||
@ -73,9 +89,9 @@ RUN /app/bin/php /app/bin/composer install --no-dev --classmap-authoritative
|
||||
ENV PATH="/app/bin:/cmake/bin:$PATH"
|
||||
ENV SPC_SKIP_DOCTOR_CHECK_ITEMS="if musl-wrapper is installed,if musl-cross-make is installed"
|
||||
|
||||
|
||||
ADD ./config/env.ini /app/config/env.ini
|
||||
RUN bin/spc doctor --auto-fix --debug
|
||||
RUN git clone https://github.com/dunglas/frankenphp.git --depth=1 /frankenphp
|
||||
EOF
|
||||
fi
|
||||
|
||||
@ -97,8 +113,20 @@ MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/dist:/app/dist"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/downloads:/app/downloads"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot"
|
||||
|
||||
# Apply env in temp env file
|
||||
echo 'SPC_SKIP_DOCTOR_CHECK_ITEMS="if musl-wrapper is installed,if musl-cross-make is installed"' > /tmp/spc-gnu-docker.env
|
||||
echo 'CC=/opt/rh/devtoolset-7/root/usr/bin/gcc' >> /tmp/spc-gnu-docker.env
|
||||
echo 'CXX=/opt/rh/devtoolset-7/root/usr/bin/g++' >> /tmp/spc-gnu-docker.env
|
||||
echo 'AR=/opt/rh/devtoolset-7/root/usr/bin/ar' >> /tmp/spc-gnu-docker.env
|
||||
echo 'LD=/opt/rh/devtoolset-7/root/usr/bin/ld' >> /tmp/spc-gnu-docker.env
|
||||
echo 'SPC_DEFAULT_C_FLAGS=-fPIC' >> /tmp/spc-gnu-docker.env
|
||||
echo 'SPC_NO_MUSL_PATH=yes' >> /tmp/spc-gnu-docker.env
|
||||
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env
|
||||
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil"' >> /tmp/spc-gnu-docker.env
|
||||
|
||||
# Run docker
|
||||
# shellcheck disable=SC2068
|
||||
# shellcheck disable=SC2086
|
||||
# shellcheck disable=SC2090
|
||||
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH bin/spc $@
|
||||
|
||||
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH # bin/spc $@
|
||||
|
||||
@ -34,25 +34,6 @@ but **statically linked with all other dependencies**.
|
||||
The latest version of static-php-cli includes the `bin/spc-gnu-docker` script,
|
||||
which can create a CentOS 7.x (glibc-2.17) Docker container with one click and build a glibc compatible PHP static binary in the container.
|
||||
|
||||
First, clone the repository of this project and add the following content to the `config/env.custom.ini` file:
|
||||
|
||||
```ini
|
||||
; Modify this file name to `env.custom.ini`, and run `bin/spc-gnu-docker`,
|
||||
; you can compile a GNU libc based static binary !
|
||||
[global]
|
||||
SPC_SKIP_DOCTOR_CHECK_ITEMS="if musl-wrapper is installed,if musl-cross-make is installed"
|
||||
|
||||
[linux]
|
||||
CC=gcc
|
||||
CXX=g++
|
||||
AR=ar
|
||||
LD=ld
|
||||
SPC_DEFAULT_C_FLAGS=-fPIC
|
||||
SPC_NO_MUSL_PATH=yes
|
||||
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"
|
||||
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil"
|
||||
```
|
||||
|
||||
Then, run the following command once.
|
||||
The first run will take a long time because it needs to download the CentOS 7.x image and some build tools.
|
||||
|
||||
|
||||
@ -29,25 +29,6 @@ musl-libc 是一个轻量级的 libc 实现,它的目标是与 glibc 兼容,
|
||||
|
||||
最新版的 static-php-cli 内置了 `bin/spc-gnu-docker` 脚本,可以一键创建一个 CentOS 7.x (glibc-2.17) 的 Docker 容器,并在容器中构建 glibc 兼容的 PHP 静态二进制文件。
|
||||
|
||||
请先克隆本项目的仓库,并将下面的内容添加到 `config/env.custom.ini` 文件中:
|
||||
|
||||
```ini
|
||||
; Modify this file name to `env.custom.ini`, and run `bin/spc-gnu-docker`,
|
||||
; you can compile a GNU libc based static binary !
|
||||
[global]
|
||||
SPC_SKIP_DOCTOR_CHECK_ITEMS="if musl-wrapper is installed,if musl-cross-make is installed"
|
||||
|
||||
[linux]
|
||||
CC=gcc
|
||||
CXX=g++
|
||||
AR=ar
|
||||
LD=ld
|
||||
SPC_DEFAULT_C_FLAGS=-fPIC
|
||||
SPC_NO_MUSL_PATH=yes
|
||||
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"
|
||||
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil"
|
||||
```
|
||||
|
||||
然后,先运行一次以下命令。首次运行时时间较长,因为需要下载 CentOS 7.x 的镜像和一些编译工具。
|
||||
|
||||
```bash
|
||||
@ -73,4 +54,4 @@ glibc 构建为扩展的特性,不属于默认 static-php 的支持范围。
|
||||
如果你需要不使用 Docker 构建基于 glibc 的二进制,请参考 `bin/spc-gnu-docker` 脚本,手动构建一个类似的环境。
|
||||
|
||||
由于 glibc 二进制不是项目的主要目标,一般情况下我们不会额外测试 glibc 下的各个库和扩展的兼容性。
|
||||
任何特定库如果在 musl-libc 上构建成功,但在 glibc 上构建失败,请提交 issue,我们将会单独解决。
|
||||
任何特定库如果在 musl-libc 上构建成功,但在 glibc 上构建失败,请提交 issue,我们将会单独解决。
|
||||
|
||||
@ -16,7 +16,7 @@ class icu extends LinuxLibraryBase
|
||||
{
|
||||
$cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"';
|
||||
$cxxflags = 'CXXFLAGS="-std=c++17"';
|
||||
$ldflags = 'LDFLAGS="-static"';
|
||||
$ldflags = $this->builder->libc !== 'glibc' ? 'LDFLAGS="-static"' : '';
|
||||
shell()->cd($this->source_dir . '/source')
|
||||
->exec(
|
||||
"{$cppflags} {$cxxflags} {$ldflags} " .
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user