Skip to content

Commit

Permalink
Merge pull request #57 from sgrif/fix/old_glibc_does_not_have_explici…
Browse files Browse the repository at this point in the history
…t_bzero

Fix/old glibc does not have explicit bzero
  • Loading branch information
weiznich committed Apr 10, 2024
2 parents 0a67a9c + c1aeae0 commit c69261c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pq-src/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pq-src"
version = "0.1.4"
version = "0.1.5"
edition = "2021"
include = [
"src/*",
Expand All @@ -18,6 +18,9 @@ description = "Bundled version of libpq"
license = "MIT OR Apache-2.0"
repository = "https://github.com/sgrif/pq-sys"
links = "pq_sys_src"
keywords = ["bindings", "libpq", "pq-sys", "bundled"]
categories = ["database", "external-ffi-bindings"]
readme = "README.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
68 changes: 68 additions & 0 deletions pq-src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
pq-sys
======

Autogenerated Rust bindings for libpq

Building
--------

This repository contains direct, one-to-one mappings to the C functions provided
in `libpq-fe.h` and `postgres_ext.h`. This library expects that libpq be
installed on the system.

The build script of crate will attempt to find the lib path of libpq using the
following methods:

* First it will look for an environment variable in the format of `PQ_LIB_DIR_{TARGET}`
where `{TARGET}` gets replaced by the Target environment variable set for cross-compilation
* Second, if the environment variable `PQ_LIB_DIR` is set, it will use its value
* If the environment variable isn't set, it tries to use pkg-config to locate it.
All the config options, such as `PKG_CONFIG_ALLOW_CROSS`, `PKG_CONFIG_ALL_STATIC`
etc., of the crate [pkg-config](https://docs.rs/pkg-config/)
apply.
* Then, for MSVC ABI builds the build script will attempt use the library from a
[vcpkg](https://github.com/Microsoft/vcpkg) installation if there is one available.
You may need to set VCPKG_ROOT (or run `vcpkg integrate install`), set VCPKGRS_DYNAMIC=1, and run
`vcpkg install libpq:x64-windows`. See the documentation for the [vcpkg](https://docs.rs/vcpkg/) crate for more.
* If it still can't locate the library, it will invoke the Postgres command
`pg_config --libdir`

The build script instructs Cargo to link the library statically if the environmental
variable `PQ_LIB_STATIC` is set. This can be useful, if targeting for a musl target.
If pkg-config is being used, it's configuration options will apply.

## FAQ

### I'm seeing `dyld: Symbol not found __cg_jpeg_resync_to_restart` on macOS

This is caused when the output of `pg_config --libdir` is a directory that also
contains `libjpeg.dylib` which differs from the system libjpeg. This is usually
caused by install postgres via homebrew, or using postgresapp.com.

If you've installed via homebrew, you should not see this issue unless you've
provided `features = ["pkg-config"]`. You can work around the issue by exporting
`PQ_LIB_DIR="$(brew --prefix postgres)/lib"`.

If you've installed postgresql using postgresapp.com, you will not be able to
run your binaries using `cargo run` or `cargo test`. You can compile the binary
manually via `cargo build` and then run `/target/debug/yourapp`. You can also
manually create a directory that contains only a symlink to `libpq.dylib` and
nothing else, then export `PQ_LIB_DIR` to that directory. It is recommended that
you do not use postgresapp.com.

## License

Licensed under either of

* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
4 changes: 2 additions & 2 deletions pq-src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ const LIBPORTS_BASE: &[&str] = &[
"quotes.c",
"strerror.c",
"tar.c",
"explicit_bzero.c",
];

const LIBPORTS_LINUX: &[&str] = &["getpeereid.c", "thread.c"];

const LIBPORTS_MACOS: &[&str] = &["explicit_bzero.c", "thread.c"];
const LIBPORTS_MACOS: &[&str] = &["thread.c"];

const LIBPORTS_WINDOWS: &[&str] = &[
"getpeereid.c",
"explicit_bzero.c",
"win32common.c",
"win32dlopen.c",
"win32env.c",
Expand Down

0 comments on commit c69261c

Please sign in to comment.