Skip to content

Commit fdbcdff

Browse files
authored
Merge pull request #928 from jingjingxyk/build_native_php
Build native php
2 parents d3ce389 + a274e22 commit fdbcdff

File tree

9 files changed

+194
-88
lines changed

9 files changed

+194
-88
lines changed

.github/workflows/build-alpine-builder-container.sh

+25-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -exu
44
__DIR__=$(
@@ -16,7 +16,7 @@ cd ${__PROJECT__}/var/build-github-action-container/
1616

1717
cp -f ${__PROJECT__}/sapi/quickstart/linux/alpine-init.sh .
1818

19-
cat > Dockerfile <<'EOF'
19+
cat >Dockerfile <<'EOF'
2020
FROM alpine:3.18
2121
2222
ENV TZ=Etc/UTC
@@ -25,7 +25,6 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
2525
ADD ./alpine-init.sh /alpine-init.sh
2626
2727
RUN sh /alpine-init.sh
28-
# RUN sh /alpine-init.sh --mirror china
2928
3029
RUN uname -m
3130
RUN mkdir /work
@@ -35,9 +34,25 @@ ENTRYPOINT ["tini", "--"]
3534
3635
EOF
3736

38-
39-
40-
PLATFORM='linux/amd64'
37+
PLATFORM=''
38+
ARCH=$(uname -m)
39+
case $ARCH in
40+
'x86_64')
41+
PLATFORM='linux/amd64'
42+
;;
43+
'aarch64')
44+
PLATFORM='linux/arm64'
45+
;;
46+
'riscv64')
47+
PLATFORM="linux/riscv64"
48+
;;
49+
'mips64le')
50+
PLATFORM="linux/mips64le"
51+
;;
52+
'loongarch64')
53+
PLATFORM="linux/mips64le"
54+
;;
55+
esac
4156

