Skip to content

fix: unblock hosted builds (Swoole snprintf, static libpq) - #1260

Merged
crazywhalecc merged 1 commit into
v3from
fix/hosted-build-swoole-pgsql
Oct 22, 2026
Merged

crazywhalecc merged 1 commit into
v3from
fix/hosted-build-swoole-pgsql

Conversation

@crazywhalecc

@crazywhalecc crazywhalecc commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Why

The [v3] Build Self-Hosted PHP Binary (Unix) workflow is still red after the stale downloads caches were cleared. Three independent build failures remain:

  1. Swoole (bulk / gnu-bulk, Linux + macOS, PHP 8.2–8.5)
    ext-src/swoole_admin_server.cc includes PHP headers first and then Swoole's bundled nlohmann/json.hpp. php.h includes main/snprintf.h, which unconditionally does #define snprintf ap_php_snprintf (same for vsnprintf). nlohmann uses (std::snprintf), so the object-like macro rewrites it to std::ap_php_snprintf and the C++ build fails.
  2. Swoole + Zig libc++ on Linux
    swoole.h includes libc++ <list> → <locale> from inside the PHP header chain. Zig's libc++ __locale_dir/support/linux.h uses std::vsnprintf, which the PHP macro has already rewritten to std::ap_php_vsnprintf. macOS's libc++ does not hit this path.
  3. macOS PHP 8.2/8.3 common + bulk
    PostgreSQL 18 keeps libpgcommon.a / libpgport.a as separate static archives, and libpq itself references OpenSSL / LDAP / zlib / zstd / ICU depending on how it was built. PHP < 8.4 checks libpq with AC_CHECK_LIB(pq, PQlibVersion, ...), which links only -lpq plus the minimal configure LIBS, so the check fails with undefined BIO_* / ASN1_* / ldap_* / explicit_bzero / pg_b64_* symbols. PHP 8.4+ uses PHP_SETUP_PGSQL + PGSQL_LIBS (from pg_config --libs) and is unaffected.

A fourth issue surfaced while validating on macOS: Swoole 6.2.3 src/core/misc.cc calls sw_usleep(), which is defined in include/swoole_posix.h but that translation unit does not include it. Linux pulls it in indirectly; macOS fails with use of undeclared identifier 'sw_usleep'. Swoole 6.2.2 and master use usleep() there.

Changes

  • src/Package/Extension/swoole.php:
    • Prepend -include locale to the PHP C++ flags for Swoole builds, so libc++ <locale> is parsed before PHP's vsnprintf macro is defined.
    • Include <cstdio> before php_swoole_server.h in swoole_admin_server.cc. This declares std::snprintf before php.h defines the macro.
    • #undef snprintf / #undef vsnprintf immediately before the nlohmann/json.hpp include.
    • Replace sw_usleep(...) with usleep(...) in src/core/misc.cc for Swoole 6.2.3.
    • All patches are idempotent and guarded for versions where the files/layout differ.
  • src/Package/Extension/pgsql.php + src/Package/Extension/pdo_pgsql.php: for PHP < 8.4, compute the same static dependency list used by the final build (SPCConfigUtil::configForResolvedBuild(['postgresql'], $installer)['libs']) and pass it as AC_CHECK_LIB's OTHER-LIBRARIES argument for the PQlibVersion check. The generated configure then links -lpq plus the full static dependency list, matching the final build.

Local validation (macOS arm64, PHP 8.3)

Clean build (buildroot + source removed) with:

bin/spc build "pdo_pgsql,pgsql,swoole" --build-cli --dl-with-php=8.3 --debug

Result: BUILD SUCCESSFUL, including the pgsql, pdo_pgsql and swoole smoke tests.

  • checking for PQlibVersion in -lpq... yes (before this PR: no → configure error).
  • swoole_admin_server.cc compiles; no std::ap_php_snprintf / missing std::snprintf errors.
  • src/core/misc.cc compiles after the sw_usleep → usleep patch.
  • composer analyse — no errors.
  • composer test — 468 tests pass (the local untracked tests/StaticPHP/Package/ZipTest.php was excluded; it is unrelated to this branch and currently fails against v3).

