-
-
Notifications
You must be signed in to change notification settings - Fork 315
Add zig toolchain support & shared build improvement #806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
new zig-cc and zig-c++ scripts: #!/usr/bin/env bash
if [[ "$*" == *"-version"* || "$*" == *" -v"* || "$*" == "-v "* || "$*" == "-v" ]]; then
exec zig cc "$@"
else
exec zig cc -fno-sanitize=undefined -target native-native-gnu.2.17 "$@"
fi
Tracked here: ziglang/zig#24252 |
[07:39:02] [I] Entering dir: /home/m/static-php-cli/source/embed-test
[07:39:02] [I] [EXEC] LD_LIBRARY_PATH=/home/m/static-php-cli/buildroot/lib:$LD_LIBRARY_PATH ./embed
[07:39:02] [I] running frankenphp sanity check
[07:39:02] [I] [EXEC] /home/m/static-php-cli/buildroot/bin/frankenphp version
[07:39:02] [I]
[07:39:02] [I] Build complete, used 431.219 s !
[07:39:02] [I]
[07:39:02] [I] Static php binary path: /home/m/static-php-cli/buildroot/bin/php
[07:39:02] [I] Static php-fpm binary path: /home/m/static-php-cli/buildroot/bin/php-fpm
[07:39:02] [I] Shared extension [amqp] path: /home/m/static-php-cli/buildroot/modules/amqp.so
[07:39:02] [I] Shared extension [brotli] path: /home/m/static-php-cli/buildroot/modules/brotli.so
[07:39:02] [I] Shared extension [bz2] path: /home/m/static-php-cli/buildroot/modules/bz2.so
[07:39:02] [I] Shared extension [dio] path: /home/m/static-php-cli/buildroot/modules/dio.so
[07:39:02] [I] Shared extension [ds] path: /home/m/static-php-cli/buildroot/modules/ds.so
[07:39:02] [I] Shared extension [ev] path: /home/m/static-php-cli/buildroot/modules/ev.so
[07:39:02] [I] Shared extension [event] path: /home/m/static-php-cli/buildroot/modules/event.so
[07:39:02] [I] Shared extension [ffi] path: /home/m/static-php-cli/buildroot/modules/ffi.so
[07:39:02] [I] Shared extension [ftp] path: /home/m/static-php-cli/buildroot/modules/ftp.so
[07:39:02] [I] Shared extension [gd] path: /home/m/static-php-cli/buildroot/modules/gd.so
[07:39:02] [I] Shared extension [gettext] path: /home/m/static-php-cli/buildroot/modules/gettext.so
[07:39:02] [I] Shared extension [gmp] path: /home/m/static-php-cli/buildroot/modules/gmp.so
[07:39:02] [I] Shared extension [gmssl] path: /home/m/static-php-cli/buildroot/modules/gmssl.so
[07:39:02] [I] Shared extension [igbinary] path: /home/m/static-php-cli/buildroot/modules/igbinary.so
[07:39:02] [I] Shared extension [imagick] path: /home/m/static-php-cli/buildroot/modules/imagick.so
[07:39:02] [I] Shared extension [inotify] path: /home/m/static-php-cli/buildroot/modules/inotify.so
[07:39:02] [I] Shared extension [intl] path: /home/m/static-php-cli/buildroot/modules/intl.so
[07:39:02] [I] Shared extension [ldap] path: /home/m/static-php-cli/buildroot/modules/ldap.so
[07:39:02] [I] Shared extension [lz4] path: /home/m/static-php-cli/buildroot/modules/lz4.so
[07:39:02] [I] Shared extension [memcache] path: /home/m/static-php-cli/buildroot/modules/memcache.so
[07:39:02] [I] Shared extension [memcached] path: /home/m/static-php-cli/buildroot/modules/memcached.so
[07:39:02] [I] Shared extension [mongodb] path: /home/m/static-php-cli/buildroot/modules/mongodb.so
[07:39:02] [I] Shared extension [msgpack] path: /home/m/static-php-cli/buildroot/modules/msgpack.so
[07:39:02] [I] Shared extension [mysqli] path: /home/m/static-php-cli/buildroot/modules/mysqli.so
[07:39:02] [I] Shared extension [mysqlnd] path: /home/m/static-php-cli/buildroot/modules/mysqlnd.so
[07:39:02] [I] Shared extension [odbc] path: /home/m/static-php-cli/buildroot/modules/odbc.so
[07:39:02] [I] Shared extension [opentelemetry] path: /home/m/static-php-cli/buildroot/modules/opentelemetry.so
[07:39:02] [I] Shared extension [parallel] path: /home/m/static-php-cli/buildroot/modules/parallel.so
[07:39:02] [I] Shared extension [pdo] path: /home/m/static-php-cli/buildroot/modules/pdo.so
[07:39:02] [I] Shared extension [pdo_mysql] path: /home/m/static-php-cli/buildroot/modules/pdo_mysql.so
[07:39:02] [I] Shared extension [pdo_odbc] path: /home/m/static-php-cli/buildroot/modules/pdo_odbc.so
[07:39:02] [I] Shared extension [pdo_pgsql] path: /home/m/static-php-cli/buildroot/modules/pdo_pgsql.so
[07:39:02] [I] Shared extension [pdo_sqlite] path: /home/m/static-php-cli/buildroot/modules/pdo_sqlite.so
[07:39:02] [I] Shared extension [pdo_sqlsrv] path: /home/m/static-php-cli/buildroot/modules/pdo_sqlsrv.so
[07:39:02] [I] Shared extension [pgsql] path: /home/m/static-php-cli/buildroot/modules/pgsql.so
[07:39:02] [I] Shared extension [protobuf] path: /home/m/static-php-cli/buildroot/modules/protobuf.so
[07:39:02] [I] Shared extension [rar] path: /home/m/static-php-cli/buildroot/modules/rar.so
[07:39:02] [I] Shared extension [redis] path: /home/m/static-php-cli/buildroot/modules/redis.so
[07:39:02] [I] Shared extension [rdkafka] path: /home/m/static-php-cli/buildroot/modules/rdkafka.so
[07:39:02] [I] Shared extension [shmop] path: /home/m/static-php-cli/buildroot/modules/shmop.so
[07:39:02] [I] Shared extension [spx] path: /home/m/static-php-cli/buildroot/modules/spx.so
[07:39:02] [I] Shared extension [sqlite3] path: /home/m/static-php-cli/buildroot/modules/sqlite3.so
[07:39:02] [I] Shared extension [sqlsrv] path: /home/m/static-php-cli/buildroot/modules/sqlsrv.so
[07:39:02] [I] Shared extension [ssh2] path: /home/m/static-php-cli/buildroot/modules/ssh2.so
[07:39:02] [I] Shared extension [swoole] path: /home/m/static-php-cli/buildroot/modules/swoole.so
[07:39:02] [I] Shared extension [sysvmsg] path: /home/m/static-php-cli/buildroot/modules/sysvmsg.so
[07:39:02] [I] Shared extension [sysvsem] path: /home/m/static-php-cli/buildroot/modules/sysvsem.so
[07:39:02] [I] Shared extension [sysvshm] path: /home/m/static-php-cli/buildroot/modules/sysvshm.so
[07:39:02] [I] Shared extension [tidy] path: /home/m/static-php-cli/buildroot/modules/tidy.so
[07:39:02] [I] Shared extension [uuid] path: /home/m/static-php-cli/buildroot/modules/uuid.so
[07:39:02] [I] Shared extension [uv] path: /home/m/static-php-cli/buildroot/modules/uv.so
[07:39:02] [I] Shared extension [xdebug] path: /home/m/static-php-cli/buildroot/modules/xdebug.so
[07:39:02] [I] Shared extension [xhprof] path: /home/m/static-php-cli/buildroot/modules/xhprof.so
[07:39:02] [I] Shared extension [xlswriter] path: /home/m/static-php-cli/buildroot/modules/xlswriter.so
[07:39:02] [I] Shared extension [xsl] path: /home/m/static-php-cli/buildroot/modules/xsl.so
[07:39:02] [I] Shared extension [xz] path: /home/m/static-php-cli/buildroot/modules/xz.so
[07:39:02] [I] Shared extension [yac] path: /home/m/static-php-cli/buildroot/modules/yac.so
[07:39:02] [I] Shared extension [yaml] path: /home/m/static-php-cli/buildroot/modules/yaml.so
[07:39:02] [I] Shared extension [zstd] path: /home/m/static-php-cli/buildroot/modules/zstd.so
[07:39:02] [I] License path: /home/m/static-php-cli/buildroot/license/ |
Look at the abomination of zig-cc script I've ended up now to work around all the open ziglang issues 🪂 #!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILDROOT_ABS="$(realpath "$SCRIPT_DIR/../../buildroot/include" 2>/dev/null || echo "")"
PARSED_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
-isystem)
shift
ARG="$1"
[[ -n "$ARG" ]] && shift || break
ARG_ABS="$(realpath "$ARG" 2>/dev/null || echo "")"
if [[ -n "$ARG_ABS" && "$ARG_ABS" == "$BUILDROOT_ABS" ]]; then
PARSED_ARGS+=("-I$ARG")
else
PARSED_ARGS+=("-isystem" "$ARG")
fi
;;
-isystem*)
ARG="${1#-isystem}"
shift
ARG_ABS="$(realpath "$ARG" 2>/dev/null || echo "")"
if [[ -n "$ARG_ABS" && "$ARG_ABS" == "$BUILDROOT_ABS" ]]; then
PARSED_ARGS+=("-I$ARG")
else
PARSED_ARGS+=("-isystem$ARG")
fi
;;
*)
PARSED_ARGS+=("$1")
shift
;;
esac
done
SPC_TARGET_WAS_SET=1
if [ -z "${SPC_TARGET+x}" ]; then
SPC_TARGET_WAS_SET=0
fi
UNAME_M="$(uname -m)"
UNAME_S="$(uname -s)"
case "$UNAME_M" in
x86_64) ARCH="x86_64" ;;
aarch64|arm64) ARCH="aarch64" ;;
*) echo "Unsupported architecture: $UNAME_M" >&2; exit 1 ;;
esac
case "$UNAME_S" in
Linux) OS="linux" ;;
Darwin) OS="macos" ;;
*) echo "Unsupported OS: $UNAME_S" >&2; exit 1 ;;
esac
SPC_TARGET="${SPC_TARGET:-$ARCH-$OS}"
SPC_LIBC="${SPC_LIBC}"
SPC_LIBC_VERSION="${SPC_LIBC_VERSION}"
if [ "$SPC_LIBC" = "glibc" ]; then
SPC_LIBC="gnu"
fi
if [ "$SPC_TARGET_WAS_SET" -eq 0 ] && [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then
exec zig cc "${PARSED_ARGS[@]}"
elif [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then
exec zig cc -target ${SPC_TARGET} "${PARSED_ARGS[@]}"
elif [ -z "$SPC_LIBC_VERSION" ]; then
exec zig cc -target ${SPC_TARGET}-${SPC_LIBC} -L/usr/lib64 -lstdc++ "${PARSED_ARGS[@]}"
else
error_output=$(zig cc -target ${SPC_TARGET}-${SPC_LIBC}.${SPC_LIBC_VERSION} "${PARSED_ARGS[@]}" 2>&1 >/dev/null)
if echo "$error_output" | grep -q "zig: error: version '.*' in target triple '${SPC_TARGET}-${SPC_LIBC}\..*' is invalid"; then
exec zig cc -target ${SPC_TARGET}-${SPC_LIBC} -L/usr/lib64 -lstdc++ "${PARSED_ARGS[@]}"
else
exec zig cc -target ${SPC_TARGET}-${SPC_LIBC}.${SPC_LIBC_VERSION} -L/usr/lib64 -lstdc++ "${PARSED_ARGS[@]}"
fi
fi |
This seems a bit long, how about putting the shell part separately into |
cool, musl actually works too, although it needs more extensive testing later |
no debug do I can see where it fails
I'm very confused how the feature tests for PQchangePassword and uuid_generate_md5 are succeeding. The former was introduced in libpq 17, which we don't use yet, so I don't understand how the test link succeeds. Is it falling back to system libraries that exist only on Ubuntu but not on RHEL? |
well, it's working fine on my local ubuntu 24.04 this will be fun to debug... |
my aarch64 rhel 9 machine also worked right away, I don't understand what's holding up the actions runners |
Looks like ignoring |
Try cleaning cache?
|
I've set up a completely new ubuntu 24.04 VM in wsl. The actions runners pass feature checks for symbols that are not available in the libraries they build. I'm really unsure how that's possible. |
this is cursed, I set up a aarch64 ubuntu vm and it built fine (failed on the gettext check because en-US locale wasn't installed, but on a second run it ran through)... |
On my own aarch64 vm: configure:4421: checking for uuid_generate_md5 in -luuid
configure:4446: zig-cc -o conftest -fpic -O3 -fstack-protector-strong -fstack-clash-protection -Wno-date-time -I/home/opc/static-php-cli/buildroot/include -I/home/opc/static-php-cli/buildroot/include/php -I/home/opc/static-php-cli/buildroot/include/php/main -I/home/opc/static-php-cli/buildroot/include/php/TSRM -I/home/opc/static-php-cli/buildroot/include/php/Zend -I/home/opc/static-php-cli/buildroot/include/php/ext -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -L/home/opc/static-php-cli/buildroot/lib conftest.c -luuid -luuid -luuid -Wl,--start-group -luuid -Wl,--end-group -lphp -lc -ldl -lpthread -lm -lresolv -lutil -lrt -lstdc++ -lunwind >&5
ld.lld: error: undefined symbol: uuid_generate_md5
>>> referenced by conftest.c:24
>>> /home/opc/.cache/zig/o/b8605c038b12b959e0a2909bee85229f/conftest.o:(main)
ld.lld: error: undefined symbol: uuid_generate_md5
>>> referenced by conftest.c:24
>>> /home/opc/.cache/zig/o/b8605c038b12b959e0a2909bee85229f/conftest.o:(main)
configure:4446: $? = 1
configure: failed program was:
| /* confdefs.h */
--
| Use char because int might match the return type of a GCC
| builtin and then its argument prototype would still apply. */
| #ifdef __cplusplus
| extern "C"
| #endif
| char uuid_generate_md5 ();
| int
| main ()
| {
| return uuid_generate_md5 ();
| ;
| return 0;
| } On the github runner: 2025-06-27T03:03:07.6121853Z Configuring extension
2025-06-27T03:03:07.6139802Z checking whether uuid is available... yes, shared
2025-06-27T03:03:07.6149894Z checking for the location of libuuid... found in /usr
2025-06-27T03:03:07.6608166Z checking for uuid_type in -luuid... yes
2025-06-27T03:03:07.7514646Z checking for uuid_variant in -luuid... yes
2025-06-27T03:03:07.8473940Z checking for uuid_generate_md5 in -luuid... yes
2025-06-27T03:03:07.9412703Z checking for uuid_generate_sha1 in -luuid... yes
2025-06-27T03:03:08.0334416Z checking for uuid_time in -luuid... yes
2025-06-27T03:03:08.1611671Z checking for uuid_time64 in -luuid... no
2025-06-27T03:03:08.2410271Z checking for __uuid_time64 in -luuid... no
2025-06-27T03:03:09.9771021Z zig-cc -I. -I/home/runner/work/static-php-cli/static-php-cli/source/php-src/ext/uuid -I/home/runner/work/static-php-cli/static-php-cli/buildroot/include/php -I/home/runner/work/static-php-cli/static-php-cli/buildroot/include/php/main -I/home/runner/work/static-php-cli/static-php-cli/buildroot/include/php/TSRM -I/home/runner/work/static-php-cli/static-php-cli/buildroot/include/php/Zend -I/home/runner/work/static-php-cli/static-php-cli/buildroot/include/php/ext -I/home/runner/work/static-php-cli/static-php-cli/buildroot/include/php/ext/date/lib -DHAVE_CONFIG_H -fPIC -Os -Wno-error=date-time -I/home/runner/work/static-php-cli/static-php-cli/buildroot/include -I/home/runner/work/static-php-cli/static-php-cli/buildroot/include/php -I/home/runner/work/static-php-cli/static-php-cli/buildroot/include/php/main -I/home/runner/work/static-php-cli/static-php-cli/buildroot/include/php/TSRM -I/home/runner/work/static-php-cli/static-php-cli/buildroot/include/php/Zend -I/home/runner/work/static-php-cli/static-php-cli/buildroot/include/php/ext -D_GNU_SOURCE -DZEND_COMPILE_DL_EXT=1 -c /home/runner/work/static-php-cli/static-php-cli/source/php-src/ext/uuid/uuid.c -MMD -MF uuid.dep -MT uuid.lo -fPIC -DPIC -o .libs/uuid.o
2025-06-27T03:03:10.3074597Z /home/runner/work/static-php-cli/static-php-cli/source/php-src/ext/uuid/uuid.c:245:2: error: call to undeclared function 'uuid_generate_md5'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2025-06-27T03:03:10.3075541Z 245 | uuid_generate_md5(out, ns, name, name_len);
2025-06-27T03:03:10.3075790Z | ^
2025-06-27T03:03:10.3076551Z /home/runner/work/static-php-cli/static-php-cli/source/php-src/ext/uuid/uuid.c:272:2: error: call to undeclared function 'uuid_generate_sha1'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2025-06-27T03:03:10.3077506Z 272 | uuid_generate_sha1(out, ns, name, name_len);
2025-06-27T03:03:10.3077753Z | ^
2025-06-27T03:03:10.3077914Z 2 errors generated.
2025-06-27T03:03:10.6087729Z /home/runner/work/static-php-cli/static-php-cli/source/php-src/ext/uuid/uuid.c:245:2: error: call to undeclared function 'uuid_generate_md5'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2025-06-27T03:03:10.6088679Z 245 | uuid_generate_md5(out, ns, name, name_len);
2025-06-27T03:03:10.6088922Z | ^
2025-06-27T03:03:10.6093480Z /home/runner/work/static-php-cli/static-php-cli/source/php-src/ext/uuid/uuid.c:272:2: error: call to undeclared function 'uuid_generate_sha1'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2025-06-27T03:03:10.6094373Z 272 | uuid_generate_sha1(out, ns, name, name_len);
2025-06-27T03:03:10.6094617Z | ^
2025-06-27T03:03:10.6154212Z 2 errors generated.
2025-06-27T03:03:10.6189080Z make: *** [Makefile:209: uuid.lo] Error 1
2025-06-27T03:03:10.6218431Z |
Okay, that also explains why clang/zig can build and link with LTO, but gcc fails to. remi also builds without lto by setting
|
I'm making an exact copy of rpmbuilds CFLAGS and LDFLAGS minus the LTO part and still get 137k points. I don't have the faintest idea why remi's build is 156k points and the local remi rpm rebuild is 160k points. |
Cool. I will review the remaining part after everything available. I haven't dig it deeper yet but I'm open to research it if you need. |
Yeah, I fixed macOS, this is good to merge now. LDFLAGS bit was needed to let you test with ldflags, which may impact optimization testing. |
I'll leave fixing the tests up to you. Why |
Wonderful, more segmentation faults of FrankenPHP. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll test zig on my linux machine later and review the remaining zig-cc and package part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds compatibility for the zig compiler to SPC (Static PHP Cli), introducing a new ZigToolchain alongside the existing GCC, Clang, and MSVC toolchains. The changes include comprehensive updates to handle zig-specific build requirements, environment setup, and cross-compilation capabilities.
- Adds a complete ZigToolchain implementation with custom compiler script handling
- Updates target and library configuration system to support zig's target format
- Refactors extension and library build processes to be more compiler-agnostic
Reviewed Changes
Copilot reviewed 82 out of 87 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
src/SPC/toolchain/ZigToolchain.php | New toolchain implementation for zig compiler with environment setup and runtime object handling |
src/SPC/store/pkg/Zig.php | Package manager implementation for downloading and configuring zig compiler |
src/SPC/store/scripts/zig-cc.sh | Wrapper script to handle zig-specific compiler arguments and target specifications |
src/SPC/util/SPCTarget.php | Major refactor to support zig target format and runtime library detection |
src/SPC/toolchain/ToolchainManager.php | Updates to integrate ZigToolchain as the new default for Linux |
Multiple library files | Updates to handle zig-specific build flags and environment variables |
Test files | Updates to reflect changes in target naming and test configurations |
Comments suppressed due to low confidence (1)
It seems that Copilot AI has no thinking and PR context. The suggestion level this time is 0%. |
Hahahaha, not surprised. |
What does this PR do?
updates SPC to work with a zig cc compiler script.
/usr/bin/zig-cc:
Checklist before merging
*.php
or*.json
, run them locally to ensure your changes are valid:Better handling of disabling warnings individually
Figure out why -Wno-error is not enough
php compilation succeeds
Zig cc still has the following issues. Ticked, if worked around: