sgrif / pq-sys

Auto-generated rust bindings for libpq
Apache License 2.0
42 stars 32 forks source link

The build script adds standard path to rustc-link-search, causing troubles #31

Open jerry73204 opened 4 years ago

jerry73204 commented 4 years ago

The section in build.rs can possibly add the standard path /usr/lib (or /usr/lib/x86_64-linux-gnu on Debian) to the rustc-link-search path. It will introduce an extra -L/usr/lib flag to the linker. It is not desired because it overrides the search order of other more specific search paths.

I encountered a scenario to import both opencv and diesel in my project. I install the OpenCV 4 in non-standard path (It's because Ubuntu ships the older OpenCV), and set PKG_CONFIG_PATH to let the build.rs in opencv crate to append the non-standard search paths for me.

In the mean time, the pq-sys required by diesel puts the standard search path to the linker as I pointed here. It causes the linker to search for libopencv_*.so in both standard and non-standard paths, and the build fails due to conflict.

I see an obvious solution is the pkg-config feature. However, pq-sys is not the direct dependency of my project but for the dependent diesel, making the patch a bit difficult. The build script itself should also avoid producing standard paths to the linker.

davepacheco commented 3 years ago

In case this is helpful, I stumbled across what appears to be a workaround for the same issue in libz-sys: https://github.com/rust-lang/libz-sys/blob/6b12e9a37bae1a444aaa1a11248c5b0e555869b4/build.rs#L37-L43 (which seems relevant because libz-sys is the example that the Cargo docs use for exposing a native library)