Skip to content

feat(windows): make libpq and abseil-cpp build for a mingw host - #4

Merged
dlipicar merged 1 commit into
masterfrom
feat/mingw-libpq-abseil
Aug 14, 2026
Merged

feat(windows): make libpq and abseil-cpp build for a mingw host#4
dlipicar merged 1 commit into
masterfrom
feat/mingw-libpq-abseil

Conversation

@dlipicar

Copy link
Copy Markdown
Contributor

Two nixpkgs packages that Logos modules declare in metadata.json
nix.packages.runtime but that do not build for a mingw host. Both fixed here
rather than in each consumer, alongside the existing cli11 / glib / sqlite
/ libwebp entries.

The common cause

nixpkgs builds mingw-w64 against mcfgthread, so pthread.h and
libpthread.a do not exist anywhere in the default cross closure. Anything
carrying an unconditional POSIX-threads assumption fails, and it fails late —
during compilation of a transitive dependency, far from whatever declared it.

This is the same hole that has already produced four other unrelated-looking
failures during the Windows port: libpq's pthread_barrier_wait.c, Rust's
x86_64-pc-windows-gnu std wanting -l:libpthread.a, lsquic's
clock_gettime64, and nim-boringssl. Adding windows.pthreads to the offending
package's buildInputs is the whole fix in each case.

abseil-cpp

absl/base/internal/thread_identity.cc:18:10: fatal error: pthread.h: No such file or directory
   18 | #include <pthread.h>

One line. Verified: builds clean for x86_64-w64-mingw32 with the fix, producing
libabsl_*.dll.a.

libpq

Four unrelated obstacles, none of them individually interesting:

  • curlSupport = false — postgres 18 links libcurl for its OAuth device
    flow, and curl cross to mingw drags in ngtcp2 → nghttp3, whose examples
    #include <arpa/inet.h> and fail. Nothing in Logos uses OAuth auth.
  • drop make-shell-wrapper-hookmakeWrapper resolves to a
    host-platform bash, and mingw bash does not build. libpq never calls
    wrapProgram; the hook is vestigial.
  • windows.pthreads — the mcfgthread gap above.
  • separateDebugInfo = false — that hook runs objcopy --only-keep-debug,
    which is the ELF split.

Note this is the client library only. Full postgresql (the server) has no
mingw build and is deliberately not made available — a module that wants
postgres should declare libpq, which is all it ever links or dlopens anyway
(see logos-co/logos-delivery-module#85, which corrects exactly that
declaration).

Verified: libpq.dll builds, loads on real Windows 10.0.26200, and
PQconnectdb/PQexec/PQfinish/PQlibVersion resolve. Its import table is
fully Nix-tracked — Windows system DLLs plus the two OpenSSL DLLs, which
win-dll-link.sh already stages.

Why these two, now

logos-delivery-module needs libpq; logos-chat-ui declares abseil-cpp.
Neither could be expressed per-platform in metadata.json
parseMetadata.nix produces one flat list with no host gating — so the fix has
to live in the package set.

A note for reviewers

Both entries are narrow overrideAttrs on top of upstream. If this pattern keeps
recurring (this is the fifth instance), the alternative worth considering is
making the whole cross set use a pthreads-providing thread model rather than
mcfgthread, which would fix the class instead of the instances. That is a much
larger change — it rebuilds the entire Windows closure — so I have not attempted
it here, but it may be the right long-term answer.

🤖 Generated with Claude Code

Both are declared by Logos modules in metadata nix.packages.runtime and
neither builds for x86_64-w64-mingw32. Fixed here rather than in each
consumer, since metadata has no per-platform gating (parseMetadata.nix
produces one flat list).

Common cause: nixpkgs builds mingw-w64 against mcfgthread, so pthread.h
and libpthread.a are absent from the whole cross closure. This is the
fifth unrelated-looking failure from that one hole -- libpq, Rust's
windows-gnu std, lsquic's clock_gettime64, nim-boringssl, and now abseil
-- and each time the fix is windows.pthreads in buildInputs.

abseil-cpp: thread_identity.cc includes <pthread.h> unconditionally.

libpq: four obstacles -- curlSupport=false (postgres 18 links libcurl for
OAuth, and curl cross drags in ngtcp2 -> nghttp3, whose EXAMPLES include
<arpa/inet.h>); drop make-shell-wrapper-hook (wants a HOST bash, which
mingw does not build, and libpq never calls wrapProgram); windows.pthreads;
separateDebugInfo=false (that hook is the ELF split).

The libpq entry is the CLIENT library only. Full postgresql has no mingw
build and is deliberately not exposed -- a module wanting postgres should
declare libpq, which is all it ever links or dlopens.

Verified: abseil-cpp builds producing libabsl_*.dll.a; libpq.dll builds,
loads on real Windows 10.0.26200, and PQconnectdb/PQexec/PQfinish/
PQlibVersion resolve.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 14, 2026 14:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants