From bfebd30f81430bdc13871986ea1cbeb6ecb7c13a Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Sat, 20 May 2023 22:03:35 -0700 Subject: [PATCH 1/2] This PR fixes compiling the pg extension with MSVC 2022 when using extconf.rb, nmake and libpq installed by vcpkg (not mingw64). Running the command: ruby extconf.rb --with-pg-include=c:\Source\vcpkg\installed\x64-windows\include --with-pg-lib=c:\Source\vcpkg\installed\x64-windows\lib Fails with linker errors: pg_connection.obj : error LNK2019: unresolved external symbol __imp_WSAGetLastError referenced in function pg_rb_thread_io_wait This is fixed by adding ws2_32.lib to the linker command. --- ext/extconf.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/extconf.rb b/ext/extconf.rb index 9bf1c2e5f..d9b7b38bb 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -60,6 +60,10 @@ if dlldir && RbConfig::CONFIG["RPATHFLAG"].to_s.empty? append_ldflags "-Wl,-rpath,#{dlldir.quote}" end + + if /mswin/ =~ RUBY_PLATFORM + $libs = append_library($libs, 'ws2_32') + end end $stderr.puts "Using libpq from #{dlldir}" From 46d9dad55a33d49adde2413e404e90075070f88a Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Fri, 1 Sep 2023 09:25:12 +0200 Subject: [PATCH 2/2] CI: Add test with mswin environment --- .github/workflows/source-gem.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/source-gem.yml b/.github/workflows/source-gem.yml index 00708b398..dd9bf5854 100644 --- a/.github/workflows/source-gem.yml +++ b/.github/workflows/source-gem.yml @@ -42,6 +42,10 @@ jobs: ruby: "2.5" PGVERSION: 9.4.26-1-windows-x64 PGVER: "9.4" + - os: windows + ruby: "mswin" + PGVERSION: 15.1-1-windows-x64 + PGVER: "15" - os: ubuntu ruby: "head" PGVER: "15" @@ -82,7 +86,7 @@ jobs: name: source-gem - name: Install required packages Windows - if: matrix.os == 'windows' + if: matrix.os == 'windows' && matrix.ruby != 'mswin' shell: cmd run: ridk exec sh -c "pacman --sync --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-gcc"