-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static linking needs to include openssl
somehow.
#25
Comments
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 clux/muslrust#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 emk/rust-musl-builder#69 and emk/rust-musl-builder#64. Unfortunately, I've been busy lately, and I've forgotten the details. But if anybody wants to take a look, please feel welcome. |
Added a new feature (openssl-static) that includes the openssl-sys crate to fix static builds. This fixes sgrif#25
Added a new feature (openssl-static) that includes the openssl-sys crate to fix static builds. Renamed src/lib.rs to src/bindgen.rs and added a new lib.rs that re-exports everything from bindgen.rs to prevent future bindgen runs from reverting this change. This fixes sgrif#25
I managed to consistently reproduce this. Here's a Dockerized repro: https://github.com/golddranks/pq_link_test |
Added a new feature (openssl-static) that includes the openssl-sys crate to fix static builds. Renamed src/lib.rs to src/bindgen.rs and added a new lib.rs that re-exports everything from bindgen.rs to prevent future bindgen runs from reverting this change. This fixes sgrif#25
Added a new feature (openssl-static) that includes the openssl-sys crate to fix static builds. Renamed src/lib.rs to src/bindgen.rs and added a new lib.rs that re-exports everything from bindgen.rs to prevent future bindgen runs from reverting this change. This fixes sgrif#25
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:diesel
link order issues sometimes break build emk/rust-musl-builder#69Investigation 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.
The text was updated successfully, but these errors were encountered: