Closed emk closed 4 years ago
PR sounds great
Hi, I'm the maintainer of https://gitlab.com/rust_musl_docker/image and I recently ran into this problem also. Is there any movement fixing this?
@emk Apparently there hasn't been a PR fixing this. Could you elaborate why the order of the linker flags matter? Is the problem that libpq pulls in a dependency to OpenSSL? ( https://github.com/postgres/postgres/blame/master/src/interfaces/libpq/fe-secure-openssl.c#L702-L715 )
From https://github.com/clux/muslrust/issues/49 , I got the impression libpq can be built with support for SSL or not, and depending on that the linking might fail, if it doesn't find the object. I wonder what's the correct way for this crate to detect that – is there a way to detect that and insert a dependence, or should the build just be configurable via an env var (hoping that the users will find out about that and set it if they need to.)
I'm still getting reports of similar errors occasionally, and we have several long bug reports over at https://github.com/emk/rust-musl-builder/issues/69 and https://github.com/emk/rust-musl-builder/issues/64. Unfortunately, I've been busy lately, and I've forgotten the details. But if anybody wants to take a look, please feel welcome.
I managed to consistently reproduce this. Here's a Dockerized repro: https://github.com/golddranks/pq_link_test
Hello! Thank you for maintaining
pq-sys
. I've used it in a lot of projects, and it works very nicely.I'm the maintainer of rust-musl-builder, which makes it possible to statically link Rust applications using the
postgres
,diesel
andopenssl
crates. (It's apparently pretty popular, with over 450 thousand downloads on Docker Hub.)Recently, some users of
rust-musl-builder
have been encountering a linking problem withpq-sys
. This also seems to affect users ofmuslrust
, the other cross-building library:Investigation suggests that the problem is that these libraries:
...appear before:
Manually reordering these will cause the linker to succeed.
The underlying problem sees to be that a statically-linked
libpq
doesn't actually pull in a statically linkedlibopenssl
or the relevant portions of musl-libc'slibc
.The easiest fix seems to be including the following in
main.rs
:But this is fragile, and the exact details seem to change from one release of
rustc
to the next. You can find a working example here, and it should break if you reorder theextern crate
declarations.Probably the easiest fix (kludge?) for this would be to include
extern crate openssl_sys;
somewhere inpq-sys
, at least whenPQ_LIB_STATIC_X86_64_UNKNOWN_LINUX_MUSL=1
is set. That feels slightly hackish, but it would delegate responsibility for correctly finding and linkinglibopenssl
to theopenssl_sys
crate, which has a fairly fancy cross-platform build system.Once again, thank you so much for your crate, and for maintaining it over all these years! If there's anything I can do to help sort this out, please let me know! I'd be happy to prepare a PR for you to review, or whatever else is needed.