sgrif / pq-sys

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

use vcpkg with automatic dependency following #23

Closed mcgoo closed 2 years ago

mcgoo commented 5 years ago

This uses a more resilient api in the vcpkg crate to link recursively against all required ports in the vcpkg tree given the libpq port name.

This does not extend to knowing which system libraries are required. This now includes shell32, so it is added to the manual list of system libraries that are linked if libpq is found in vcpkg.

sgrif commented 5 years ago

Thanks. Can you open a PR against Diesel which uses this branch as a git dependency so we can see a windows build there?

mcgoo commented 5 years ago

Thanks @sgrif. The vcpkg builds and everything else work on the azure CI, but there was a spurious CI failure (because of macos VM timeout) on the PR above.

ahwatts commented 3 years ago

I was recently trying to install diesel_cli using libpq built with the x64-windows-static-md vcpkg triple, and was getting link errors about unresolved externals:

(error messages included here for Google people)

  = note: libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol pg_set_noblock referenced in function PQconnectPoll
          libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol pg_snprintf referenced in function PQconnectPoll
          libpq.lib(fe-secure-openssl.obj) : error LNK2001: unresolved external symbol pg_snprintf
          libpq.lib(win32.obj) : error LNK2001: unresolved external symbol pg_sprintf
          libpq.lib(fe-connect.obj) : error LNK2001: unresolved external symbol pg_sprintf
          libpq.lib(fe-exec.obj) : error LNK2001: unresolved external symbol pg_sprintf
          libpq.lib(fe-protocol2.obj) : error LNK2001: unresolved external symbol pg_sprintf
          libpq.lib(fe-auth.obj) : error LNK2001: unresolved external symbol pg_sprintf
          libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol pg_fprintf referenced in function defaultNoticeProcessor
          libpq.lib(fe-exec.obj) : error LNK2001: unresolved external symbol pg_fprintf
          libpq.lib(encnames.obj) : error LNK2001: unresolved external symbol pg_fprintf
          libpq.lib(fe-misc.obj) : error LNK2001: unresolved external symbol pg_fprintf
          libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol pgwin32_fopen referenced in function parseServiceFile
          libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol strlcpy referenced in function PQcancel
          libpq.lib(fe-protocol2.obj) : error LNK2001: unresolved external symbol strlcpy
          libpq.lib(fe-protocol3.obj) : error LNK2001: unresolved external symbol strlcpy
          libpq.lib(fe-secure-openssl.obj) : error LNK2001: unresolved external symbol strlcpy
          libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol pg_get_encoding_from_locale referenced in function PQsetClientEncoding
          libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol inet_net_ntop referenced in function PQconnectPoll
          libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol pg_gai_strerror referenced in function PQconnectPoll
          libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol __imp_SHGetFolderPathA referenced in function pqGetHomeDirectory
          libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol pg_getaddrinfo_all referenced in function PQconnectPoll
          libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol pg_freeaddrinfo_all referenced in function PQconnectPoll
          libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol pg_link_canary_is_frontend referenced in function connectDBStart
          libpq.lib(fe-exec.obj) : error LNK2019: unresolved external symbol pg_tolower referenced in function PQfnumber
          libpq.lib(fe-exec.obj) : error LNK2019: unresolved external symbol pg_vsnprintf referenced in function pqInternalNotice
          libpq.lib(pqexpbuffer.obj) : error LNK2001: unresolved external symbol pg_vsnprintf
          libpq.lib(fe-protocol2.obj) : error LNK2019: unresolved external symbol pg_strcasecmp referenced in function pqSetenvPoll
          libpq.lib(fe-protocol3.obj) : error LNK2001: unresolved external symbol pg_strcasecmp
          libpq.lib(fe-secure-common.obj) : error LNK2001: unresolved external symbol pg_strcasecmp
          libpq.lib(fe-auth.obj) : error LNK2019: unresolved external symbol pg_md5_encrypt referenced in function PQencryptPassword
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol pg_strong_random referenced in function pg_fe_scram_exchange
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol pg_b64_encode referenced in function pg_fe_scram_exchange
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol pg_b64_decode referenced in function pg_fe_scram_exchange
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol pg_b64_enc_len referenced in function pg_fe_scram_exchange
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol pg_b64_dec_len referenced in function pg_fe_scram_exchange
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol pg_saslprep referenced in function pg_fe_scram_init
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol scram_HMAC_init referenced in function pg_fe_scram_exchange
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol scram_HMAC_update referenced in function pg_fe_scram_exchange
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol scram_HMAC_final referenced in function pg_fe_scram_exchange
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol scram_SaltedPassword referenced in function build_client_final_message
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol scram_H referenced in function build_client_final_message
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol scram_ClientKey referenced in function build_client_final_message
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol scram_ServerKey referenced in function pg_fe_scram_exchange
          libpq.lib(fe-auth-scram.obj) : error LNK2019: unresolved external symbol scram_build_verifier referenced in function pg_fe_scram_build_verifier
          libpq.lib(fe-secure-openssl.obj) : error LNK2019: unresolved external symbol pg_strerror_r referenced in function initialize_SSL
          C:\Users\Andrew\AppData\Local\Temp\cargo-installbAEPbV\release\deps\diesel-e28788914659534e.exe : fatal error LNK1120: 32 unresolved externals

Ultimately I needed to make these changes to build.rs in the .cargo/registry/src/... directory in order to get it to build.

It's just my experience, but I wold vote in favor of it getting merged.

Diggsey commented 2 years ago

I had the same experience of linker errors without this PR, so I hope it is merged soon :)