4257
while [ $# -gt 0 ]; do
4358
case "$1" in
@@ -51,18 +66,14 @@ while [ $# -gt 0 ]; do
5166
shift $(($# > 0 ? 1 : 0))
5267
done
5368

54-
55-
5669
IMAGE='swoole-cli-builder:latest'
57-
docker buildx build -t ${IMAGE} -f ./Dockerfile . --platform ${PLATFORM}
70+
docker buildx build -t ${IMAGE} -f ./Dockerfile . --platform ${PLATFORM}
5871

5972
docker save -o "swoole-cli-builder-image.tar" ${IMAGE}
6073

61-
62-
6374
# alpine 可设置的架构选项
6475
# https://hub.docker.com/_/alpine/tags
65-
:<<'EOF'
76+
: <<'EOF'
6677
linux/386
6778
linux/amd64
6879
linux/arm/v6
@@ -72,4 +83,5 @@ linux/ppc64le
7283
linux/s390x
7384
EOF
7485

75-
86+
# 龙芯架构
87+
# https://cr.loongnix.cn/search
+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: build-swoole-cli-linux-aarch64-qemu
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
linux-aarch64-qemu:
7+
if: 0
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Show Environment Info
12+
run: |
13+
lscpu
14+
echo $PATH
15+
env
16+
docker info
17+
id -u
18+
id -g
19+
who
20+
cat /etc/os-release
21+
hostnamectl
22+
uname -s
23+
uname -m
24+
uname -r
25+
export IPV6=$(ip -6 address show | grep inet6 | awk '{print $2}' | cut -d'/' -f1 | sed -n '2p')
26+
export IPV4=$(ip -4 address show | grep inet | grep -v 127.0.0 | awk '{print $2}' | cut -d'/' -f1 | sed -n '1p')
27+
echo $IPV4
28+
echo $IPV6
29+
echo "X_IPV6=${IPV6}" >> $GITHUB_ENV
30+
echo "X_IPV4=${IPV4}" >> $GITHUB_ENV
31+
32+
- name: Prepare Build Environment
33+
run: |
34+
git submodule update --init
35+
36+
sudo mkdir -p /usr/local/swoole-cli
37+
uid=$(id -u) && gid=$(id -g) && sudo chown -R ${uid}:${gid} /usr/local/swoole-cli
38+
39+
mkdir -p ${{ github.workspace }}/var/build-github-action-container/
40+
41+
- name: Prepare QEMU
42+
run: |
43+
set -x
44+
sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
45+
46+
- name: Prepare swoole-cli-builder-image
47+
run: |
48+
if [ -f ${{ github.workspace }}/var/build-github-action-container/swoole-cli-builder-image.tar ] ; then
49+
docker load -i ${{ github.workspace }}/var/build-github-action-container/swoole-cli-builder-image.tar
50+
else
51+
bash .github/workflows/build-alpine-builder-container.sh --platform "linux/arm64"
52+
fi
53+
54+
- name: prepare pre-built library
55+
uses: addnab/docker-run-action@v3
56+
with:
57+
image: docker.io/jingjingxyk/build-swoole-cli:all-dependencies-alpine-3.18-php8-v1.0.0-aarch64-20240618T091126Z
58+
options: -v ${{ github.workspace }}:/work -w /work -v /usr/local/swoole-cli/:/usr/local/tmp/
59+
run: |
60+
for i in `ls /usr/local/swoole-cli/`
61+
do
62+
if [ ! -d /usr/local/tmp/${i} ] ; then
63+
echo $i
64+
cp -rf /usr/local/swoole-cli/${i}/ /usr/local/tmp/${i}
65+
fi
66+
done
67+
68+
- name: Build
69+
uses: addnab/docker-run-action@v3
70+
with:
71+
image: swoole-cli-builder:latest
72+
options: -v ${{ github.workspace }}:/work -w /work -v /usr/local/swoole-cli:/usr/local/swoole-cli
73+
run: |
74+
set -eux
75+
uname -m
76+
if [ ! -f bin/runtime/php ] ; then
77+
bash setup-php-runtime.sh
78+
fi
79+
80+
export PATH=/work/bin/runtime:$PATH # 容器已经内置 php 和 composer
81+
alias php="php -d curl.cainfo=/work/bin/runtime/cacert.pem -d openssl.cafile=/work/bin/runtime/cacert.pem"
82+
83+
sh sapi/quickstart/linux/alpine-init.sh
84+
composer install --no-interaction --no-autoloader --no-scripts --profile
85+
composer dump-autoload --optimize --profile
86+
87+
php prepare.php
88+
89+
bash make.sh all-library
90+
91+
bash make.sh config
92+
bash make.sh build
93+
bash make.sh archive
94+
95+
- name: Show Build Result
96+
uses: addnab/docker-run-action@v3
97+
with:
98+
image: swoole-cli-builder:latest
99+
options: -v ${{ github.workspace }}:/work -w /work
100+
run: |
101+
./bin/swoole-cli -v
102+
./bin/swoole-cli -m
103+
./bin/swoole-cli --ri gd
104+
./bin/swoole-cli --ri swoole
105+
file ./bin/swoole-cli
106+
readelf -h ./bin/swoole-cli
107+
APP_VERSION=$(./bin/swoole-cli -v | awk '{print $2}')
108+
echo ${APP_VERSION}
109+
echo ${APP_VERSION} > APP_VERSION
110+
111+
./bin/swoole-cli -r "echo PHP_VERSION;"
112+
113+
./bin/swoole-cli ./vendor/bin/phpunit ./sapi/src/UnitTest/MainTest.php --list-tests
114+
./bin/swoole-cli ./vendor/bin/phpunit ./sapi/src/UnitTest/MainTest.php

.github/workflows/linux-aarch64.yml

+44-63
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ env:
88
jobs:
99
linux-aarch64:
1010
if: 1
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-24.04-arm
1212
strategy:
1313
matrix:
1414
php-version:
@@ -31,6 +31,13 @@ jobs:
3131
uname -s
3232
uname -m
3333
uname -r
34+
35+
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
36+
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
37+
cat /proc/cpuinfo | grep "cpu cores" | uniq
38+
cat /proc/cpuinfo| grep "processor"| wc -l
39+
lscpu
40+
3441
export IPV6=$(ip -6 address show | grep inet6 | awk '{print $2}' | cut -d'/' -f1 | sed -n '2p')
3542
export IPV4=$(ip -4 address show | grep inet | grep -v 127.0.0 | awk '{print $2}' | cut -d'/' -f1 | sed -n '1p')
3643
echo $IPV4
@@ -50,14 +57,14 @@ jobs:
5057
5158
- name: Cache PHP Runtime
5259
uses: actions/cache@v4
53-
id: php-runtime-cache
60+
id: php-runtime-cache-aarch64
5461
with:
5562
path: ${{ github.workspace }}/bin/runtime
5663
key: ${{ runner.os }}-aarch64-php-runtime
5764

5865
- name: Cache PHP Vendor
5966
uses: actions/cache@v4
60-
id: php-vendor-cache
67+
id: php-vendor-cache-aarch64
6168
with:
6269
path: ${{ github.workspace }}/vendor
6370
key: ${{ runner.os }}-aarch64-php-vendor
@@ -71,35 +78,18 @@ jobs:
7178

7279
- name: Cache all-library
7380
uses: actions/cache@v4
74-
id: all-library-cache
81+
id: all-library-cache-aarch64
7582
with:
7683
path: /usr/local/swoole-cli
7784
key: ${{ github.head_ref || github.ref_name }}-${{ runner.os }}-aarch64-all-library
7885

7986
- name: Cache swoole-cli-builder-image
8087
uses: actions/cache@v4
81-
id: swoole-cli-builder-image-aarch64-cache
88+
id: swoole-cli-builder-image-cache-aarch64
8289
with:
8390
path: ${{ github.workspace }}/var/build-github-action-container/swoole-cli-builder-image.tar
8491
key: ${{ runner.os }}-aarch64-swoole-cli-builder-image
8592

86-
- name: Prepare Libraries and Extensions
87-
run: |
88-
set -x
89-
mkdir -p pool/lib
90-
mkdir -p pool/ext
91-
mkdir -p bin/runtime
92-
93-
bash sapi/download-box/download-box-get-archive-from-server.sh
94-
95-
ls -A pool/lib/
96-
ls -A /usr/local/swoole-cli/
97-
98-
- name: Prepare QEMU
99-
run: |
100-
set -x
101-
sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
102-
10393
- name: Prepare swoole-cli-builder-image
10494
run: |
10595
if [ -f ${{ github.workspace }}/var/build-github-action-container/swoole-cli-builder-image.tar ] ; then
@@ -108,19 +98,18 @@ jobs:
10898
bash .github/workflows/build-alpine-builder-container.sh --platform "linux/arm64"
10999
fi
110100
111-
- name: prepare pre-built library
112-
uses: addnab/docker-run-action@v3
113-
with:
114-
image: docker.io/jingjingxyk/build-swoole-cli:all-dependencies-alpine-3.18-php8-v1.0.0-aarch64-20240618T091126Z
115-
options: -v ${{ github.workspace }}:/work -w /work -v /usr/local/swoole-cli/:/usr/local/tmp/
116-
run: |
117-
for i in `ls /usr/local/swoole-cli/`
118-
do
119-
if [ ! -d /usr/local/tmp/${i} ] ; then
120-
echo $i
121-
cp -rf /usr/local/swoole-cli/${i}/ /usr/local/tmp/${i}
122-
fi
123-
done
101+
- name: Prepare Runtime and Libraries and Extensions
102+
run: |
103+
set -x
104+
mkdir -p pool/lib
105+
mkdir -p pool/ext
106+
mkdir -p bin/runtime
107+
if [ ! -f bin/runtime/php ] ; then
108+
bash setup-php-runtime.sh
109+
fi
110+
bash sapi/download-box/download-box-get-archive-from-server.sh
111+
ls -A pool/lib/
112+
ls -A /usr/local/swoole-cli/
124113
125114
- name: Build
126115
uses: addnab/docker-run-action@v3
@@ -130,10 +119,6 @@ jobs:
130119
run: |
131120
set -eux
132121
uname -m
133-
if [ ! -f bin/runtime/php ] ; then
134-
bash setup-php-runtime.sh
135-
fi
136-
137122
export PATH=/work/bin/runtime:$PATH # 容器已经内置 php 和 composer
138123
alias php="php -d curl.cainfo=/work/bin/runtime/cacert.pem -d openssl.cafile=/work/bin/runtime/cacert.pem"
139124
@@ -149,31 +134,27 @@ jobs:
149134
150135
bash make-install-deps.sh
151136
152-
bash make.sh all-library
137+
bash ./make.sh all-library
153138
154-
bash make.sh config
155-
bash make.sh build
156-
bash make.sh archive
139+
bash ./make.sh config
140+
bash ./make.sh build
141+
bash ./make.sh archive
157142
158143
- name: Show Build Result
159-
uses: addnab/docker-run-action@v3
160-
with:
161-
image: swoole-cli-builder:latest
162-
options: -v ${{ github.workspace }}:/work -w /work
163-
run: |
164-
./thirdparty/php-src/sapi/cli/php -v
165-
./thirdparty/php-src/sapi/cli/php -m
166-
./thirdparty/php-src/sapi/cli/php --ri gd
167-
./thirdparty/php-src/sapi/cli/php --ri swoole
168-
./thirdparty/php-src/sapi/cli/php --ri pgsql
169-
file ./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/php
170-
readelf -h ./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/php
171-
APP_VERSION=$(./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/php -v | head -n 1 | awk '{print $2}')
172-
echo ${APP_VERSION}
173-
echo ${APP_VERSION} > APP_VERSION
174-
./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/php -r "echo PHP_VERSION;"
175-
./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/php ./vendor/bin/phpunit ./sapi/src/UnitTest/MainTest.php --list-tests
176-
./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/php ./vendor/bin/phpunit ./sapi/src/UnitTest/MainTest.php
144+
run: |
145+
./thirdparty/php-src/sapi/cli/php -v
146+
./thirdparty/php-src/sapi/cli/php -m
147+
./thirdparty/php-src/sapi/cli/php --ri gd
148+
./thirdparty/php-src/sapi/cli/php --ri swoole
149+
./thirdparty/php-src/sapi/cli/php --ri pgsql
150+
file ./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/php
151+
readelf -h ./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/php
152+
APP_VERSION=$(./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/php -v | head -n 1 | awk '{print $2}')
153+
echo ${APP_VERSION}
154+
echo ${APP_VERSION} > APP_VERSION
155+
./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/php -r "echo PHP_VERSION;"
156+
./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/php ./vendor/bin/phpunit ./sapi/src/UnitTest/MainTest.php --list-tests
157+
./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/php ./vendor/bin/phpunit ./sapi/src/UnitTest/MainTest.php
177158
178159
- name: get app version
179160
run: |
@@ -186,14 +167,14 @@ jobs:
186167
with:
187168
name: php-cli-v${{ env.APP_VERSION }}-linux-arm64-debug
188169
retention-days: 90
189-
path: ./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/php
170+
path: ./bin/php-${{ env.APP_VERSION }}/bin/php
190171

191172
- name: production artifacts
192173
uses: actions/upload-artifact@v4
193174
with:
194175
name: php-cli-v${{ env.APP_VERSION }}-linux-arm64
195176
retention-days: 90
196-
path: ./bin/php-${{ env.BUILD_PHP_VERSION }}/bin/dist/php
177+
path: ./bin/php-${{ env.APP_VERSION }}/bin/dist/php
197178

198179
- name: gh release
199180
uses: softprops/action-gh-release@v2

0 commit comments

Comments
 (0)