CI iterations

  • First run: pgsql 8.3 macOS failed with BIO_* / ldap_* undefined symbols. Root cause: CI uses --with-suggested-libs --with-suggested-exts, so libpq is built with OpenSSL/LDAP and -lpgcommon -lpgport alone was not enough. Fixed by passing the full resolved static dependency list.
  • Second run: all pgsql jobs passed, including PHP 8.3 macOS; Swoole passed on macOS. Swoole on Linux failed at __locale_dir/support/linux.h: no member named 'ap_php_vsnprintf'. Fixed by pre-including libc++ <locale>.
  • Third run is the current head (158babd7).

Scope

This does not change the compiler-rt downloader. The missing compiler-rt-21.1.0.src.tar.xz on the mirror is an operational gap (the publishing workflow only backfills the latest zig) and is no longer hit after the stale caches were cleared; the next run resolves zig 0.17 / compiler-rt 22.1.8.

@crazywhalecc crazywhalecc added need-test This PR has not been tested yet, cannot merge now test/php-83 labels Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

StaticPHP Test Bot

Detected: Extensions: pdo_pgsql, pgsql, swoole | Libraries: none | Targets: none
Active labels: test/php-83
Available labels: need-test (gate), test/linux test/windows test/macos (platform), test/tier2 (extra arch), test/php-83 test/php-84 (PHP version), sapi/frankenphp (extra FrankenPHP SAPI build)
Config: Linux x86_64 + Windows x86_64 + macOS arm64 | PHP 8.3, PHP 8.5 NTS

@henderkes henderkes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there an issue already at swoole-src?

@crazywhalecc

Copy link
Copy Markdown
Owner Author

Not yet. https://github.com/jcleng/swoole-src/tree/fix/php-snprintf-macro is a forked version for this. This is blocking our build; we should fix it first.

@crazywhalecc
crazywhalecc force-pushed the fix/hosted-build-swoole-pgsql branch 2 times, most recently from 369af16 to e76609a Compare October 21, 2026 18:35
- Swoole: pre-include libc++ <locale> for the Swoole C++ build (Zig libc++ on Linux uses std::vsnprintf before the macro is undefined), include <cstdio> before php.h, undef PHP's snprintf/vsnprintf macros before nlohmann/json, and restore usleep() in 6.2.3 misc.cc where sw_usleep is not declared on macOS.
- pgsql/pdo_pgsql: for PHP < 8.4, pass the full resolved static libpq dependency list as AC_CHECK_LIB's OTHER-LIBRARIES for the PQlibVersion check (libpgcommon/libpgport alone was not enough when libpq is built with OpenSSL/LDAP/zstd/ICU).
@crazywhalecc
crazywhalecc force-pushed the fix/hosted-build-swoole-pgsql branch from e76609a to 158babd Compare October 22, 2026 01:18
@crazywhalecc

Copy link
Copy Markdown
Owner Author

Final CI for 158babd7 is fully green: all 16 jobs pass, including swoole,... and pdo_pgsql,pgsql on PHP 8.3 / 8.5 × Linux / macOS / Windows. The previous Linux Swoole failure was Zig libc++ __locale_dir/support/linux.h expanding PHP's vsnprintf macro; the -include locale pre-include fixes it. The pgsql 8.3 macOS job also passes with the full resolved static libpq dependency list.

@crazywhalecc
crazywhalecc merged commit 583746a into v3 Oct 22, 2026
17 checks passed
@crazywhalecc
crazywhalecc deleted the fix/hosted-build-swoole-pgsql branch October 22, 2026 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need-test This PR has not been tested yet, cannot merge now test/php-83

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants