Skip to content

Commit 0ae4bcb

Browse files
authored
Merge pull request #806 from crazywhalecc/zig
Add zig toolchain support & shared build improvement
2 parents fafe7d5 + c58bc03 commit 0ae4bcb

File tree

88 files changed

+1135
-686
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1135
-686
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
> If a modification is not involved, please skip it directly.
99
1010
- If you modified `*.php` or `*.json`, run them locally to ensure your changes are valid:
11-
- [ ] `PHP_CS_FIXER_IGNORE_ENV=1 composer cs-fix`
11+
- [ ] `composer cs-fix`
1212
- [ ] `composer analyse`
1313
- [ ] `composer test`
1414
- [ ] `bin/spc dev:sort-config`

.github/workflows/build-unix.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ jobs:
198198
run: ${{ needs.define-build.outputs.download }}
199199
- name: "Build PHP"
200200
run: ${{ needs.define-build.outputs.build }}
201-
#- name: Setup tmate session
202-
# if: ${{ failure() }}
203-
# uses: mxschmitt/action-tmate@v3
201+
# - name: Setup tmate session
202+
# if: ${{ failure() }}
203+
# uses: mxschmitt/action-tmate@v3
204204

205205
# Upload cli executable
206206
- if: ${{ inputs.build-cli == true }}

.github/workflows/tests.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
tools: pecl, composer, php-cs-fixer
4040

4141
- name: Run PHP-CS-Fixer fix
42-
run: PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --dry-run --diff --ansi
42+
run: php-cs-fixer fix --dry-run --diff --ansi
4343

4444
phpstan:
4545
runs-on: ubuntu-latest
@@ -55,6 +55,8 @@ jobs:
5555
extensions: curl, openssl, mbstring
5656
ini-values: memory_limit=-1
5757
tools: composer
58+
env:
59+
phpts: zts
5860

