Skip to content

recipe: psycopg2 2.9.12 (+ flet-libpq 17.5)#84

Merged
ndonkoHenri merged 3 commits into
mainfrom
psycopg
Jun 20, 2026
Merged

recipe: psycopg2 2.9.12 (+ flet-libpq 17.5)#84
ndonkoHenri merged 3 commits into
mainfrom
psycopg

Conversation

@ndonkoHenri

Copy link
Copy Markdown

Adds the psycopg2 PostgreSQL driver for iOS and Android (closes flet-dev/flet#3204), its native dependency flet-libpq, and a small forge feature — requirements.host_build — that psycopg2 uses to avoid bundling a library it static-links.

Recipes

  • flet-libpq 17.5 — PostgreSQL's libpq, built from the release tarball (client library only). Ships the static libpq.a + libpgcommon/libpgport archives, headers, and a relocatable pg_config shim, alongside a shared libpq.so. Cross-compile fixes: ac_cv_header_langinfo_h=no (Android API 24 hides nl_langinfo), strip quotes from CFLAGS/LDFLAGS (postgres bakes them into config_info.c string literals on iOS), and make all-lib + pre-touch libpq-refs-stamp (iOS _atexit false-positive).
  • psycopg2 2.9.12 — a Cython C-extension that statically links libpq + OpenSSL into _psycopg.so (Pattern E, like pymssql). mobile.patch ships the *_shlib.a PIC archives, links OpenSSL + the extra archives unconditionally (psycopg2 only does so in finalize_darwin/finalize_linux, which the cross sys.platform matches neither), and reads pg_config from the PG_CONFIG env var.

Forge: requirements.host_build

A native lib a C-extension static-links is folded into the extension's own .so — needed at build time, but not at runtime. requirements.host, however, promotes every flet-* dep to the wheel's Requires-Dist, so the consuming app bundles the unused flet-lib wheel (~2.7 MB android / ~3.9 MB iOS of dead weight per app).

requirements.host_build installs the dep into the cross environment exactly like host (its opt/include/opt/lib wired into CFLAGS/LDFLAGS and pkg-config), but excludes it from Requires-Dist (the promotion loop only walks host). psycopg2 uses it for flet-libpq; pymssql → flet-libfreetds is a natural follow-on adopter.

This PR also rewrites the now-stale requirements.build/host schema descriptions, which carried chaquopy-heritage claims that the current builders don't implement (a cmake build keyword generating chaquopy.toolchain.cmake; openssl/sqlite/python host keyword special-cases; a $SRC_DIR/../requirements extraction path; a >= Requires-Dist pin). They now accurately describe the build-vs-cross environment, the install_root CFLAGS/LDFLAGS/pkg-config wiring, the {platlib}/{prefix} script_env placeholders, and the flet-*-only == Requires-Dist promotion.

Tested

  • Builds green on Android arm64-v8a and iOS (arm64 device, arm64 sim, x86_64 sim),rrrrrrrr+ Python 3.12. (CI builds the full matrix.)
  • Live on-device (Android arm64 emulator + iOS simulator): psycopg2 imports (libpq 170005, static-folded), then a real TCP + SCRAM-SHA-256 auth + SELECT round-trip agains PostgreSQL 17.10 succeeds on both platforms.
  • host_build verified: the psycopg2 wheel METADATA no longer lists flet-libpq in Requires-Dist; the built app no longer bundles the flet-libpq wheel; and psycopg2 still connects + queries on-device with it absent — confirming the dependency was purely build-time.

Adds the psycopg2 PostgreSQL driver (flet-dev/flet#3204) for iOS and Android,
plus its native dependency flet-libpq.

- flet-libpq 17.5: PostgreSQL's libpq, built from the release tarball (client
  library only). Ships the static libpq.a + libpgcommon/libpgport archives,
  headers and a relocatable pg_config shim, alongside a shared libpq.so.
  Cross-compile fixes: ac_cv_header_langinfo_h=no (Android API 24 hides
  nl_langinfo), strip quotes from CFLAGS/LDFLAGS (postgres bakes them into
  config_info.c string literals on iOS), and make all-lib + pre-touch
  libpq-refs-stamp (iOS _atexit false-positive).
- psycopg2 2.9.12: a Cython C-extension that statically links libpq + OpenSSL
  into _psycopg.so. mobile.patch ships the *_shlib.a PIC archives, links OpenSSL
  + the extra archives unconditionally (psycopg2 only does so in
  finalize_darwin/finalize_linux, which the cross sys.platform matches neither),
  and reads pg_config from the PG_CONFIG env var.

Tested: built green on Android arm64-v8a and iOS (device + arm64/x86_64 sim),
Python 3.12. Live on-device round-trip (connect + SELECT against PostgreSQL
17.10) passes on an Android emulator and an iOS simulator.
A native lib that a C-extension STATICALLY links is folded into the extension's
own .so, so it is needed at build time but not at runtime. requirements.host,
however, promotes every flet-* dep to the wheel's Requires-Dist, so the consuming
app bundles the unused flet-lib* wheel (~2.7 MB android / ~3.9 MB iOS of dead
weight per app).

Add requirements.host_build: installed into the cross environment exactly like
host (its opt/include + opt/lib wired into CFLAGS/LDFLAGS and pkg-config), but
excluded from Requires-Dist (the promotion loop only walks "host"). psycopg2
adopts it for flet-libpq; pymssql -> flet-libfreetds is a natural follow-on.

Also rewrites the stale requirements.build / requirements.host schema
descriptions: they carried chaquopy-heritage claims (a "cmake" build keyword
generating chaquopy.toolchain.cmake; "openssl"/"sqlite"/"python" host keyword
special-cases; a $SRC_DIR/../requirements extraction path; a ">=" Requires-Dist
pin) that the current builders do not implement. They now accurately describe the
build vs cross environment, the install_root CFLAGS/LDFLAGS/pkg-config wiring, the
{platlib}/{prefix} script_env placeholders, and the flet-*-only "==" Requires-Dist
promotion.

Verified: psycopg2 builds green on android arm64 with host_build, the wheel no
longer lists flet-libpq in Requires-Dist, the app no longer bundles flet-libpq,
and psycopg2 still connects + SELECTs against live PostgreSQL 17.10 on-device.
@ndonkoHenri ndonkoHenri merged commit d1ef993 into main Jun 20, 2026
15 of 27 checks passed
@ndonkoHenri ndonkoHenri deleted the psycopg branch June 20, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant