From 13f1158e83aa4ab84df5866ade1ae7fd2d0b68de Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Sat, 8 Jun 2024 08:06:54 +0200 Subject: [PATCH] Also link openssl on windows This commit adds openssl as dependency for bundled windows builds. This is required as otherwise the scram-sha-256 authentication method is broken for bundled windows builds. I've verified the issue locally using a recent postgres docker container + wine. I also verifed that this change fixes the issue. --- .github/workflows/ci.yml | 7 +++---- pq-src/Cargo.toml | 2 +- pq-src/additional_include/pg_config.h | 7 ++++--- pq-src/build.rs | 23 +++++++++-------------- pq-src/src/lib.rs | 1 - 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index afadfbc..8d7abfb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,10 +70,9 @@ jobs: - name: Windows setup (bundled) if: runner.os == 'Windows' && matrix.features == 'bundled' - shell: bash run: | - echo "OPENSSL_RUST_USE_NASM=0" >> $GITHUB_ENV - echo OPENSSL_SRC_PERL=C:/Strawberry/perl/bin/perl >> $GITHUB_ENV + echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV + vcpkg install openssl:x64-windows-static-md - name: Install rust toolchain uses: dtolnay/rust-toolchain@stable @@ -89,7 +88,7 @@ jobs: - name: Test compile diesel shell: bash - # currently broken as diesel does not allow pq-sys 0.5 yet + # allow to fail as diesel might not pull in the right feature yet continue-on-error: true run: | cargo new test_diesel diff --git a/pq-src/Cargo.toml b/pq-src/Cargo.toml index 5fb055f..504e4f3 100644 --- a/pq-src/Cargo.toml +++ b/pq-src/Cargo.toml @@ -22,7 +22,7 @@ keywords = ["bindings", "libpq", "pq-sys", "bundled"] categories = ["database", "external-ffi-bindings"] readme = "README.md" -[target.'cfg(not(target_os = "windows"))'.dependencies] +[dependencies] openssl-sys = "0.9.93" [build-dependencies] diff --git a/pq-src/additional_include/pg_config.h b/pq-src/additional_include/pg_config.h index 87ff582..f89ff4d 100644 --- a/pq-src/additional_include/pg_config.h +++ b/pq-src/additional_include/pg_config.h @@ -212,11 +212,8 @@ /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 - -#ifndef __WIN32__ /* Define to 1 to build with OpenSSL support. (--with-ssl=openssl) */ #define USE_OPENSSL 1 -#endif /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ @@ -276,3 +273,7 @@ #if defined _WIN32 #define HAVE_INET_ATON 1 #endif + +#if defined _WIN32 +#define HAVE_DECL_STRNLEN 1 +#endif diff --git a/pq-src/build.rs b/pq-src/build.rs index 8b91a20..699291f 100644 --- a/pq-src/build.rs +++ b/pq-src/build.rs @@ -48,6 +48,7 @@ const LIBPORTS_WINDOWS: &[&str] = &[ "win32stat.c", "open.c", "dirmod.c", + "inet_aton.c", ]; const LIBCOMMON_BASE: &[&str] = &[ @@ -78,22 +79,14 @@ const LIBCOMMON_BASE: &[&str] = &[ "restricted_token.c", "sprompt.c", "logging.c", -]; - -const LIBCOMMON_NOT_WINDOWS: &[&str] = &[ "cryptohash_openssl.c", "hmac_openssl.c", "protocol_openssl.c", ]; -const LIBCOMMON_WINDOWS: &[&str] = &[ - "cryptohash.c", - "hmac.c", - "md5.c", - "sha1.c", - "sha2.c", - "wchar.c", -]; +const LIBCOMMON_NOT_WINDOWS: &[&str] = &[]; + +const LIBCOMMON_WINDOWS: &[&str] = &["wchar.c"]; const LIBPQ_BASE: &[&str] = &[ "fe-auth-scram.c", @@ -109,9 +102,11 @@ const LIBPQ_BASE: &[&str] = &[ "legacy-pqsignal.c", "libpq-events.c", "pqexpbuffer.c", + "fe-secure-common.c", + "fe-secure-openssl.c", ]; -const LIBPQ_NOT_WINDOWS: &[&str] = &["fe-secure-common.c", "fe-secure-openssl.c"]; +const LIBPQ_NOT_WINDOWS: &[&str] = &[]; const LIBPQ_WINDOWS: &[&str] = &["fe-secure.c", "pthread-win32.c", "win32.c"]; @@ -173,6 +168,7 @@ fn main() { format!("{path}src/include"), format!("{crate_dir}/additional_include"), temp_include.clone(), + env::var("DEP_OPENSSL_INCLUDE").unwrap().clone(), ][..]; let includes = if target_os == "windows" { @@ -182,8 +178,7 @@ fn main() { ]; [base_includes, includes_windows].concat() } else { - let includes_not_windows = &[env::var("DEP_OPENSSL_INCLUDE").unwrap().clone()]; - [base_includes, includes_not_windows].concat() + base_includes.to_vec() }; basic_build diff --git a/pq-src/src/lib.rs b/pq-src/src/lib.rs index c135f59..176961b 100644 --- a/pq-src/src/lib.rs +++ b/pq-src/src/lib.rs @@ -1,2 +1 @@ -#[cfg(not(target_os = "windows"))] extern crate openssl_sys;