Pq-sys 0.5.0

I'm happy to announce the release of pq-sys 0.5.0. pq-sys is a major dependency of Diesel, the safe, extensible ORM and Query Builder for Rust. The crate provides Rust bindings to libpq, the official C library for connection to PostgreSQL databases. Diesel uses these bindings internally to implement PgConnection. It's a major building block that allows us to provide a highly performant implementation.

This pq-sys release includes major changes and new features. It updates the bundled Rust bindings generated with an up-to date version of bindgen and libpq. This is a potential breaking change due to changes in the generated definitions, although it does not affect Diesel. Beside this breaking change, pq-sys 0.5 introduces two new features: Support for building and statically linking libpq as part of the cargo build process and generating Rust bindings based on your local libpq version.

To support future development efforts, please consider sponsoring me on GitHub. I would like to extend a sincere thank you to all my generous sponsors who have contributed to making this release possible.

Building and statically linking libpq during cargo build

pq-sys 0.5 introduces an optional dependency on the new pq-src crate behind the bundled feature flag. This feature enables building and statically linking a version of libpq to the final binary. It's meant to simplify setting up and deploying applications depending on pq-sys, as this feature automatically provides the required native dependency. This feature currently supports targeting Windows, Linux and macOS. We run CI tests for it using the following toolchains:

  • x86_64-unknown-linux-gnu
  • x86_64-pc-windows-msvc
  • x86_64-apple-ios

In addition we received reports that it works on the following toolchains as well:

  • aarch64-apple-darwin
  • x86_64-unknown-linux-musl

We are happy to extend the list of tested and supported targets based on your reports and contributions.

The bundled feature builds libpq based on the PostgreSQL 16.1 release. We expect to update the bundled version over time. The included Rust bindings match the bundled version.

PostgreSQL's build process is heavily based on autotools. As this is known to be problematic on non-Unix platforms we decided not to relay on the standard build process. Instead we emulate the build process by using the cc crate and specifying the relevant list of source files directly.

If you expect that your software will also be packed by various Linux distributions you should consider putting the usage of this feature behind a own feature flag, so that these packaged version of your application can depend on the packed libpq version from the distribution instead.

Generating bindings on build time

pq-sys 0.5 introduces the buildtime_bindgen feature flag, that allows to regenerate the used Rust bindings based on your local libpq version. This feature is targeted at users that target significantly different environments than that one used to generate the provided bindings. This feature might also be interesting for Linux distributions packaging pq-sys as they now can ensure that the used bindings actually match their libpq version.

Using the new release with diesel

pq-sys is currently not supported by Diesel. We expect to release built-in support for this new version with the next Diesel feature release. If you want to try out the features now you can add the following lines to your Cargo.toml file:

# optionally enable one of the new feature flags
# here
pq-sys = "0.4.8"
# your other dependencies

# Point to the commit before bumping the version number
# as that's the last one that is compatible with the current
# diesel release
pq-sys = { git = "https://github.com/sgrif/pq-sys", rev = "f8d1f4a" }

We are happy to hear about potential bugs and success stories.