From 8f3b4e26775439a5c380a5a3a3c39671986e659a Mon Sep 17 00:00:00 2001 From: Alex Kasko Date: Fri, 17 Apr 2026 17:07:54 +0100 Subject: [PATCH] Build libpq dependency using vcpkg --- .gitignore | 5 +- CMakeLists.txt | 224 ++-------- vcpkg.json | 10 +- vcpkg_ports/libpq/Makefile | 54 +++ .../libpq/android/unversioned_so.patch | 16 + vcpkg_ports/libpq/build-msvc.cmake | 80 ++++ .../libpq/include/port/win32/arpa/inet.h | 3 + vcpkg_ports/libpq/include/port/win32/dlfcn.h | 1 + vcpkg_ports/libpq/include/port/win32/grp.h | 1 + vcpkg_ports/libpq/include/port/win32/netdb.h | 7 + .../libpq/include/port/win32/netinet/in.h | 3 + .../libpq/include/port/win32/netinet/tcp.h | 7 + vcpkg_ports/libpq/include/port/win32/pwd.h | 3 + .../libpq/include/port/win32/sys/resource.h | 20 + .../libpq/include/port/win32/sys/select.h | 3 + .../libpq/include/port/win32/sys/socket.h | 34 ++ vcpkg_ports/libpq/include/port/win32/sys/un.h | 17 + .../libpq/include/port/win32/sys/wait.h | 3 + .../libpq/include/port/win32_msvc/dirent.h | 34 ++ .../libpq/include/port/win32_msvc/sys/file.h | 1 + .../libpq/include/port/win32_msvc/sys/param.h | 1 + .../libpq/include/port/win32_msvc/sys/time.h | 1 + .../libpq/include/port/win32_msvc/unistd.h | 9 + .../libpq/include/port/win32_msvc/utime.h | 3 + vcpkg_ports/libpq/libpq.props.in | 25 ++ vcpkg_ports/libpq/portfile.cmake | 158 +++++++ vcpkg_ports/libpq/unix/fix-configure.patch | 79 ++++ vcpkg_ports/libpq/unix/installdirs.patch | 48 +++ vcpkg_ports/libpq/unix/mingw-install.patch | 36 ++ vcpkg_ports/libpq/unix/no-server-tools.patch | 37 ++ vcpkg_ports/libpq/unix/python.patch | 35 ++ vcpkg_ports/libpq/unix/single-linkage.patch | 56 +++ vcpkg_ports/libpq/usage | 4 + vcpkg_ports/libpq/vcpkg-cmake-wrapper.cmake | 69 +++ vcpkg_ports/libpq/vcpkg-libs.props.in | 31 ++ vcpkg_ports/libpq/vcpkg.json | 194 +++++++++ vcpkg_ports/libpq/windows/macro-def.patch | 18 + vcpkg_ports/libpq/windows/msbuild.patch | 398 ++++++++++++++++++ vcpkg_ports/libpq/windows/spin_delay.patch | 24 ++ vcpkg_ports/libpq/windows/tcl-9.0-alpha.patch | 12 + .../libpq/windows/win_bison_flex.patch | 42 ++ 41 files changed, 1608 insertions(+), 198 deletions(-) create mode 100644 vcpkg_ports/libpq/Makefile create mode 100644 vcpkg_ports/libpq/android/unversioned_so.patch create mode 100644 vcpkg_ports/libpq/build-msvc.cmake create mode 100644 vcpkg_ports/libpq/include/port/win32/arpa/inet.h create mode 100644 vcpkg_ports/libpq/include/port/win32/dlfcn.h create mode 100644 vcpkg_ports/libpq/include/port/win32/grp.h create mode 100644 vcpkg_ports/libpq/include/port/win32/netdb.h create mode 100644 vcpkg_ports/libpq/include/port/win32/netinet/in.h create mode 100644 vcpkg_ports/libpq/include/port/win32/netinet/tcp.h create mode 100644 vcpkg_ports/libpq/include/port/win32/pwd.h create mode 100644 vcpkg_ports/libpq/include/port/win32/sys/resource.h create mode 100644 vcpkg_ports/libpq/include/port/win32/sys/select.h create mode 100644 vcpkg_ports/libpq/include/port/win32/sys/socket.h create mode 100644 vcpkg_ports/libpq/include/port/win32/sys/un.h create mode 100644 vcpkg_ports/libpq/include/port/win32/sys/wait.h create mode 100644 vcpkg_ports/libpq/include/port/win32_msvc/dirent.h create mode 100644 vcpkg_ports/libpq/include/port/win32_msvc/sys/file.h create mode 100644 vcpkg_ports/libpq/include/port/win32_msvc/sys/param.h create mode 100644 vcpkg_ports/libpq/include/port/win32_msvc/sys/time.h create mode 100644 vcpkg_ports/libpq/include/port/win32_msvc/unistd.h create mode 100644 vcpkg_ports/libpq/include/port/win32_msvc/utime.h create mode 100644 vcpkg_ports/libpq/libpq.props.in create mode 100644 vcpkg_ports/libpq/portfile.cmake create mode 100644 vcpkg_ports/libpq/unix/fix-configure.patch create mode 100644 vcpkg_ports/libpq/unix/installdirs.patch create mode 100644 vcpkg_ports/libpq/unix/mingw-install.patch create mode 100644 vcpkg_ports/libpq/unix/no-server-tools.patch create mode 100644 vcpkg_ports/libpq/unix/python.patch create mode 100644 vcpkg_ports/libpq/unix/single-linkage.patch create mode 100644 vcpkg_ports/libpq/usage create mode 100644 vcpkg_ports/libpq/vcpkg-cmake-wrapper.cmake create mode 100644 vcpkg_ports/libpq/vcpkg-libs.props.in create mode 100644 vcpkg_ports/libpq/vcpkg.json create mode 100644 vcpkg_ports/libpq/windows/macro-def.patch create mode 100644 vcpkg_ports/libpq/windows/msbuild.patch create mode 100644 vcpkg_ports/libpq/windows/spin_delay.patch create mode 100644 vcpkg_ports/libpq/windows/tcl-9.0-alpha.patch create mode 100644 vcpkg_ports/libpq/windows/win_bison_flex.patch diff --git a/.gitignore b/.gitignore index 94fc032ae..76c2cc0a0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ build cmake-build-debug .idea .DS_Store -postgres/postgres -postgres \ No newline at end of file +.vscode +.cache +duckdb_unittest_tempdir diff --git a/CMakeLists.txt b/CMakeLists.txt index 951820ff6..034505d50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,213 +2,42 @@ cmake_minimum_required(VERSION 2.8.12...3.29) set(TARGET_NAME postgres_scanner) project(${TARGET_NAME}) -add_definitions(-DFRONTEND=1 -D_GNU_SOURCE=1) -add_definitions(-DUSE_OPENSSL=1 -DHAVE_BIO_GET_DATA=1 -DHAVE_BIO_METH_NEW=1) -set(OPENSSL_USE_STATIC_LIBS TRUE) +add_definitions( + -DFRONTEND=1 + -D_GNU_SOURCE=1 + -DUSE_OPENSSL=1 + -DHAVE_BIO_GET_DATA=1 + -DHAVE_BIO_METH_NEW=1) find_package(OpenSSL REQUIRED) +find_package(PostgreSQL REQUIRED) if(NOT MSVC) - set(POSTGRES_SCANNER_EXTRA_CFLAGS - "-Wno-pedantic -Wno-sign-compare -Wno-unused-variable") + add_compile_options( + -Wno-pedantic + -Wno-sign-compare + -Wno-unused-variable) endif() -set(CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG} ${POSTGRES_SCANNER_EXTRA_CFLAGS}") -set(CMAKE_CXX_FLAGS_RELEASE - "${CMAKE_CXX_FLAGS_RELEASE} ${POSTGRES_SCANNER_EXTRA_CFLAGS}") -set(CMAKE_CXX_FLAGS_RELWITHDEBINFO - "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${POSTGRES_SCANNER_EXTRA_CFLAGS}") - -set(CMAKE_C_FLAGS_DEBUG - "${CMAKE_C_FLAGS_DEBUG} ${POSTGRES_SCANNER_EXTRA_CFLAGS} ${POSTGRES_SCANNER_EXTRA_CFLAGS}" -) -set(CMAKE_C_FLAGS_RELEASE - "${CMAKE_C_FLAGS_RELEASE} ${POSTGRES_SCANNER_EXTRA_CFLAGS}") -set(CMAKE_C_FLAGS_RELWITHDEBINFO - "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${POSTGRES_SCANNER_EXTRA_CFLAGS}") - include_directories( include database-connector/src/include - postgres/src/include postgres/src/backend - postgres/src/interfaces/libpq ${OPENSSL_INCLUDE_DIR}) if(WIN32) - include_directories(postgres/src/include/port/win32 postgres/src/port - postgres/src/include/port/win32_msvc) + include_directories( + vcpkg_ports/libpq/include/port/win32 + vcpkg_ports/libpq/include/port/win32_msvc) endif() -set(LIBPG_SOURCES - postgres/src/common/base64.c - postgres/src/common/cryptohash.c - postgres/src/common/encnames.c - postgres/src/common/hmac.c - postgres/src/common/ip.c - postgres/src/common/link-canary.c - postgres/src/common/md5.c - postgres/src/common/md5_common.c - postgres/src/common/saslprep.c - postgres/src/common/scram-common.c - postgres/src/common/sha1.c - postgres/src/common/sha2.c - postgres/src/common/string.c - postgres/src/common/unicode_norm.c - postgres/src/common/wchar.c - postgres/src/interfaces/libpq/fe-auth-scram.c - postgres/src/interfaces/libpq/fe-auth.c - postgres/src/interfaces/libpq/fe-connect.c - postgres/src/interfaces/libpq/fe-exec.c - postgres/src/interfaces/libpq/fe-lobj.c - postgres/src/interfaces/libpq/fe-misc.c - postgres/src/interfaces/libpq/fe-print.c - postgres/src/interfaces/libpq/fe-protocol3.c - postgres/src/interfaces/libpq/fe-secure.c - postgres/src/interfaces/libpq/fe-trace.c - postgres/src/interfaces/libpq/legacy-pqsignal.c - postgres/src/interfaces/libpq/libpq-events.c - postgres/src/interfaces/libpq/pqexpbuffer.c - postgres/src/interfaces/libpq/fe-secure-openssl.c - postgres/src/interfaces/libpq/fe-secure-common.c - postgres/src/port/chklocale.c - postgres/src/port/explicit_bzero.c - postgres/src/port/inet_net_ntop.c - postgres/src/port/noblock.c - postgres/src/port/pg_strong_random.c - postgres/src/port/pgstrcasecmp.c - postgres/src/port/snprintf.c - postgres/src/port/strerror.c - postgres/src/port/thread.c) - -if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux" OR WIN32) - set(LIBPG_SOURCES ${LIBPG_SOURCES} postgres/src/port/strlcpy.c - postgres/src/port/getpeereid.c) -endif() - -if(WIN32) - set(LIBPG_SOURCES - ${LIBPG_SOURCES} - postgres/src/interfaces/libpq/pthread-win32.c - postgres/src/interfaces/libpq/win32.c - postgres/src/port/getaddrinfo.c - postgres/src/port/gettimeofday.c - postgres/src/port/inet_aton.c - postgres/src/port/open.c - postgres/src/port/pgsleep.c - postgres/src/port/system.c - postgres/src/port/dirmod.c - postgres/src/port/win32common.c - postgres/src/port/win32error.c - postgres/src/port/win32ntdll.c - postgres/src/port/win32setlocale.c - postgres/src/port/win32stat.c) - -endif() - -function(PREPEND var prefix) - set(listVar "") - foreach(f ${ARGN}) - list(APPEND listVar "${prefix}/${f}") - endforeach(f) - set(${var} - "${listVar}" - PARENT_SCOPE) -endfunction(PREPEND) - add_subdirectory(src) -prepend(LIBPG_SOURCES_FULLPATH ${CMAKE_CURRENT_SOURCE_DIR} ${LIBPG_SOURCES}) - -if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/postgres) - - # Download the PostgreSQL source code - message(STATUS "Downloading PostgreSQL source code") - file( - DOWNLOAD - "https://github.com/postgres/postgres/archive/refs/tags/REL_15_13.tar.gz" - ${CMAKE_CURRENT_SOURCE_DIR}/pg.tar.gz - SHOW_PROGRESS - EXPECTED_MD5 106c54e53aca9395354a251eeea914c0 - STATUS PG_DOWNLOAD_RESULT) - - if(NOT PG_DOWNLOAD_RESULT EQUAL 0) - file(REMOVE pg.tar.gz) - message(FATAL_ERROR "Failed to download PostgreSQL source code") - endif() - - # Extract the PostgreSQL source code - message(STATUS "Extracting PostgreSQL source code") - file(ARCHIVE_EXTRACT INPUT ${CMAKE_CURRENT_SOURCE_DIR}/pg.tar.gz DESTINATION - ${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp) - - # Move out of root directory - file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp/postgres-REL_15_13 - ${CMAKE_CURRENT_SOURCE_DIR}/postgres) - - # Remove the tmp directory - file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp) - - # Remove the downloaded tarball - file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/pg.tar.gz) - - # Configure the PostgreSQL source code - message(STATUS "Configuring PostgreSQL source code") - if(WIN32) - # On windows, use the mkvcbuild.pl script to configure the source code - execute_process( - COMMAND perl mkvcbuild.pl - RESULT_VARIABLE PG_MKVCBUILD_RESULT - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/postgres/src/tools/msvc) - - # Check if configuration was successful - if(NOT PG_MKVCBUILD_RESULT EQUAL 0) - file(REMOVE_RECURSE postgres) - message( - FATAL_ERROR "Failed to configure PostgreSQL source code for windows") - endif() - else() - # On other platforms, use the configure script to configure the source code - set(ENV{CC} gcc) - set(ENV{CXX} g++) - execute_process( - COMMAND - ./configure --without-llvm --without-icu --without-tcl --without-perl - --without-python --without-gssapi --without-pam --without-bsd-auth - --without-ldap --without-bonjour --without-selinux --without-systemd - --without-readline --without-libxml --without-libxslt --without-zlib - --without-lz4 --without-openssl - RESULT_VARIABLE PG_CONFIGURE_RESULT - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/postgres) - # Check if configuration was successful - if(NOT PG_CONFIGURE_RESULT EQUAL 0) - file(REMOVE_RECURSE postgres) - message(FATAL_ERROR "Failed to configure PostgreSQL source code") - endif() - endif() - message(STATUS "Finished setting up PostgreSQL source code!") -endif() - set(PARAMETERS "-no-warnings") set(EXTENSION_NAME ${TARGET_NAME}_extension) set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension) -build_static_extension(${TARGET_NAME} ${ALL_OBJECT_FILES} - ${LIBPG_SOURCES_FULLPATH}) -build_loadable_extension(${TARGET_NAME} ${PARAMETERS} ${ALL_OBJECT_FILES} - ${LIBPG_SOURCES_FULLPATH}) - -target_include_directories( - ${LOADABLE_EXTENSION_NAME} - PRIVATE include postgres/src/include postgres/src/backend - postgres/src/interfaces/libpq ${OPENSSL_INCLUDE_DIR}) - -if(WIN32) - target_include_directories( - ${LOADABLE_EXTENSION_NAME} - PRIVATE postgres/src/include/port/win32 postgres/src/port - postgres/src/include/port/win32_msvc) -endif() +build_static_extension(${TARGET_NAME} ${ALL_OBJECT_FILES}) +build_loadable_extension(${TARGET_NAME} ${PARAMETERS} ${ALL_OBJECT_FILES}) # Fix for ELF symbol conflict when loaded inside PostgreSQL backend # Use -Bsymbolic to force the extension to prefer its own symbols over global ones @@ -220,17 +49,24 @@ if(NOT WIN32 AND NOT APPLE) ) endif() -target_link_libraries(${LOADABLE_EXTENSION_NAME} ${OPENSSL_LIBRARIES}) +target_link_libraries(${LOADABLE_EXTENSION_NAME} + OpenSSL::SSL + OpenSSL::Crypto + PostgreSQL::PostgreSQL) set_property(TARGET ${EXTENSION_NAME} PROPERTY C_STANDARD 99) set_property(TARGET ${LOADABLE_EXTENSION_NAME} PROPERTY C_STANDARD 99) if(WIN32) - target_link_libraries(${LOADABLE_EXTENSION_NAME} wsock32 ws2_32 - wldap32 secur32 crypt32) + target_link_libraries(${LOADABLE_EXTENSION_NAME} + wsock32 + ws2_32 + wldap32 + secur32 + crypt32) endif() install( - TARGETS ${EXTENSION_NAME} - EXPORT "${DUCKDB_EXPORT_SET}" - LIBRARY DESTINATION "${INSTALL_LIB_DIR}" - ARCHIVE DESTINATION "${INSTALL_LIB_DIR}") + TARGETS ${EXTENSION_NAME} + EXPORT "${DUCKDB_EXPORT_SET}" + LIBRARY DESTINATION "${INSTALL_LIB_DIR}" + ARCHIVE DESTINATION "${INSTALL_LIB_DIR}") diff --git a/vcpkg.json b/vcpkg.json index 85936bf44..fb16ba635 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,5 +1,11 @@ { "dependencies": [ - "openssl" - ] + "openssl", + "libpq" + ], + "vcpkg-configuration": { + "overlay-ports": [ + "./vcpkg_ports" + ] + } } \ No newline at end of file diff --git a/vcpkg_ports/libpq/Makefile b/vcpkg_ports/libpq/Makefile new file mode 100644 index 000000000..67994f4ba --- /dev/null +++ b/vcpkg_ports/libpq/Makefile @@ -0,0 +1,54 @@ +subdir = . +top_builddir = . +include src/Makefile.global + +ifeq ($(LIBPQ_LIBRARY_TYPE), static) +LIBPQ_INSTALL_LIBS = install-stlib +endif + +ifeq ($(LIBPQ_LIBRARY_TYPE), shared) +ifeq ($(LIBPQ_USING_MINGW), yes) +# The import library name is the same as the static library name +EXTRA_TARGET = install-lib-static +endif +endif + +.PHONY: all +all: + $(MAKE) -C src/include + $(MAKE) -C src/common + $(MAKE) -C src/port + $(MAKE) -C src/interfaces/libpq all-$(LIBPQ_LIBRARY_TYPE)-lib + $(MAKE) -C src/interfaces/ecpg/include + $(MAKE) -C src/interfaces/ecpg/pgtypeslib + $(MAKE) -C src/interfaces/ecpg/ecpglib + $(MAKE) -C src/interfaces/ecpg/compatlib +ifeq ($(LIBPQ_ENABLE_TOOLS), yes) + $(MAKE) -C src/interfaces/ecpg/preproc + $(MAKE) -C src/fe_utils + $(MAKE) -C src/bin +else + $(MAKE) -C src/bin/pg_config +endif + +.PHONY: install-stlib +install-stlib: + $(MAKE) -C src/common install -o all + rm -f '$(DESTDIR)$(libdir)/libpgcommon_shlib.a' + $(MAKE) -C src/port install -o all + rm -f '$(DESTDIR)$(libdir)/libpgport_shlib.a' + +.PHONY: install +install: $(LIBPQ_INSTALL_LIBS) + $(MAKE) -C src/include install + $(MAKE) -C src/interfaces/libpq $(EXTRA_TARGET) install-lib-$(LIBPQ_LIBRARY_TYPE) install-lib-pc install -o all -o install-lib + $(MAKE) -C src/interfaces/ecpg/include install + $(MAKE) -C src/interfaces/ecpg/pgtypeslib install + $(MAKE) -C src/interfaces/ecpg/ecpglib install + $(MAKE) -C src/interfaces/ecpg/compatlib install +ifeq ($(LIBPQ_ENABLE_TOOLS), yes) + $(MAKE) -C src/interfaces/ecpg/preproc install + $(MAKE) -C src/bin install +else + $(MAKE) -C src/bin/pg_config install +endif diff --git a/vcpkg_ports/libpq/android/unversioned_so.patch b/vcpkg_ports/libpq/android/unversioned_so.patch new file mode 100644 index 000000000..42096a367 --- /dev/null +++ b/vcpkg_ports/libpq/android/unversioned_so.patch @@ -0,0 +1,16 @@ +diff --git a/src/Makefile.shlib b/src/Makefile.shlib +index f94d59d1c597..8ca51ca03f75 100644 +--- a/src/Makefile.shlib ++++ b/src/Makefile.shlib +@@ -183,6 +183,11 @@ endif + ifeq ($(PORTNAME), linux) + LINK.shared = $(COMPILER) -shared + ifdef soname ++ ifneq (,$(findstring linux-android,$(host_os))) ++ # Android uses unversioned shared libraries ++ shlib = $(shlib_bare) ++ soname = $(shlib_bare) ++ endif + LINK.shared += -Wl,-soname,$(soname) + endif + BUILD.exports = ( echo '{ global:'; $(AWK) '/^[^\#]/ {printf "%s;\n",$$1}' $<; echo ' local: *; };' ) >$@ diff --git a/vcpkg_ports/libpq/build-msvc.cmake b/vcpkg_ports/libpq/build-msvc.cmake new file mode 100644 index 000000000..34d969487 --- /dev/null +++ b/vcpkg_ports/libpq/build-msvc.cmake @@ -0,0 +1,80 @@ +function(build_msvc build_type source_path) + if(build_type STREQUAL "DEBUG") + set(vcpkg_configuration "Debug") + set(label "${TARGET_TRIPLET}-dbg") + set(packages_dir "${CURRENT_PACKAGES_DIR}/debug") + else() + set(vcpkg_configuration "Release") + set(label "${TARGET_TRIPLET}-rel") + set(packages_dir "${CURRENT_PACKAGES_DIR}") + endif() + + set(build_path "${CURRENT_BUILDTREES_DIR}/${label}") + file(REMOVE_RECURSE "${build_path}") + file(COPY "${source_path}/" DESTINATION "${build_path}") + + if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + vcpkg_replace_string("${build_path}/src/include/port/win32.h" "__declspec (dllimport)" "") + endif() + vcpkg_replace_string("${build_path}/src/tools/msvc/MSBuildProject.pm" "perl " "\"${PERL}\" ") + configure_file("${CURRENT_PORT_DIR}/libpq.props.in" "${build_path}/libpq.props" @ONLY) + configure_file("${CURRENT_PORT_DIR}/vcpkg-libs.props.in" "${build_path}/vcpkg-libs.props" @ONLY) + set(config "# Generated by ${CMAKE_CURRENT_LIST_FILE}\n\n") + foreach(var IN ITEMS VCPKG_TARGET_ARCHITECTURE VCPKG_LIBRARY_LINKAGE VCPKG_CRT_LINKAGE) + string(APPEND config "\$config->{${var}} = \"${${var}}\";\n") + endforeach() + foreach(option IN ITEMS icu lz4 nls openssl python tcl xml xslt zlib zstd) + if(option IN_LIST FEATURES) + string(APPEND config "\$config->{${option}} = \"${CURRENT_INSTALLED_DIR}\";\n") + endif() + endforeach() + if("openssl" IN_LIST FEATURES) + file(STRINGS "${CURRENT_INSTALLED_DIR}/lib/pkgconfig/openssl.pc" OPENSSL_VERSION REGEX "Version:") + string(APPEND config "\$config->{openssl_version} = '${OPENSSL_VERSION}';\n") + endif() + string(APPEND config "\$config->{python_version} = '3.${PYTHON_VERSION_MINOR}';\n") + string(APPEND config "\$config->{tcl_version} = '90';\n") + file(WRITE "${build_path}/src/tools/msvc/config.pl" "${config}") + + set(build_in_parallel "-m") + set(build_targets libpq libecpg_compat) + set(install_target core) + if(HAS_TOOLS AND NOT build_type STREQUAL "DEBUG") + set(build_in_parallel "") # mitigate winflex races + set(build_targets client) + set(install_target client) + endif() + + string(REPLACE "x86" "Win32" platform "${VCPKG_TARGET_ARCHITECTURE}") + vcpkg_get_windows_sdk(VCPKG_TARGET_PLATFORM_VERSION) + set(ENV{MSBFLAGS} "\ + /p:Platform=${platform} \ + /p:PlatformToolset=${VCPKG_PLATFORM_TOOLSET} \ + /p:VCPkgLocalAppDataDisabled=true \ + /p:UseIntelMKL=No \ + /p:WindowsTargetPlatformVersion=${VCPKG_TARGET_PLATFORM_VERSION} \ + /p:VcpkgConfiguration=${vcpkg_configuration} \ + ${build_in_parallel} \ + /p:ForceImportBeforeCppTargets=\"${SCRIPTS}/buildsystems/msbuild/vcpkg.targets;${build_path}/vcpkg-libs.props\" \ + /p:VcpkgTriplet=${TARGET_TRIPLET} \ + /p:VcpkgCurrentInstalledDir=\"${CURRENT_INSTALLED_DIR}\" \ + /p:ForceImportAfterCppTargets=\"${build_path}/libpq.props\" \ + ") + + message(STATUS "Building ${label}") + foreach(target IN LISTS build_targets) + string(REPLACE "client" "" target "${target}") + vcpkg_execute_required_process( + COMMAND "${PERL}" build.pl ${build_type} ${target} + WORKING_DIRECTORY "${build_path}/src/tools/msvc" + LOGNAME "build-${target}-${label}" + ) + endforeach() + + message(STATUS "Installing ${label}") + vcpkg_execute_required_process( + COMMAND "${PERL}" install.pl "${packages_dir}" ${install_target} + WORKING_DIRECTORY "${build_path}/src/tools/msvc" + LOGNAME "install-${label}" + ) +endfunction() diff --git a/vcpkg_ports/libpq/include/port/win32/arpa/inet.h b/vcpkg_ports/libpq/include/port/win32/arpa/inet.h new file mode 100644 index 000000000..ad1803179 --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32/arpa/inet.h @@ -0,0 +1,3 @@ +/* src/include/port/win32/arpa/inet.h */ + +#include diff --git a/vcpkg_ports/libpq/include/port/win32/dlfcn.h b/vcpkg_ports/libpq/include/port/win32/dlfcn.h new file mode 100644 index 000000000..b6e43c091 --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32/dlfcn.h @@ -0,0 +1 @@ +/* src/include/port/win32/dlfcn.h */ diff --git a/vcpkg_ports/libpq/include/port/win32/grp.h b/vcpkg_ports/libpq/include/port/win32/grp.h new file mode 100644 index 000000000..8b4f21310 --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32/grp.h @@ -0,0 +1 @@ +/* src/include/port/win32/grp.h */ diff --git a/vcpkg_ports/libpq/include/port/win32/netdb.h b/vcpkg_ports/libpq/include/port/win32/netdb.h new file mode 100644 index 000000000..9ed13e457 --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32/netdb.h @@ -0,0 +1,7 @@ +/* src/include/port/win32/netdb.h */ +#ifndef WIN32_NETDB_H +#define WIN32_NETDB_H + +#include + +#endif diff --git a/vcpkg_ports/libpq/include/port/win32/netinet/in.h b/vcpkg_ports/libpq/include/port/win32/netinet/in.h new file mode 100644 index 000000000..a4e22f89f --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32/netinet/in.h @@ -0,0 +1,3 @@ +/* src/include/port/win32/netinet/in.h */ + +#include diff --git a/vcpkg_ports/libpq/include/port/win32/netinet/tcp.h b/vcpkg_ports/libpq/include/port/win32/netinet/tcp.h new file mode 100644 index 000000000..1d377b6ad --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32/netinet/tcp.h @@ -0,0 +1,7 @@ +/* src/include/port/win32/netinet/tcp.h */ +#ifndef WIN32_NETINET_TCP_H +#define WIN32_NETINET_TCP_H + +#include + +#endif diff --git a/vcpkg_ports/libpq/include/port/win32/pwd.h b/vcpkg_ports/libpq/include/port/win32/pwd.h new file mode 100644 index 000000000..b8c7178fc --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32/pwd.h @@ -0,0 +1,3 @@ +/* + * src/include/port/win32/pwd.h + */ diff --git a/vcpkg_ports/libpq/include/port/win32/sys/resource.h b/vcpkg_ports/libpq/include/port/win32/sys/resource.h new file mode 100644 index 000000000..a14feeb58 --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32/sys/resource.h @@ -0,0 +1,20 @@ +/* + * Replacement for for Windows. + */ +#ifndef WIN32_SYS_RESOURCE_H +#define WIN32_SYS_RESOURCE_H + +#include /* for struct timeval */ + +#define RUSAGE_SELF 0 +#define RUSAGE_CHILDREN (-1) + +struct rusage +{ + struct timeval ru_utime; /* user time used */ + struct timeval ru_stime; /* system time used */ +}; + +extern int getrusage(int who, struct rusage *rusage); + +#endif /* WIN32_SYS_RESOURCE_H */ diff --git a/vcpkg_ports/libpq/include/port/win32/sys/select.h b/vcpkg_ports/libpq/include/port/win32/sys/select.h new file mode 100644 index 000000000..f8a877acc --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32/sys/select.h @@ -0,0 +1,3 @@ +/* + * src/include/port/win32/sys/select.h + */ diff --git a/vcpkg_ports/libpq/include/port/win32/sys/socket.h b/vcpkg_ports/libpq/include/port/win32/sys/socket.h new file mode 100644 index 000000000..f2b475df5 --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32/sys/socket.h @@ -0,0 +1,34 @@ +/* + * src/include/port/win32/sys/socket.h + */ +#ifndef WIN32_SYS_SOCKET_H +#define WIN32_SYS_SOCKET_H + +/* + * Unfortunately, of VC++ also defines ERROR. + * To avoid the conflict, we include here and undefine ERROR + * immediately. + * + * Note: Don't include directly. It causes compile errors. + */ +#include +#include +#include + +#undef ERROR +#undef small + +/* Restore old ERROR value */ +#ifdef PGERROR +#define ERROR PGERROR +#endif + +/* + * We don't use the Windows gai_strerror[A] function because it is not + * thread-safe. We define our own in src/port/win32gai_strerror.c. + */ +#undef gai_strerror + +extern const char *gai_strerror(int ecode); + +#endif /* WIN32_SYS_SOCKET_H */ diff --git a/vcpkg_ports/libpq/include/port/win32/sys/un.h b/vcpkg_ports/libpq/include/port/win32/sys/un.h new file mode 100644 index 000000000..4fc13a23f --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32/sys/un.h @@ -0,0 +1,17 @@ +/* + * src/include/port/win32/sys/un.h + */ +#ifndef WIN32_SYS_UN_H +#define WIN32_SYS_UN_H + +/* + * Windows defines this structure in , but not all tool chains have + * the header yet, so we define it here for now. + */ +struct sockaddr_un +{ + unsigned short sun_family; + char sun_path[108]; +}; + +#endif diff --git a/vcpkg_ports/libpq/include/port/win32/sys/wait.h b/vcpkg_ports/libpq/include/port/win32/sys/wait.h new file mode 100644 index 000000000..eaeb5661c --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32/sys/wait.h @@ -0,0 +1,3 @@ +/* + * src/include/port/win32/sys/wait.h + */ diff --git a/vcpkg_ports/libpq/include/port/win32_msvc/dirent.h b/vcpkg_ports/libpq/include/port/win32_msvc/dirent.h new file mode 100644 index 000000000..62799db00 --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32_msvc/dirent.h @@ -0,0 +1,34 @@ +/* + * Headers for port/dirent.c, win32 native implementation of dirent functions + * + * src/include/port/win32_msvc/dirent.h + */ + +#ifndef _WIN32VC_DIRENT_H +#define _WIN32VC_DIRENT_H +struct dirent +{ + long d_ino; + unsigned short d_reclen; + unsigned char d_type; + unsigned short d_namlen; + char d_name[MAX_PATH]; +}; + +typedef struct DIR DIR; + +DIR *opendir(const char *); +struct dirent *readdir(DIR *); +int closedir(DIR *); + +/* File types for 'd_type'. */ +#define DT_UNKNOWN 0 +#define DT_FIFO 1 +#define DT_CHR 2 +#define DT_DIR 4 +#define DT_BLK 6 +#define DT_REG 8 +#define DT_LNK 10 +#define DT_SOCK 12 +#define DT_WHT 14 +#endif diff --git a/vcpkg_ports/libpq/include/port/win32_msvc/sys/file.h b/vcpkg_ports/libpq/include/port/win32_msvc/sys/file.h new file mode 100644 index 000000000..76be3e777 --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32_msvc/sys/file.h @@ -0,0 +1 @@ +/* src/include/port/win32_msvc/sys/file.h */ diff --git a/vcpkg_ports/libpq/include/port/win32_msvc/sys/param.h b/vcpkg_ports/libpq/include/port/win32_msvc/sys/param.h new file mode 100644 index 000000000..160df3b25 --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32_msvc/sys/param.h @@ -0,0 +1 @@ +/* src/include/port/win32_msvc/sys/param.h */ diff --git a/vcpkg_ports/libpq/include/port/win32_msvc/sys/time.h b/vcpkg_ports/libpq/include/port/win32_msvc/sys/time.h new file mode 100644 index 000000000..9d943ecc6 --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32_msvc/sys/time.h @@ -0,0 +1 @@ +/* src/include/port/win32_msvc/sys/time.h */ diff --git a/vcpkg_ports/libpq/include/port/win32_msvc/unistd.h b/vcpkg_ports/libpq/include/port/win32_msvc/unistd.h new file mode 100644 index 000000000..b7795ba03 --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32_msvc/unistd.h @@ -0,0 +1,9 @@ +/* src/include/port/win32_msvc/unistd.h */ + +/* + * MSVC does not define these, nor does _fileno(stdin) etc reliably work + * (returns -1 if stdin/out/err are closed). + */ +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 diff --git a/vcpkg_ports/libpq/include/port/win32_msvc/utime.h b/vcpkg_ports/libpq/include/port/win32_msvc/utime.h new file mode 100644 index 000000000..c78e79c33 --- /dev/null +++ b/vcpkg_ports/libpq/include/port/win32_msvc/utime.h @@ -0,0 +1,3 @@ +/* src/include/port/win32_msvc/utime.h */ + +#include /* for non-unicode version */ diff --git a/vcpkg_ports/libpq/libpq.props.in b/vcpkg_ports/libpq/libpq.props.in new file mode 100644 index 000000000..223e528fe --- /dev/null +++ b/vcpkg_ports/libpq/libpq.props.in @@ -0,0 +1,25 @@ + + + + + %(AdditionalOptions) @VCPKG_COMBINED_C_FLAGS_DEBUG@ + + + %(AdditionalOptions) @VCPKG_COMBINED_SHARED_LINKER_FLAGS_DEBUG@ + + + %(AdditionalOptions) @VCPKG_COMBINED_STATIC_LINKER_FLAGS_DEBUG@ + + + + + %(AdditionalOptions) @VCPKG_COMBINED_C_FLAGS_RELEASE@ + + + %(AdditionalOptions) @VCPKG_COMBINED_SHARED_LINKER_FLAGS_RELEASE@ + + + %(AdditionalOptions) @VCPKG_COMBINED_STATIC_LINKER_FLAGS_RELEASE@ + + + diff --git a/vcpkg_ports/libpq/portfile.cmake b/vcpkg_ports/libpq/portfile.cmake new file mode 100644 index 000000000..63217f607 --- /dev/null +++ b/vcpkg_ports/libpq/portfile.cmake @@ -0,0 +1,158 @@ +vcpkg_download_distfile(ARCHIVE + URLS "https://ftp.postgresql.org/pub/source/v${VERSION}/postgresql-${VERSION}.tar.bz2" + "https://www.mirrorservice.org/sites/ftp.postgresql.org/source/v${VERSION}/postgresql-${VERSION}.tar.bz2" + FILENAME "postgresql-${VERSION}.tar.bz2" + SHA512 23a3d983c5be49c3daabbbde35db2920bd2e2ba8d9baba805e7908da1f43153ff438c76c253ea8ee8ac6f8a9313fbf0348a1e9b45ef530c5e156fee0daceb814 +) + +vcpkg_extract_source_archive( + SOURCE_PATH + ARCHIVE "${ARCHIVE}" + PATCHES + unix/installdirs.patch + unix/fix-configure.patch + unix/single-linkage.patch + unix/no-server-tools.patch + unix/mingw-install.patch + unix/python.patch + windows/macro-def.patch + windows/win_bison_flex.patch + windows/msbuild.patch + windows/spin_delay.patch + windows/tcl-9.0-alpha.patch + android/unversioned_so.patch +) + +file(GLOB _py3_include_path "${CURRENT_HOST_INSTALLED_DIR}/include/python3*") +string(REGEX MATCH "python3\\.([0-9]+)" _python_version_tmp "${_py3_include_path}") +set(PYTHON_VERSION_MINOR "${CMAKE_MATCH_1}") + +if("client" IN_LIST FEATURES) + set(HAS_TOOLS TRUE) +else() + set(HAS_TOOLS FALSE) +endif() + +vcpkg_cmake_get_vars(cmake_vars_file) +include("${cmake_vars_file}") + +set(required_programs BISON FLEX) +if(VCPKG_DETECTED_MSVC OR NOT VCPKG_HOST_IS_WINDOWS) + list(APPEND required_programs PERL) +endif() +foreach(program_name IN LISTS required_programs) + vcpkg_find_acquire_program(${program_name}) + get_filename_component(program_dir ${${program_name}} DIRECTORY) + vcpkg_add_to_path(PREPEND "${program_dir}") +endforeach() + +if(VCPKG_DETECTED_MSVC) + if("xml" IN_LIST FEATURES) + x_vcpkg_pkgconfig_get_modules( + PREFIX PC_LIBXML2 + MODULES --msvc-syntax libxml-2.0 + LIBS + ) + separate_arguments(LIBXML2_LIBS_DEBUG NATIVE_COMMAND "${PC_LIBXML2_LIBS_DEBUG}") + separate_arguments(LIBXML2_LIBS_RELEASE NATIVE_COMMAND "${PC_LIBXML2_LIBS_RELEASE}") + endif() + if("xslt" IN_LIST FEATURES) + x_vcpkg_pkgconfig_get_modules( + PREFIX PC_LIBXSLT + MODULES --msvc-syntax libxslt + LIBS + ) + separate_arguments(LIBXSLT_LIBS_DEBUG NATIVE_COMMAND "${PC_LIBXSLT_LIBS_DEBUG}") + separate_arguments(LIBXSLT_LIBS_RELEASE NATIVE_COMMAND "${PC_LIBXSLT_LIBS_RELEASE}") + endif() + + include("${CMAKE_CURRENT_LIST_DIR}/build-msvc.cmake") + if(NOT VCPKG_BUILD_TYPE) + build_msvc(DEBUG "${SOURCE_PATH}") + endif() + build_msvc(RELEASE "${SOURCE_PATH}") + + if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin") + endif() + + if(HAS_TOOLS) + vcpkg_copy_tool_dependencies("${CURRENT_PACKAGES_DIR}/tools/${PORT}") + else() + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/tools") + endif() +else() + file(COPY "${CMAKE_CURRENT_LIST_DIR}/Makefile" DESTINATION "${SOURCE_PATH}") + + vcpkg_list(SET BUILD_OPTS) + foreach(option IN ITEMS icu lz4 nls openssl readline xml xslt zlib zstd) + if(option IN_LIST FEATURES) + list(APPEND BUILD_OPTS --with-${option}) + else() + list(APPEND BUILD_OPTS --without-${option}) + endif() + endforeach() + if("nls" IN_LIST FEATURES) + set(ENV{MSGFMT} "${CURRENT_HOST_INSTALLED_DIR}/tools/gettext/bin/msgfmt${VCPKG_HOST_EXECUTABLE_SUFFIX}") + endif() + if("python" IN_LIST FEATURES) + list(APPEND BUILD_OPTS --with-python=3.${PYTHON_VERSION_MINOR}) + vcpkg_find_acquire_program(PYTHON3) + list(APPEND BUILD_OPTS "PYTHON=${PYTHON3}") + endif() + if(VCPKG_TARGET_IS_ANDROID AND (NOT VCPKG_CMAKE_SYSTEM_VERSION OR VCPKG_CMAKE_SYSTEM_VERSION LESS "26")) + list(APPEND BUILD_OPTS ac_cv_header_langinfo_h=no) + endif() + if(VCPKG_DETECTED_CMAKE_OSX_SYSROOT) + list(APPEND BUILD_OPTS "PG_SYSROOT=${VCPKG_DETECTED_CMAKE_OSX_SYSROOT}") + endif() + vcpkg_configure_make( + SOURCE_PATH "${SOURCE_PATH}" + COPY_SOURCE + AUTOCONFIG + ADDITIONAL_MSYS_PACKAGES autoconf-archive + DIRECT_PACKAGES + "https://mirror.msys2.org/msys/x86_64/tzcode-2025b-1-x86_64.pkg.tar.zst" + 824779e3ac4857bb21cbdc92fa881fa24bf89dfa8bc2f9ca816e9a9837a6d963805e8e0991499c43337a134552215fdee50010e643ddc8bd699170433a4c83de + OPTIONS + ${BUILD_OPTS} + OPTIONS_DEBUG + --enable-debug + ) + + if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic") + set(ENV{LIBPQ_LIBRARY_TYPE} shared) + else() + set(ENV{LIBPQ_LIBRARY_TYPE} static) + endif() + if(VCPKG_TARGET_IS_MINGW) + set(ENV{LIBPQ_USING_MINGW} yes) + endif() + if(HAS_TOOLS) + set(ENV{LIBPQ_ENABLE_TOOLS} yes) + endif() + + # https://stackoverflow.com/a/76688525 + set(ENV{MAKELEVEL} 0) + + vcpkg_install_make() + + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/postgresql/server/pg_config.h" "#define CONFIGURE_ARGS" "// #define CONFIGURE_ARGS") + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/pg_config.h" "#define CONFIGURE_ARGS" "// #define CONFIGURE_ARGS") +endif() + +vcpkg_fixup_pkgconfig() +configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake" "${CURRENT_PACKAGES_DIR}/share/postgresql/vcpkg-cmake-wrapper.cmake" @ONLY) + +file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/doc" + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" + "${CURRENT_PACKAGES_DIR}/debug/symbols" + "${CURRENT_PACKAGES_DIR}/debug/tools" + "${CURRENT_PACKAGES_DIR}/symbols" + "${CURRENT_PACKAGES_DIR}/tools/${PORT}/debug" +) + +file(INSTALL "${CURRENT_PORT_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYRIGHT") diff --git a/vcpkg_ports/libpq/unix/fix-configure.patch b/vcpkg_ports/libpq/unix/fix-configure.patch new file mode 100644 index 000000000..34ceb36bc --- /dev/null +++ b/vcpkg_ports/libpq/unix/fix-configure.patch @@ -0,0 +1,79 @@ +diff --git a/configure.ac b/configure.ac +index 7f97248..48ff1a1 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -19,7 +19,8 @@ m4_pattern_forbid(^PGAC_)dnl to catch undefined macros + + AC_INIT([PostgreSQL], [16.9], [pgsql-bugs@lists.postgresql.org], [], [https://www.postgresql.org/]) + +-m4_if(m4_defn([m4_PACKAGE_VERSION]), [2.69], [], [m4_fatal([Autoconf version 2.69 is required. ++cross_compiling=yes # Avoid conftest loading shared objects ++m4_if(m4_defn([m4_PACKAGE_VERSION]), [2.69], [], [m4_warn([unsupported],[Autoconf version 2.69 is required. + Untested combinations of 'autoconf' and PostgreSQL versions are not + recommended. You can remove the check from 'configure.ac' but it is then + your responsibility whether the result works or not.])]) +@@ -1311,7 +1312,8 @@ if test "$enable_thread_safety" = yes; then + fi + + if test "$with_readline" = yes; then +- PGAC_CHECK_READLINE ++ PKG_CHECK_MODULES([READLINE], [readline], [HAVE_LIBREADLINE=1], [pgac_cv_check_readline=no]) ++ LIBS="$READLINE_LIBS $LIBS" + if test x"$pgac_cv_check_readline" = x"no"; then + AC_MSG_ERROR([readline library not found + If you have readline already installed, see config.log for details on the +@@ -1321,7 +1323,7 @@ Use --without-readline to disable readline support.]) + fi + + if test "$with_zlib" = yes; then +- AC_CHECK_LIB(z, inflate, [], ++ PKG_CHECK_MODULES([ZLIB], [zlib], [LIBS="$ZLIB_LIBS $LIBS"], + [AC_MSG_ERROR([zlib library not found + If you have zlib already installed, see config.log for details on the + failure. It is possible the compiler isn't looking in the proper directory. +@@ -1370,6 +1372,9 @@ if test "$with_ssl" = openssl ; then + # Minimum required OpenSSL version is 1.0.1 + AC_DEFINE(OPENSSL_API_COMPAT, [0x10001000L], + [Define to the OpenSSL API version in use. This avoids deprecation warnings from newer OpenSSL versions.]) ++ PKG_CHECK_MODULES([CRYPTO_new_ex_data], [libcrypto], [LIBS="$CRYPTO_new_ex_data_LIBS $LIBS"], [AC_MSG_ERROR([library 'crypto' is required for OpenSSL])]) ++ PKG_CHECK_MODULES([SSL_new], [libssl], [LIBS="$SSL_new_LIBS $LIBS"], [AC_MSG_ERROR([library 'ssl' is required for OpenSSL])]) ++ if false ; then + if test "$PORTNAME" != "win32"; then + AC_CHECK_LIB(crypto, CRYPTO_new_ex_data, [], [AC_MSG_ERROR([library 'crypto' is required for OpenSSL])]) + AC_CHECK_LIB(ssl, SSL_new, [], [AC_MSG_ERROR([library 'ssl' is required for OpenSSL])]) +@@ -1377,6 +1382,7 @@ if test "$with_ssl" = openssl ; then + AC_SEARCH_LIBS(CRYPTO_new_ex_data, [eay32 crypto], [], [AC_MSG_ERROR([library 'eay32' or 'crypto' is required for OpenSSL])]) + AC_SEARCH_LIBS(SSL_new, [ssleay32 ssl], [], [AC_MSG_ERROR([library 'ssleay32' or 'ssl' is required for OpenSSL])]) + fi ++ fi + # Functions introduced in OpenSSL 1.0.2. LibreSSL does not have + # SSL_CTX_set_cert_cb(). + AC_CHECK_FUNCS([X509_get_signature_nid SSL_CTX_set_cert_cb]) +@@ -1403,19 +1409,23 @@ if test "$with_pam" = yes ; then + fi + + if test "$with_libxml" = yes ; then +- AC_CHECK_LIB(xml2, xmlSaveToBuffer, [], [AC_MSG_ERROR([library 'xml2' (version >= 2.6.23) is required for XML support])]) ++ PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.23], [AC_DEFINE(HAVE_LIBXML2,1,[Define to 1 if with xml2])], [AC_MSG_ERROR([library 'xml2' (version >= 2.6.23) is required for XML support])]) ++ LIBS="$LIBXML2_LIBS $LIBS" + fi + + if test "$with_libxslt" = yes ; then +- AC_CHECK_LIB(xslt, xsltCleanupGlobals, [], [AC_MSG_ERROR([library 'xslt' is required for XSLT support])]) ++ PKG_CHECK_MODULES([LIBXSLT], [libxslt], [AC_DEFINE(HAVE_LIBXSLT,1,[Define to 1 if with xslt])], [AC_MSG_ERROR([library 'xslt' is required for XSLT support])]) ++ LIBS="$LIBXSLT_LIBS $LIBS" + fi + + if test "$with_lz4" = yes ; then +- AC_CHECK_LIB(lz4, LZ4_compress_default, [], [AC_MSG_ERROR([library 'lz4' is required for LZ4 support])]) ++ PKG_CHECK_MODULES([LZ4], [liblz4], [AC_DEFINE(HAVE_LIBLZ4,1,[Define to 1 if with lz4])], [AC_MSG_ERROR([library 'lz4' is required for LZ4 support])]) ++ LIBS="$LZ4_LIBS $LIBS" + fi + + if test "$with_zstd" = yes ; then +- AC_CHECK_LIB(zstd, ZSTD_compress, [], [AC_MSG_ERROR([library 'zstd' is required for ZSTD support])]) ++ PKG_CHECK_MODULES([ZSTD], [libzstd], [AC_DEFINE(HAVE_LIBZSTD,1,[Define to 1 if with zstd])], [AC_MSG_ERROR([library 'zstd' is required for ZSTD support])]) ++ LIBS="$ZSTD_LIBS $LIBS" + fi + + # Note: We can test for libldap_r only after we know PTHREAD_LIBS; diff --git a/vcpkg_ports/libpq/unix/installdirs.patch b/vcpkg_ports/libpq/unix/installdirs.patch new file mode 100644 index 000000000..ae6653f90 --- /dev/null +++ b/vcpkg_ports/libpq/unix/installdirs.patch @@ -0,0 +1,48 @@ +diff --git a/src/Makefile.global.in b/src/Makefile.global.in +index 5dacc4d..a9a797e 100644 +--- a/src/Makefile.global.in ++++ b/src/Makefile.global.in +@@ -100,14 +100,14 @@ datarootdir := @datarootdir@ + + bindir := @bindir@ + +-datadir := @datadir@ ++datadir := @datadir@/postgresql + ifeq "$(findstring pgsql, $(datadir))" "" + ifeq "$(findstring postgres, $(datadir))" "" + override datadir := $(datadir)/postgresql + endif + endif + +-sysconfdir := @sysconfdir@ ++sysconfdir := @sysconfdir@/postgresql + ifeq "$(findstring pgsql, $(sysconfdir))" "" + ifeq "$(findstring postgres, $(sysconfdir))" "" + override sysconfdir := $(sysconfdir)/postgresql +@@ -116,7 +116,7 @@ endif + + libdir := @libdir@ + +-pkglibdir = $(libdir) ++pkglibdir = $(libdir)/postgresql + ifeq "$(findstring pgsql, $(pkglibdir))" "" + ifeq "$(findstring postgres, $(pkglibdir))" "" + override pkglibdir := $(pkglibdir)/postgresql +@@ -125,7 +125,7 @@ endif + + includedir := @includedir@ + +-pkgincludedir = $(includedir) ++pkgincludedir = $(includedir)/postgresql + ifeq "$(findstring pgsql, $(pkgincludedir))" "" + ifeq "$(findstring postgres, $(pkgincludedir))" "" + override pkgincludedir := $(pkgincludedir)/postgresql +@@ -134,7 +134,7 @@ endif + + mandir := @mandir@ + +-docdir := @docdir@ ++docdir := @docdir@/postgresql + ifeq "$(findstring pgsql, $(docdir))" "" + ifeq "$(findstring postgres, $(docdir))" "" + override docdir := $(docdir)/postgresql diff --git a/vcpkg_ports/libpq/unix/mingw-install.patch b/vcpkg_ports/libpq/unix/mingw-install.patch new file mode 100644 index 000000000..ffeea023c --- /dev/null +++ b/vcpkg_ports/libpq/unix/mingw-install.patch @@ -0,0 +1,36 @@ +diff --git a/src/Makefile.shlib b/src/Makefile.shlib +index 16255d7..51e9ed2 100644 +--- a/src/Makefile.shlib ++++ b/src/Makefile.shlib +@@ -85,7 +85,11 @@ else + # Naming convention for dynamically loadable modules + shlib = $(NAME)$(DLSUFFIX) + endif ++ifeq ($(PORTNAME)-$(LIBPQ_LIBRARY_TYPE), win32-shared) ++stlib = lib$(NAME).dll.a ++else + stlib = lib$(NAME).a ++endif + + ifndef soname + # additional flags for backend modules +@@ -468,6 +472,9 @@ endif + else # no soname + $(INSTALL_SHLIB) $< '$(DESTDIR)$(pkglibdir)/$(shlib)' + endif ++ifeq ($(PORTNAME)-$(LIBPQ_LIBRARY_TYPE), win32-shared) ++ mv '$(DESTDIR)$(libdir)/$(shlib)' '$(DESTDIR)$(libdir)/../bin/$(shlib)' ++endif + + + installdirs-lib: +@@ -476,6 +483,9 @@ ifdef soname + else + $(MKDIR_P) '$(DESTDIR)$(pkglibdir)' + endif ++ifeq ($(PORTNAME)-$(LIBPQ_LIBRARY_TYPE), win32-shared) ++ $(MKDIR_P) '$(DESTDIR)$(libdir)/../bin' ++endif + + + ## diff --git a/vcpkg_ports/libpq/unix/no-server-tools.patch b/vcpkg_ports/libpq/unix/no-server-tools.patch new file mode 100644 index 000000000..f83682afb --- /dev/null +++ b/vcpkg_ports/libpq/unix/no-server-tools.patch @@ -0,0 +1,37 @@ +diff --git a/src/bin/Makefile b/src/bin/Makefile +index 7f9dde9..bc6d835 100644 +--- a/src/bin/Makefile ++++ b/src/bin/Makefile +@@ -13,29 +13,20 @@ subdir = src/bin + top_builddir = ../.. + include $(top_builddir)/src/Makefile.global + ++.NOTPARALLEL: ++# incl. https://www.postgresql.org/docs/current/reference-client.html ++# excl. https://www.postgresql.org/docs/current/reference-server.html + SUBDIRS = \ +- initdb \ + pg_amcheck \ +- pg_archivecleanup \ + pg_basebackup \ +- pg_checksums \ + pg_config \ +- pg_controldata \ +- pg_ctl \ + pg_dump \ +- pg_resetwal \ +- pg_rewind \ +- pg_test_fsync \ +- pg_test_timing \ +- pg_upgrade \ + pg_verifybackup \ +- pg_waldump \ + pgbench \ + psql \ + scripts + + ifeq ($(PORTNAME), win32) +-SUBDIRS += pgevent + else + ALWAYS_SUBDIRS += pgevent + endif diff --git a/vcpkg_ports/libpq/unix/python.patch b/vcpkg_ports/libpq/unix/python.patch new file mode 100644 index 000000000..7d8f58d4a --- /dev/null +++ b/vcpkg_ports/libpq/unix/python.patch @@ -0,0 +1,35 @@ +diff --git a/configure.ac b/configure.ac +index 7f97248992..33b6c84fc4 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -891,7 +891,9 @@ AC_SUBST(with_perl) + # Optionally build Python modules (PL/Python) + # + AC_MSG_CHECKING([whether to build Python modules]) +-PGAC_ARG_BOOL(with, python, no, [build Python modules (PL/Python)]) ++PGAC_ARG_OPTARG(with, python, [PYTHON_VERSION], [build Python modules (PL/Python)], ++ [], ++ [python_version=$withval]) + AC_MSG_RESULT([$with_python]) + AC_SUBST(with_python) + +@@ -1214,7 +1216,18 @@ fi + + if test "$with_python" = yes; then + PGAC_PATH_PYTHON +- PGAC_CHECK_PYTHON_EMBED_SETUP ++ python_majorversion=3 ++ PKG_CHECK_MODULES(PYTHON_EMBED, python-${python_version}-embed) ++ python_includespec="${PYTHON_EMBED_CFLAGS}" ++ python_libdir=[$(echo " ${PYTHON_EMBED_LIBS}" | sed -e 's/\( -L[^ ]*\).*/\1/' -e 's/^.* -L//')] ++ python_libspec="${PYTHON_EMBED_LIBS}" ++ python_additional_libs="" ++ AC_SUBST(python_majorversion) ++ AC_SUBST(python_version) ++ AC_SUBST(python_includespec) ++ AC_SUBST(python_libdir) ++ AC_SUBST(python_libspec) ++ AC_SUBST(python_additional_libs) + fi + + if test x"$cross_compiling" = x"yes" && test -z "$with_system_tzdata"; then diff --git a/vcpkg_ports/libpq/unix/single-linkage.patch b/vcpkg_ports/libpq/unix/single-linkage.patch new file mode 100644 index 000000000..dd149c7d3 --- /dev/null +++ b/vcpkg_ports/libpq/unix/single-linkage.patch @@ -0,0 +1,56 @@ +diff --git a/src/Makefile.shlib b/src/Makefile.shlib +index 551023c..16255d7 100644 +--- a/src/Makefile.shlib ++++ b/src/Makefile.shlib +@@ -260,10 +260,14 @@ endif + + .PHONY: all-lib all-static-lib all-shared-lib + ++ifndef LIBPQ_LIBRARY_TYPE + all-lib: all-shared-lib + ifdef soname + # no static library when building a dynamically loadable module + all-lib: all-static-lib ++endif ++else ++all-lib: all-$(LIBPQ_LIBRARY_TYPE)-lib + all-lib: lib$(NAME).pc + endif + +@@ -417,9 +421,13 @@ endif # PORTNAME == cygwin || PORTNAME == win32 + ## + + .PHONY: install-lib install-lib-static install-lib-shared installdirs-lib ++ifndef LIBPQ_LIBRARY_TYPE + install-lib: install-lib-shared + ifdef soname + install-lib: install-lib-static ++endif ++else ++install-lib: install-lib-$(LIBPQ_LIBRARY_TYPE) + install-lib: install-lib-pc + endif + +diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile +index 8abdb09..185461e 100644 +--- a/src/interfaces/libpq/Makefile ++++ b/src/interfaces/libpq/Makefile +@@ -115,6 +115,7 @@ backend_src = $(top_srcdir)/src/backend + # Also skip the test on platforms where libpq infrastructure may be provided + # by statically-linked libraries, as we can't expect them to honor this + # coding rule. ++ifeq ($(LIBPQ_LIBRARY_TYPE), shared) + libpq-refs-stamp: $(shlib) + ifneq ($(enable_coverage), yes) + ifeq (,$(filter aix solaris,$(PORTNAME))) +@@ -124,6 +125,10 @@ ifeq (,$(filter aix solaris,$(PORTNAME))) + endif + endif + touch $@ ++else ++.PHONY: libpq-refs-stamp ++libpq-refs-stamp: ++endif + + # Make dependencies on pg_config_paths.h visible in all builds. + fe-connect.o: fe-connect.c $(top_builddir)/src/port/pg_config_paths.h diff --git a/vcpkg_ports/libpq/usage b/vcpkg_ports/libpq/usage new file mode 100644 index 000000000..8dfcd2754 --- /dev/null +++ b/vcpkg_ports/libpq/usage @@ -0,0 +1,4 @@ +The package libpq provides CMake integration: + + find_package(PostgreSQL REQUIRED) + target_link_libraries(main PRIVATE PostgreSQL::PostgreSQL) diff --git a/vcpkg_ports/libpq/vcpkg-cmake-wrapper.cmake b/vcpkg_ports/libpq/vcpkg-cmake-wrapper.cmake new file mode 100644 index 000000000..fa7d3b56e --- /dev/null +++ b/vcpkg_ports/libpq/vcpkg-cmake-wrapper.cmake @@ -0,0 +1,69 @@ +find_library(PostgreSQL_LIBRARY_RELEASE NAMES pq libpq NAMES_PER_DIR PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib" NO_DEFAULT_PATH REQUIRED) +find_library(PostgreSQL_LIBRARY_DEBUG NAMES pq libpq NAMES_PER_DIR PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib" NO_DEFAULT_PATH) +_find_package(${ARGS}) +if(PostgreSQL_FOUND AND NOT "@VCPKG_TARGET_IS_WINDOWS@") + find_library(PostgreSQL_DL_LIBRARY NAMES dl) + if(PostgreSQL_DL_LIBRARY) + list(APPEND PostgreSQL_LIBRARIES "dl") + if(TARGET PostgreSQL::PostgreSQL) + set_property(TARGET PostgreSQL::PostgreSQL APPEND PROPERTY INTERFACE_LINK_LIBRARIES "dl") + endif() + endif() +endif() +if(PostgreSQL_FOUND AND "@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static") + include(SelectLibraryConfigurations) + foreach(LIB_ITEM pgport pgcommon) + find_library(PostgreSQL_${LIB_ITEM}_LIBRARY_RELEASE + NAMES ${LIB_ITEM} lib${LIB_ITEM} + NAMES_PER_DIR + PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib" NO_DEFAULT_PATH + ) + if(TARGET PostgreSQL::PostgreSQL AND PostgreSQL_${LIB_ITEM}_LIBRARY_RELEASE) + set_property( + TARGET PostgreSQL::PostgreSQL + APPEND PROPERTY INTERFACE_LINK_LIBRARIES "\$<\$>:${PostgreSQL_${LIB_ITEM}_LIBRARY_RELEASE}>" + ) + endif() + + find_library(PostgreSQL_${LIB_ITEM}_LIBRARY_DEBUG + NAMES ${LIB_ITEM} lib${LIB_ITEM} + NAMES_PER_DIR + PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib" NO_DEFAULT_PATH + ) + if(TARGET PostgreSQL::PostgreSQL AND PostgreSQL_${LIB_ITEM}_LIBRARY_DEBUG) + set_property( + TARGET PostgreSQL::PostgreSQL + APPEND PROPERTY INTERFACE_LINK_LIBRARIES "\$<\$:${PostgreSQL_${LIB_ITEM}_LIBRARY_DEBUG}>" + ) + endif() + + if (PostgreSQL_${LIB_ITEM}_LIBRARY_RELEASE OR PostgreSQL_${LIB_ITEM}_LIBRARY_DEBUG) + select_library_configurations(PostgreSQL_${LIB_ITEM}) + list(APPEND PostgreSQL_LIBRARIES ${PostgreSQL_${LIB_ITEM}_LIBRARY}) + endif() + endforeach() + if(WIN32) + if(TARGET PostgreSQL::PostgreSQL) + set_property(TARGET PostgreSQL::PostgreSQL APPEND PROPERTY INTERFACE_LINK_LIBRARIES "Secur32.lib") + endif() + list(APPEND PostgreSQL_LIBRARIES Secur32.lib) + endif() + cmake_policy(PUSH) + cmake_policy(SET CMP0057 NEW) + set(Z_VCPKG_PORT_FEATURES "@FEATURES@") + if("openssl" IN_LIST Z_VCPKG_PORT_FEATURES) + find_package(OpenSSL REQUIRED) + if(TARGET PostgreSQL::PostgreSQL) + set_property(TARGET PostgreSQL::PostgreSQL APPEND PROPERTY INTERFACE_LINK_LIBRARIES "OpenSSL::SSL") + endif() + list(APPEND PostgreSQL_LIBRARIES OpenSSL::SSL) + endif() + if(WIN32) + if(TARGET PostgreSQL::PostgreSQL) + set_property(TARGET PostgreSQL::PostgreSQL APPEND PROPERTY INTERFACE_LINK_LIBRARIES "Wldap32.lib") + endif() + list(APPEND PostgreSQL_LIBRARIES Wldap32.lib) + endif() + unset(Z_VCPKG_PORT_FEATURES) + cmake_policy(POP) +endif() diff --git a/vcpkg_ports/libpq/vcpkg-libs.props.in b/vcpkg_ports/libpq/vcpkg-libs.props.in new file mode 100644 index 000000000..cb7e5f92c --- /dev/null +++ b/vcpkg_ports/libpq/vcpkg-libs.props.in @@ -0,0 +1,31 @@ + + + + @CURRENT_INSTALLED_DIR@/debug/lib/icuind.lib;@CURRENT_INSTALLED_DIR@/debug/lib/icuucd.lib;@CURRENT_INSTALLED_DIR@/debug/lib/icudtd.lib; + @CURRENT_INSTALLED_DIR@/debug/lib/lz4d.lib + @CURRENT_INSTALLED_DIR@/debug/lib/intl.lib;@CURRENT_INSTALLED_DIR@/debug/lib/iconv.lib;@CURRENT_INSTALLED_DIR@/debug/lib/charset.lib + @CURRENT_INSTALLED_DIR@/debug/lib/libssl.lib;@CURRENT_INSTALLED_DIR@/debug/lib/libcrypto.lib;crypt32.lib;ws2_32.lib;secur32.lib + @CURRENT_INSTALLED_DIR@/debug/lib/python3@PYTHON_VERSION_MINOR@_d.lib + @CURRENT_INSTALLED_DIR@/debug/lib/tcl90g.lib + @CURRENT_INSTALLED_DIR@/debug/lib/tcl90sg.lib + @CURRENT_INSTALLED_DIR@/debug/lib/tcl90sgx.lib + @LIBXML2_LIBS_DEBUG@ + @LIBXSLT_LIBS_DEBUG@ + @CURRENT_INSTALLED_DIR@/debug/lib/zlibd.lib + @CURRENT_INSTALLED_DIR@/debug/lib/zstd.lib + + + @CURRENT_INSTALLED_DIR@/lib/icuin.lib;@CURRENT_INSTALLED_DIR@/lib/icuuc.lib;@CURRENT_INSTALLED_DIR@/lib/icudt.lib; + @CURRENT_INSTALLED_DIR@/lib/lz4.lib + @CURRENT_INSTALLED_DIR@/lib/intl.lib;@CURRENT_INSTALLED_DIR@/lib/iconv.lib;@CURRENT_INSTALLED_DIR@/lib/charset.lib + @CURRENT_INSTALLED_DIR@/lib/libssl.lib;@CURRENT_INSTALLED_DIR@/lib/libcrypto.lib;crypt32.lib;ws2_32.lib;secur32.lib + @CURRENT_INSTALLED_DIR@/lib/python3@PYTHON_VERSION_MINOR@.lib + @CURRENT_INSTALLED_DIR@/lib/tcl90.lib + @CURRENT_INSTALLED_DIR@/lib/tcl90s.lib + @CURRENT_INSTALLED_DIR@/lib/tcl90sx.lib + @LIBXML2_LIBS_RELEASE@ + @LIBXSLT_LIBS_RELEASE@ + @CURRENT_INSTALLED_DIR@/lib/zlib.lib + @CURRENT_INSTALLED_DIR@/lib/zstd.lib + + diff --git a/vcpkg_ports/libpq/vcpkg.json b/vcpkg_ports/libpq/vcpkg.json new file mode 100644 index 000000000..2ab73a53e --- /dev/null +++ b/vcpkg_ports/libpq/vcpkg.json @@ -0,0 +1,194 @@ +{ + "name": "libpq", + "version": "16.9", + "port-version": 2, + "description": "The official database access API of postgresql", + "homepage": "https://www.postgresql.org/", + "license": "PostgreSQL", + "supports": "!uwp & !emscripten", + "dependencies": [ + { + "name": "libpq", + "default-features": false, + "features": [ + "bonjour" + ], + "platform": "osx" + }, + { + "name": "vcpkg-cmake-get-vars", + "host": true + }, + { + "name": "vcpkg-pkgconfig-get-modules", + "host": true, + "platform": "windows & !mingw" + } + ], + "default-features": [ + "lz4", + "openssl", + "zlib" + ], + "features": { + "all": { + "description": "Build all supported features", + "dependencies": [ + { + "name": "libpq", + "features": [ + "client", + "icu", + "xml", + "xslt", + "zstd" + ] + }, + { + "name": "libpq", + "features": [ + "bonjour" + ], + "platform": "osx" + }, + { + "name": "libpq", + "features": [ + "nls" + ], + "platform": "!osx" + }, + { + "name": "libpq", + "features": [ + "readline" + ], + "platform": "!windows" + }, + { + "name": "libpq", + "features": [ + "python" + ], + "platform": "!android & !mingw" + }, + { + "name": "libpq", + "features": [ + "tcl" + ], + "platform": "windows & !mingw & !arm" + } + ] + }, + "bonjour": { + "description": "Build with Bonjour support", + "supports": "osx" + }, + "client": { + "description": "Build all client tools and libraries" + }, + "icu": { + "description": "Build with support for the ICU library", + "dependencies": [ + "icu" + ] + }, + "lz4": { + "description": "Use lz4", + "dependencies": [ + "lz4" + ] + }, + "nls": { + "description": "Native Language Support", + "supports": "!osx", + "dependencies": [ + { + "name": "gettext", + "host": true, + "features": [ + "tools" + ] + }, + "gettext-libintl" + ] + }, + "openssl": { + "description": "support for encrypted client connections and random number generation on platforms that do not have \"/dev/urandom\" (except windows)", + "dependencies": [ + "openssl" + ] + }, + "python": { + "$supports": "!(windows & (static | mingw))", + "description": "build the PL/Python server programming language", + "dependencies": [ + { + "name": "libpq", + "default-features": false, + "features": [ + "client" + ] + }, + "python3" + ] + }, + "readline": { + "description": "Use readline", + "supports": "!windows, mingw", + "dependencies": [ + "readline" + ] + }, + "tcl": { + "$supports": "!(windows & (static | mingw))", + "description": "build the PL/Tcl procedural language", + "supports": "windows & !mingw", + "dependencies": [ + { + "name": "libpq", + "default-features": false, + "features": [ + "client" + ] + }, + "tcl" + ] + }, + "xml": { + "description": "Build with libxml", + "dependencies": [ + { + "name": "libxml2", + "default-features": false + } + ] + }, + "xslt": { + "description": "Build with libxslt", + "dependencies": [ + { + "name": "libpq", + "default-features": false, + "features": [ + "xml" + ] + }, + "libxslt" + ] + }, + "zlib": { + "description": "Use zlib", + "dependencies": [ + "zlib" + ] + }, + "zstd": { + "description": "Use zstd", + "dependencies": [ + "zstd" + ] + } + } +} diff --git a/vcpkg_ports/libpq/windows/macro-def.patch b/vcpkg_ports/libpq/windows/macro-def.patch new file mode 100644 index 000000000..1d16c1270 --- /dev/null +++ b/vcpkg_ports/libpq/windows/macro-def.patch @@ -0,0 +1,18 @@ +diff --git a/src/include/common/checksum_helper.h b/src/include/common/checksum_helper.h +index cac7570ea..d0ca1243c 100644 +--- a/src/include/common/checksum_helper.h ++++ b/src/include/common/checksum_helper.h +@@ -33,7 +28,13 @@ + */ + typedef enum pg_checksum_type + { ++#pragma push_macro("CHECKSUM_TYPE_NONE") ++#ifdef CHECKSUM_TYPE_NONE ++// winioctl.h defines CHECKSUM_TYPE_NONE to 0 as a macro. ++#undef CHECKSUM_TYPE_NONE ++#endif + CHECKSUM_TYPE_NONE, ++#pragma pop_macro("CHECKSUM_TYPE_NONE") + CHECKSUM_TYPE_CRC32C, + CHECKSUM_TYPE_SHA224, + CHECKSUM_TYPE_SHA256, diff --git a/vcpkg_ports/libpq/windows/msbuild.patch b/vcpkg_ports/libpq/windows/msbuild.patch new file mode 100644 index 000000000..e6c70ad09 --- /dev/null +++ b/vcpkg_ports/libpq/windows/msbuild.patch @@ -0,0 +1,398 @@ +diff --git a/src/tools/msvc/Install.pm b/src/tools/msvc/Install.pm +index 05548d7..097db91 100644 +--- a/src/tools/msvc/Install.pm ++++ b/src/tools/msvc/Install.pm +@@ -53,6 +53,11 @@ sub Install + my $target = shift; + $insttype = shift; + $insttype = "all" unless ($insttype); ++ if ($insttype eq 'core') ++ { ++ $insttype = 'client'; ++ @client_program_files = ( 'libecpg','libecpg_compat', 'libpgtypes', 'libpq' ); ++ } + + # if called from vcregress, the config will be passed to us + # so no need to re-include these +@@ -89,7 +94,7 @@ sub Install + my $majorver = DetermineMajorVersion(); + print "Installing version $majorver for $conf in $target\n"; + +- my @client_dirs = ('bin', 'lib', 'share', 'symbols'); ++ my @client_dirs = ('bin', 'lib', 'share', 'tools', 'share/libpq', 'tools/libpq'); + my @all_dirs = ( + @client_dirs, 'doc', 'doc/contrib', 'doc/extension', 'share/contrib', + 'share/extension', 'share/timezonesets', 'share/tsearch_data'); +@@ -117,11 +122,11 @@ sub Install + } + }, + @top_dir); +- CopySetOfFiles('config files', $sample_files, $target . '/share/'); ++ CopySetOfFiles('config files', $sample_files, $target . '/share/libpq/'); + CopyFiles( + 'Import libraries', + $target . '/lib/', +- "$conf\\", "postgres\\postgres.lib", "libpgcommon\\libpgcommon.lib", ++ "$conf\\", "libpgcommon\\libpgcommon.lib", + "libpgport\\libpgport.lib"); + CopyContribFiles($config, $target); + CopyIncludeFiles($target); +@@ -293,7 +298,16 @@ sub CopySolutionOutput + { + if ($1 == 1) + { +- push(@{ $install_list{'bin'} }, "exe"); ++ push(@{ $install_list{'tools\\libpq'} }, "exe"); ++ } ++ elsif ($1 == 2) ++ { ++ push(@{ $install_list{'bin'} }, "dll"); ++ push(@{ $install_list{'lib'} }, "lib") if $is_sharedlib; # not for plugins ++ } ++ elsif ($is_sharedlib) # forced to static lib by vcpkg triplet ++ { ++ push(@{ $install_list{'lib'} }, "lib"); + } + elsif ($1 == 2) + { +@@ -317,7 +331,16 @@ sub CopySolutionOutput + { + if ($1 eq 'Application') + { +- push(@{ $install_list{'bin'} }, "exe"); ++ push(@{ $install_list{'tools\\libpq'} }, "exe"); ++ } ++ elsif ($1 eq 'DynamicLibrary') ++ { ++ push(@{ $install_list{'bin'} }, "dll"); ++ push(@{ $install_list{'lib'} }, "lib") if $is_sharedlib; # not for plugins ++ } ++ elsif ($is_sharedlib) # forced to static lib by vcpkg triplet ++ { ++ push(@{ $install_list{'lib'} }, "lib"); + } + elsif ($1 eq 'DynamicLibrary') + { +@@ -350,7 +373,8 @@ sub CopySolutionOutput + || croak "Could not copy $pf.$ext\n"; + } + } +- lcopy("$conf\\$pf\\$pf.pdb", "$target\\symbols\\$pf.pdb") ++ $1 ne 'DynamicLibrary' || ++ lcopy("$conf\\$pf\\$pf.pdb", "$target\\bin\\$pf.pdb") + || croak "Could not copy $pf.pdb\n"; + print "."; + } +@@ -453,7 +477,7 @@ sub CopySubdirFiles + foreach my $f (split /\s+/, $flist) + { + lcopy("$subdir/$module/$f.control", +- "$target/share/extension/$f.control") ++ "$target/share/libpq/extension/$f.control") + || croak("Could not copy file $f.control in contrib $module"); + print '.'; + } +@@ -471,7 +495,7 @@ sub CopySubdirFiles + foreach my $f (split /\s+/, $flist) + { + lcopy("$subdir/$module/$f", +- "$target/share/$moduledir/" . basename($f)) ++ "$target/share/libpq/$moduledir/" . basename($f)) + || croak("Could not copy file $f in contrib $module"); + print '.'; + } +@@ -486,7 +510,7 @@ sub CopySubdirFiles + foreach my $f (split /\s+/, $flist) + { + lcopy("$subdir/$module/$f", +- "$target/share/tsearch_data/" . basename($f)) ++ "$target/share/libpq/tsearch_data/" . basename($f)) + || croak("Could not copy file $f in $subdir $module"); + print '.'; + } +@@ -549,7 +573,7 @@ sub CopySubdirFiles + if ($module eq 'spi'); + foreach my $f (split /\s+/, $flist) + { +- lcopy("$subdir/$module/$f", "$target/doc/$moduledir/$f") ++ lcopy("$subdir/$module/$f", "$target/share/libpq/doc/$moduledir/$f") + || croak("Could not copy file $f in contrib $module"); + print '.'; + } +@@ -675,7 +699,7 @@ sub GenerateNLSFiles + my $majorver = shift; + + print "Installing NLS files..."; +- EnsureDirectories($target, "share/locale"); ++ EnsureDirectories($target, "share/libpq/locale"); + my @flist; + File::Find::find( + { +@@ -697,12 +721,12 @@ sub GenerateNLSFiles + next unless /([^\/]+)\.po/; + $lang = $1; + +- EnsureDirectories($target, "share/locale/$lang", +- "share/locale/$lang/LC_MESSAGES"); ++ EnsureDirectories($target, "share/libpq/locale/$lang", ++ "share/libpq/locale/$lang/LC_MESSAGES"); + my @args = ( +- "$nlspath\\bin\\msgfmt", ++ "msgfmt", + '-o', +- "$target\\share\\locale\\$lang\\LC_MESSAGES\\$prgm-$majorver.mo", ++ "$target\\share\\libpq\\locale\\$lang\\LC_MESSAGES\\$prgm-$majorver.mo", + $_); + system(@args) && croak("Could not run msgfmt on $dir\\$_"); + print "."; +diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm +index 62fec1f..ecb1b86 100644 +--- a/src/tools/msvc/MSBuildProject.pm ++++ b/src/tools/msvc/MSBuildProject.pm +@@ -80,14 +80,14 @@ EOF + print $f < + EOF +- ++ my $maybe_dll = $self->{solution}->{options}->{VCPKG_CRT_LINKAGE} eq 'dynamic' ? "DLL" : ''; + $self->WriteItemDefinitionGroup( + $f, 'Debug', + { + defs => "_DEBUG;DEBUG=1", + opt => 'Disabled', + strpool => 'false', +- runtime => 'MultiThreadedDebugDLL' ++ runtime => 'MultiThreadedDebug' . $maybe_dll + }); + $self->WriteItemDefinitionGroup( + $f, +@@ -96,7 +96,7 @@ EOF + defs => "", + opt => 'Full', + strpool => 'true', +- runtime => 'MultiThreadedDLL' ++ runtime => 'MultiThreaded' . $maybe_dll + }); + return; + } +@@ -266,6 +266,8 @@ sub WriteConfigurationPropertyGroup + ($self->{type} eq "exe") + ? 'Application' + : ($self->{type} eq "dll" ? 'DynamicLibrary' : 'StaticLibrary'); ++ if ($self->{solution}->{options}->{VCPKG_LIBRARY_LINKAGE} eq 'static') ++ { $cfgtype =~ s/DynamicLibrary/StaticLibrary/; } + + print $f < +@@ -311,7 +313,9 @@ sub WriteItemDefinitionGroup + my $libs = $self->GetAdditionalLinkerDependencies($cfgname, ';'); + + my $targetmachine = +- $self->{platform} eq 'Win32' ? 'MachineX86' : 'MachineX64'; ++ 'Machine' . uc($self->{platform}); ++ $targetmachine =~ s/WIN32/X86/; ++ my $randomizebase = ($self->{platform} =~ /^ARM/) ? 'true' : 'false'; + my $arch = $self->{platform} eq 'Win32' ? 'x86' : 'x86_64'; + + my $includes = join ';', @{ $self->{includes} }, ""; +diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm +index 9e05eb9..8ac0a5d 100644 +--- a/src/tools/msvc/Mkvcbuild.pm ++++ b/src/tools/msvc/Mkvcbuild.pm +@@ -125,8 +125,10 @@ sub mkvcbuild + + if ($vsVersion >= '9.00') + { ++ if ($solution->{platform} !~ /^ARM/) { + push(@pgportfiles, 'pg_crc32c_sse42_choose.c'); + push(@pgportfiles, 'pg_crc32c_sse42.c'); ++ } + push(@pgportfiles, 'pg_crc32c_sb8.c'); + } + else +@@ -208,6 +210,7 @@ sub mkvcbuild + 'syncrep_gram.y'); + $postgres->AddFiles('src/backend/utils/adt', 'jsonpath_scan.l', + 'jsonpath_gram.y'); ++ ($config->{VCPKG_LIBRARY_LINKAGE} eq 'dynamic') && + $postgres->AddDefine('BUILDING_DLL'); + $postgres->AddLibrary('secur32.lib'); + $postgres->AddLibrary('ws2_32.lib'); +@@ -252,12 +255,13 @@ sub mkvcbuild + $pltcl->AddIncludeDir($solution->{options}->{tcl} . '/include'); + $pltcl->AddReference($postgres); + +- for my $tclver (qw(86t 86 85 84)) ++ my $v = $solution->{options}->{tcl_version}; ++ for my $tclver ( ("${v}","${v}s","${v}sx") ) + { + my $tcllib = $solution->{options}->{tcl} . "/lib/tcl$tclver.lib"; + if (-e $tcllib) + { +- $pltcl->AddLibrary($tcllib); ++ $pltcl->AddLibrary("\$(VcpkgTcl${tclver}Libs)"); + $found = 1; + last; + } +@@ -512,8 +516,7 @@ sub mkvcbuild + . "print(str(sys.version_info[0])+str(sys.version_info[1]))"; + my $prefixcmd = + qq("$solution->{options}->{python}\\python" -c "$pythonprog"); +- my $pyout = `$prefixcmd`; +- die "Could not query for python version!\n" if $?; ++ my $pyout = "$solution->{options}->{python}\n$solution->{options}->{python_version}"; + my ($pyprefix, $pyver) = split(/\r?\n/, $pyout); + + # Sometimes (always?) if python is not present, the execution +@@ -529,8 +532,8 @@ sub mkvcbuild + + my $plpython = $solution->AddProject('plpython' . $pymajorver, + 'dll', 'PLs', 'src/pl/plpython'); +- $plpython->AddIncludeDir($pyprefix . '/include'); +- $plpython->AddLibrary($pyprefix . "/Libs/python$pyver.lib"); ++ $plpython->AddIncludeDir($pyprefix . "/include/python$pyver"); ++ $plpython->AddLibrary('$(VcpkgPythonLibs)'); + $plpython->AddReference($postgres); + + # Add transform modules dependent on plpython +diff --git a/src/tools/msvc/Project.pm b/src/tools/msvc/Project.pm +index 0507ad0..48caab9 100644 +--- a/src/tools/msvc/Project.pm ++++ b/src/tools/msvc/Project.pm +@@ -167,6 +167,11 @@ sub AddReference + } + $self->AddLibrary( + "__CFGNAME__/" . $ref->{name} . "/" . $ref->{name} . ".lib"); ++ ++ if ($self->{solution}->{options}->{VCPKG_LIBRARY_LINKAGE} eq 'static') ++ { ++ map { $self->AddLibrary($_) } @{ $ref->{libraries} }; ++ } + } + return; + } +diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm +index b6d31c3..27d89fc 100644 +--- a/src/tools/msvc/Solution.pm ++++ b/src/tools/msvc/Solution.pm +@@ -63,6 +63,11 @@ sub DeterminePlatform + my $self = shift; + + if ($^O eq "MSWin32") ++ { ++ $self->{platform} = uc($self->{options}->{VCPKG_TARGET_ARCHITECTURE}); ++ $self->{platform} =~ s/^X86$/Win32/; ++ } ++ elsif (0) + { + # Examine CL help output to determine if we are in 32 or 64-bit mode. + my $output = `cl /help 2>&1`; +@@ -124,6 +129,9 @@ sub copyFile + sub GetOpenSSLVersion + { + my $self = shift; ++ if ($self->{options}->{openssl_version} =~ /(\d+)\.(\d+)\.(\d+)/m) { ++ return ($1, $2, $3); ++ } + + # Attempt to get OpenSSL version and location. This assumes that + # openssl.exe is in the specified directory. +@@ -148,7 +156,7 @@ sub GetOpenSSLVersion + sub GenerateFiles + { + my $self = shift; +- my $bits = $self->{platform} eq 'Win32' ? 32 : 64; ++ my $bits = $self->{platform} =~ /64/ ? 64 : 32; + my $ac_init_found = 0; + my $package_name; + my $package_version; +@@ -440,7 +448,7 @@ sub GenerateFiles + USE_PAM => undef, + USE_SLICING_BY_8_CRC32C => undef, + USE_SSE42_CRC32C => undef, +- USE_SSE42_CRC32C_WITH_RUNTIME_CHECK => 1, ++ USE_SSE42_CRC32C_WITH_RUNTIME_CHECK => $self->{platform} =~ /^ARM/ ? undef : 1, + USE_SYSTEMD => undef, + USE_SYSV_SEMAPHORES => undef, + USE_SYSV_SHARED_MEMORY => undef, +@@ -725,14 +733,14 @@ sub GenerateFiles + || confess "Could not open pg_config_paths.h"; + print $o <{options}->{zlib}) + { + $proj->AddIncludeDir($self->{options}->{zlib} . '\include'); +- $proj->AddLibrary($self->{options}->{zlib} . '\lib\zdll.lib'); ++ $proj->AddLibrary('$(VcpkgZlibLibs)'); + } + if ($self->{options}->{openssl}) + { + $proj->AddIncludeDir($self->{options}->{openssl} . '\include'); ++ $proj->AddLibrary('$(VcpkgOpensslLibs)'); ++ } ++ elsif (0) ++ { + my ($digit1, $digit2, $digit3) = $self->GetOpenSSLVersion(); + + # Starting at version 1.1.0 the OpenSSL installers have +@@ -1032,7 +1044,7 @@ sub AddProject + if ($self->{options}->{nls}) + { + $proj->AddIncludeDir($self->{options}->{nls} . '\include'); +- $proj->AddLibrary($self->{options}->{nls} . '\lib\libintl.lib'); ++ $proj->AddLibrary('$(VcpkgNlsLibs)'); + } + if ($self->{options}->{gss}) + { +@@ -1065,6 +1077,10 @@ sub AddProject + if ($self->{options}->{icu}) + { + $proj->AddIncludeDir($self->{options}->{icu} . '\include'); ++ $proj->AddLibrary('$(VcpkgIcuLibs)'); ++ } ++ elsif (0) ++ { + if ($self->{platform} eq 'Win32') + { + $proj->AddLibrary($self->{options}->{icu} . '\lib\icuin.lib'); +@@ -1082,22 +1098,22 @@ sub AddProject + { + $proj->AddIncludeDir($self->{options}->{xml} . '\include'); + $proj->AddIncludeDir($self->{options}->{xml} . '\include\libxml2'); +- $proj->AddLibrary($self->{options}->{xml} . '\lib\libxml2.lib'); ++ $proj->AddLibrary('$(VcpkgXmlLibs)'); + } + if ($self->{options}->{xslt}) + { + $proj->AddIncludeDir($self->{options}->{xslt} . '\include'); +- $proj->AddLibrary($self->{options}->{xslt} . '\lib\libxslt.lib'); ++ $proj->AddLibrary('$(VcpkgXsltLibs)'); + } + if ($self->{options}->{lz4}) + { + $proj->AddIncludeDir($self->{options}->{lz4} . '\include'); +- $proj->AddLibrary($self->{options}->{lz4} . '\lib\liblz4.lib'); ++ $proj->AddLibrary('$(VcpkgLz4Libs)'); + } + if ($self->{options}->{zstd}) + { + $proj->AddIncludeDir($self->{options}->{zstd} . '\include'); +- $proj->AddLibrary($self->{options}->{zstd} . '\lib\libzstd.lib'); ++ $proj->AddLibrary('$(VcpkgZstdLibs)'); + } + if ($self->{options}->{uuid}) + { diff --git a/vcpkg_ports/libpq/windows/spin_delay.patch b/vcpkg_ports/libpq/windows/spin_delay.patch new file mode 100644 index 000000000..163e8e6ef --- /dev/null +++ b/vcpkg_ports/libpq/windows/spin_delay.patch @@ -0,0 +1,24 @@ +diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h +index 4d3ffc7..658b1a1 100644 +--- a/src/include/storage/s_lock.h ++++ b/src/include/storage/s_lock.h +@@ -953,12 +953,18 @@ typedef LONG slock_t; + /* If using Visual C++ on Win64, inline assembly is unavailable. + * Use a _mm_pause intrinsic instead of rep nop. + */ +-#if defined(_WIN64) ++#if defined(_M_X64) && !defined(_M_ARM64EC) + static __forceinline void + spin_delay(void) + { + _mm_pause(); + } ++#elif defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM64EC) ++static __forceinline void ++spin_delay(void) ++{ ++ __yield(); ++} + #else + static __forceinline void + spin_delay(void) diff --git a/vcpkg_ports/libpq/windows/tcl-9.0-alpha.patch b/vcpkg_ports/libpq/windows/tcl-9.0-alpha.patch new file mode 100644 index 000000000..154efcb8f --- /dev/null +++ b/vcpkg_ports/libpq/windows/tcl-9.0-alpha.patch @@ -0,0 +1,12 @@ +diff -Naur postgresql-16.9/src/pl/tcl/pltcl.c postgresql-16.9-vcpkg/src/pl/tcl/pltcl.c +--- postgresql-16.9/src/pl/tcl/pltcl.c 2025-05-05 22:30:08.000000000 +0200 ++++ postgresql-16.9-vcpkg/src/pl/tcl/pltcl.c 2025-05-23 22:53:43.485828671 +0200 +@@ -56,7 +56,7 @@ + #define CONST86 + #endif + +-#if !HAVE_TCL_VERSION(8,7) ++#if !HAVE_TCL_VERSION(8,7) || (TCL_MAJOR_VERSION == 9 && TCL_MINOR_VERSION == 0 && TCL_RELEASE_LEVEL == TCL_ALPHA_RELEASE) + typedef int Tcl_Size; + #endif + diff --git a/vcpkg_ports/libpq/windows/win_bison_flex.patch b/vcpkg_ports/libpq/windows/win_bison_flex.patch new file mode 100644 index 000000000..fc8230193 --- /dev/null +++ b/vcpkg_ports/libpq/windows/win_bison_flex.patch @@ -0,0 +1,42 @@ +diff --git a/src/tools/msvc/pgbison.pl b/src/tools/msvc/pgbison.pl +index 25df669..373bedd 100644 +--- a/src/tools/msvc/pgbison.pl ++++ b/src/tools/msvc/pgbison.pl +@@ -13,7 +13,7 @@ use File::Basename; + + do './src/tools/msvc/buildenv.pl' if -e 'src/tools/msvc/buildenv.pl'; + +-my ($bisonver) = `bison -V`; # grab first line ++my ($bisonver) = `win_bison -V`; # grab first line + $bisonver = (split(/\s+/, $bisonver))[3]; # grab version number + + unless ($bisonver ge '2.3') +@@ -51,5 +51,5 @@ my $headerflag = ($make =~ /^$basetarg:\s+BISONFLAGS\b.*-d/m ? '-d' : ''); + + my $nodep = $bisonver ge '3.0' ? "-Wno-deprecated" : ""; + +-system("bison $nodep $headerflag $input -o $output"); ++system("win_bison $nodep $headerflag $input -o $output"); + exit $? >> 8; +diff --git a/src/tools/msvc/pgflex.pl b/src/tools/msvc/pgflex.pl +index c308a08..0807ce7 100644 +--- a/src/tools/msvc/pgflex.pl ++++ b/src/tools/msvc/pgflex.pl +@@ -16,7 +16,7 @@ $ENV{CYGWIN} = 'nodosfilewarning'; + + do './src/tools/msvc/buildenv.pl' if -e 'src/tools/msvc/buildenv.pl'; + +-my ($flexver) = `flex -V`; # grab first line ++my ($flexver) = `win_flex -V`; # grab first line + $flexver = (split(/\s+/, $flexver))[1]; + $flexver =~ s/[^0-9.]//g; + my @verparts = split(/\./, $flexver); +@@ -52,7 +52,7 @@ close($mf); + my $basetarg = basename($output); + my $flexflags = ($make =~ /^$basetarg:\s*FLEXFLAGS\s*=\s*(\S.*)/m ? $1 : ''); + +-system("flex $flexflags -o$output $input"); ++system("win_flex $flexflags -o$output $input"); + if ($? == 0) + { +