PostgreSQL's libpq ported to the Zig build system
  • C 60.6%
  • Zig 39.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-06-22 11:26:43 +02:00
.github/workflows PostgreSQL 18.3 2026-06-08 22:23:51 +02:00
include rebase 2025-12-12 12:54:20 +01:00
.gitignore Rely on an external source of truth for listing libc features (#14) 2026-06-07 23:10:22 +02:00
build.zig Improve readability with a 1-line function 2026-06-22 11:26:43 +02:00
build.zig.zon Update the printf attribute 2026-06-08 22:51:01 +02:00
LICENSE Test glibc version for strlcat and strlcpy 2025-12-12 12:54:20 +01:00
README.md PostgreSQL 18.4 2026-06-08 22:30:45 +02:00

build.zig for libpq

Provides a package to be used by the zig package manager for C programs.

Status

Architecture \ OS Linux MacOS
x86_64 ✅ ✅
arm 64 (untested) ✅ (not with OpenSSL)
Refname PostgreSQL version Zig 0.17-dev Zig 0.16.0 Zig 0.15.x Zig 0.14.x Zig 0.13.x
5.18.4 REL_18_4 ✅ ✅ ✅ ✅ ❌
5.16.4+5 REL_16_4 ❌ ❌ ✅ ✅ ❌
5.16.4+2 REL_16_4 ❌ ❌ ❌ ❌ ✅

Use

Add the dependency to your build.zig.zon by running the following command:

zig fetch --save git+https://github.com/allyourcodebase/libpq#master

Then, in your build.zig:

const postgres = b.dependency("libpq", { .target = target, .optimize = optimize });

// to use from Zig (since 5.16.4+5):
mod.addImport("libpq", postgres.module("libpq"));

// to use from C:
exe.linkLibrary(postgres.artifact("pq"));

Options

  -Dssl=[enum]                 Choose which dependency to use for SSL. Defaults to LibreSSL
                                 Supported Values:
                                   OpenSSL
                                   LibreSSL
                                   None
  -Ddisable-zlib=[bool]        Remove zlib as a dependency
  -Ddisable-zstd=[bool]        Remove zstd as a dependency

Bump dependencies

To update this project dependencies:

zig fetch --save=upstream git+https://github.com/postgres/postgres#REL_18_4
zig fetch --save          git+https://github.com/allyourcodebase/openssl#main
zig fetch --save          git+https://github.com/allyourcodebase/libressl#master
zig fetch --save          git+https://github.com/allyourcodebase/zlib#main
zig fetch --save          git+https://github.com/allyourcodebase/zstd#master