5961
- name: "Cache Composer packages"
6062
id: composer-cache
@@ -135,7 +137,7 @@ jobs:
135137
build:
136138
name: "Build PHP Test (PHP ${{ matrix.php }} ${{ matrix.os }})"
137139
runs-on: ${{ matrix.os }}
138-
needs: define-matrix
140+
needs: [define-matrix, php-cs-fixer, phpstan, phpunit]
139141
timeout-minutes: 120
140142
strategy:
141143
matrix:

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ packlib_files.txt
3434
/bin/*
3535
!/bin/spc*
3636
!/bin/setup-runtime*
37-
!/bin/spc-alpine-docker
38-
!/bin/php-cs-fixer-wrapper
39-
!/bin/build-static-frankenphp
4037

4138
# exclude windows build tools
4239
/php-sdk-binary-tools/

.php-cs-fixer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@
7070
])
7171
->setFinder(
7272
PhpCsFixer\Finder::create()->in([__DIR__ . '/src', __DIR__ . '/tests/SPC'])
73-
);
73+
)
74+
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect());

bin/build-static-frankenphp

Lines changed: 0 additions & 158 deletions
This file was deleted.

bin/php-cs-fixer-wrapper

Lines changed: 0 additions & 4 deletions
This file was deleted.

bin/spc-gnu-docker

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ RUN if [ "$SPC_USE_ARCH" = "aarch64" ]; then \
8383
sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo ; \
8484
fi
8585
RUN sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/*.repo && \
86-
sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo
86+
sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo && \
87+
sed -i 's|http://|https://|g' /etc/yum.repos.d/*.repo
8788
8889
RUN yum update -y && \
8990
yum install -y devtoolset-10-gcc-* devtoolset-10-libatomic-devel
@@ -155,8 +156,6 @@ fi
155156
# Apply env in temp env file
156157
echo 'SPC_DEFAULT_C_FLAGS=-fPIC' > /tmp/spc-gnu-docker.env
157158
echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env
158-
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env
159-
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' >> /tmp/spc-gnu-docker.env
160159

161160
# Environment variable passthrough
162161
ENV_LIST=""

config/env.ini

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,26 @@ PHP_SDK_PATH="${WORKING_DIR}\php-sdk-binary-tools"
6262
UPX_EXEC="${PKG_ROOT_PATH}\bin\upx.exe"
6363
; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches
6464
SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime140,win32,zend_stream,cli_static
65-
; Windows static linking system libs
66-
SPC_EXTRA_LIBS=""
6765

6866
[linux]
69-
; Linux can use different build toolchain, but the toolchain can not be changed in this file:
70-
; - musl (default): used for general linux distros, can build `musl-static` target only.
71-
; - zig (WIP): used for general linux distros, can build `musl` and `glibc` targets.
72-
; - musl-native: used for alpine linux, can build `musl-static` and `musl`(WIP) target.
73-
; - gnu-native (assume): used for general linux distros, can build `glibc` target only and have portability issues.
67+
; Linux can use different build toolchains.
68+
; - musl (default, when SPC_LIBC=musl): used for general linux distros, can build `musl` (statically linked) only.
69+
; - zig (will become default): usable on all Linux distros, can build `-musl`, `arch-linux-musl -dynamic` and `arch-linux-gnu` targets. Can specify version such as `x86_64-linux-gnu.2.17`.
70+
; - musl-native: used for alpine linux, can build `musl` and `musl -dynamic` target.
71+
; - gnu-native: used for general linux distros, can build gnu target for the installed glibc version only.
7472

75-
; build target:
76-
; - musl-static (default): pure static linking, using musl-libc, can run on any linux distro.
77-
; - musl: static linking with dynamic linking to musl-libc, can run on musl-based linux distro.
78-
; - glibc: static linking with dynamic linking to glibc, can run on glibc-based linux distro.
79-
80-
; include PATH for musl libc.
73+
; LEGACY option to specify the target
8174
SPC_LIBC=musl
75+
76+
; Recommended: specify your target here. Zig toolchain will be used.
77+
; examples:
78+
; `native-native-gnu` - links against glibc, current OS version
79+
; `native-native-gnu.2.17` - links against glibc, version 2.17
80+
; `native-native` - links against system libc dynamically
81+
; `native-native-musl` - links against musl libc statically
82+
; `native-native-musl -dynamic` - links against musl libc dynamically
83+
; SPC_TARGET=
84+
8285
; compiler environments
8386
CC=${SPC_LINUX_DEFAULT_CC}
8487
CXX=${SPC_LINUX_DEFAULT_CXX}
@@ -87,8 +90,7 @@ LD=${SPC_LINUX_DEFAULT_LD}
8790
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
8891
SPC_DEFAULT_C_FLAGS="-fPIC -Os"
8992
SPC_DEFAULT_CXX_FLAGS="-fPIC -Os"
90-
; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated)
91-
SPC_EXTRA_LIBS=""
93+
SPC_DEFAULT_LD_FLAGS=""
9294
; upx executable path
9395
UPX_EXEC=${PKG_ROOT_PATH}/bin/upx
9496
; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches
@@ -107,16 +109,10 @@ SPC_CMD_PREFIX_PHP_MAKE="make -j${SPC_CONCURRENCY}"
107109
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
108110
; CFLAGS for configuring php
109111
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -fPIE"
110-
; CPPFLAGS for configuring php
111-
SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}"
112-
; LDFLAGS for configuring php
113-
SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}"
114-
; LIBS for configuring php
115-
SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lpthread -lm"
116112
; EXTRA_CFLAGS for `make` php
117-
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="${SPC_DEFAULT_C_FLAGS} -g -fstack-protector-strong -fno-ident -fPIE"
118-
; EXTRA_LIBS for `make` php
119-
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm"
113+
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}"
114+
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so
115+
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
120116

121117
[macos]
122118
; build target: macho or macho (possibly we could support macho-universal in the future)
@@ -128,8 +124,7 @@ CXX=clang++
128124
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
129125
SPC_DEFAULT_C_FLAGS="--target=${MAC_ARCH}-apple-darwin -Os"
130126
SPC_DEFAULT_CXX_FLAGS="--target=${MAC_ARCH}-apple-darwin -Os"
131-
; extra libs for building php executable, used in `make` command for building php (this value may changed by extension build process, space separated)
132-
SPC_EXTRA_LIBS=""
127+
SPC_DEFAULT_LD_FLAGS=""
133128
; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches
134129
SPC_MICRO_PATCHES=cli_checks,macos_iconv
135130

@@ -146,14 +141,8 @@ SPC_CMD_PREFIX_PHP_MAKE="make -j${SPC_CONCURRENCY}"
146141
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
147142
; CFLAGS for configuring php
148143
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -Werror=unknown-warning-option"
149-
; CPPFLAGS for configuring php
150-
SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}"
151-
; LDFLAGS for configuring php
152-
SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}"
153144
; EXTRA_CFLAGS for `make` php
154-
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="${SPC_DEFAULT_C_FLAGS} -g -fstack-protector-strong -fpic -fpie"
155-
; EXTRA_LIBS for `make` php
156-
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-lresolv"
145+
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie ${SPC_DEFAULT_C_FLAGS}"
157146

158147
[freebsd]
159148
; compiler environments

config/ext.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@
495495
"type": "builtin",
496496
"arg-type": "custom",
497497
"arg-type-windows": "with",
498+
"build-with-php": true,
498499
"lib-depends": [
499500
"openssl",
500501
"zlib"

0 commit comments

Comments
 (0)