]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Revert "ci: install win32 libpq from conda force"
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 13 May 2025 12:55:17 +0000 (14:55 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 13 May 2025 14:07:02 +0000 (16:07 +0200)
This reverts commit ba4187d830a90f3e8edba10260d213079b7b5912.

Fix #1088

.github/workflows/packages-bin.yml
.github/workflows/tests.yml
tools/build/pg_config_vcpkg_stub/pg_config_vcpkg_stub/__init__.py [new file with mode: 0644]
tools/build/pg_config_vcpkg_stub/pyproject.toml [new file with mode: 0644]
tools/build/wheel_win32_before_build.bat

index a5ba0cd1e7ba82df9f22b7a8b3c66055ad7d395e..65f5663b2c57b1dd8551c44e7206692f9090170e 100644 (file)
@@ -26,15 +26,15 @@ on:
 env:
   # Latest release: https://www.postgresql.org/ftp/source/
   LIBPQ_VERSION: "17.5"
+  # Note: On windows the latest version can be found at
+  # https://vcpkg.io/en/package/libpq
+  # However the command line tool doesn't have a flag to specify to install
+  # a specific version, so whatever you get you keep it.
+  # https://github.com/microsoft/vcpkg/discussions/25622
 
   # Latest release: https://www.openssl.org/source/
   OPENSSL_VERSION: "3.5.0"
 
-concurrency:
-  # Cancel older requests of the same workflow in the same branch.
-  group: ${{ github.workflow }}-${{ github.ref_name }}
-  cancel-in-progress: true
-
 jobs:
 
   linux:  # {{{
@@ -204,12 +204,15 @@ jobs:
           $PgSvc.Start()
         shell: powershell
 
-      - uses: prefix-dev/setup-pixi@v0.8.8
+      - name: Export GitHub Actions cache environment variables
+        uses: actions/github-script@v7
         with:
-          run-install: false
-      - run: pixi global install libpq=${{ env.LIBPQ_VERSION }} --with openssl=${{ env.OPENSSL_VERSION }}
-      - run: echo "EXTRA_LIB_DIR=$(pg_config.exe --bindir)" >> $GITHUB_OUTPUT
-        id: libdir
+          script: |
+            const path = require('path')
+            core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
+            core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
+            core.addPath(path.join(process.env.VCPKG_INSTALLATION_ROOT, 'installed/x64-windows-release/lib'));
+            core.addPath(path.join(process.env.VCPKG_INSTALLATION_ROOT, 'installed/x64-windows-release/bin'));
 
       - name: Create the binary package source tree
         run: python3 ./tools/build/copy_to_binary.py
@@ -225,7 +228,6 @@ jobs:
           CIBW_BEFORE_BUILD_WINDOWS: '.\tools\build\wheel_win32_before_build.bat'
           CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: >-
             delvewheel repair -w {dest_dir}
-            --add-path="${{ steps.libdir.outputs.EXTRA_LIB_DIR }}"
             --no-mangle "libiconv-2.dll;libwinpthread-1.dll" {wheel}
           CIBW_TEST_REQUIRES: ./psycopg[test] ./psycopg_pool
           CIBW_TEST_COMMAND: >-
@@ -233,8 +235,8 @@ jobs:
           CIBW_ENVIRONMENT_WINDOWS: >-
             PSYCOPG_IMPL=binary
             PSYCOPG_TEST_DSN="host=127.0.0.1 user=postgres"
-            PSYCOPG_TEST_WANT_LIBPQ_BUILD=${{env.LIBPQ_VERSION}}
-            PSYCOPG_TEST_WANT_LIBPQ_IMPORT=${{env.LIBPQ_VERSION}}
+            PSYCOPG_TEST_WANT_LIBPQ_BUILD=">= 16"
+            PSYCOPG_TEST_WANT_LIBPQ_IMPORT=">= 16"
 
       - uses: actions/upload-artifact@v4
         with:
index 286688b12b0810f52e1ed0cc04c03b346037bbc2..1f1f82280a2ecd4a4614e87b1f43cb25e1a0afa8 100644 (file)
@@ -301,7 +301,6 @@ jobs:
       PSYCOPG_TEST_DSN: "host=127.0.0.1 dbname=postgres"
       # On windows pproxy doesn't seem very happy. Also a few timing test fail.
       NOT_MARKERS: "timing proxy mypy"
-      PG_VERSION: "17.4"
 
     defaults:
       run:
@@ -334,18 +333,23 @@ jobs:
         if: ${{ github.event_name == 'schedule' }}
         run: echo "NOT_MARKERS=$NOT_MARKERS refcount" >> $GITHUB_ENV
 
-      - uses: prefix-dev/setup-pixi@v0.8.8
+      - name: Export GitHub Actions cache environment variables
+      # https://learn.microsoft.com/en-us/vcpkg/consume/binary-caching-github-actions-cache
+        uses: actions/github-script@v7
         with:
-          run-install: false
-
-      - run: pixi global install libpq=${{ env.PG_VERSION }}
-
-      - name: 'add libpq.dll to path'
-        run: echo "$(pg_config.exe --bindir)" >> $GITHUB_PATH
-
-      - name: Install delvewheel
+          script: |
+            const path = require('path')
+            core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
+            core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
+            core.addPath(path.join(process.env.VCPKG_INSTALLATION_ROOT, 'installed/x64-windows-release/lib'));
+            core.addPath(path.join(process.env.VCPKG_INSTALLATION_ROOT, 'installed/x64-windows-release/bin'));
+
+      - name: Install libpq from vcpkg and install pg_config.exe stub
         run: .\tools\build\wheel_win32_before_build.bat
         shell: powershell
+        env:
+          # cache vcpkg
+          VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
 
       - name: Build the C wheel
         if: ${{ matrix.impl == 'c' }}
diff --git a/tools/build/pg_config_vcpkg_stub/pg_config_vcpkg_stub/__init__.py b/tools/build/pg_config_vcpkg_stub/pg_config_vcpkg_stub/__init__.py
new file mode 100644 (file)
index 0000000..8993566
--- /dev/null
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+"""
+We use vcpkg in github actions to build psycopg-binary.
+
+This is a stub to work as `pg_config --libdir` or `pg_config --includedir` to
+make it work with vcpkg.
+
+You will need install `vcpkg`, set `VCPKG_ROOT` env, and run `vcpkg install
+libpq:x64-windows-release` before using this script.
+"""
+
+import os
+import sys
+import platform
+from pathlib import Path
+from argparse import ArgumentParser, Namespace, RawDescriptionHelpFormatter
+
+
+class ScriptError(Exception):
+    """Controlled exception raised by the script."""
+
+
+def _main() -> None:
+    # only x64-windows
+    if not (sys.platform == "win32" and platform.machine() == "AMD64"):
+        raise ScriptError("this script should only be used in x64-windows")
+
+    vcpkg_root = os.environ.get(
+        "VCPKG_ROOT", os.environ.get("VCPKG_INSTALLATION_ROOT", "")
+    )
+    if not vcpkg_root:
+        raise ScriptError("VCPKG_ROOT/VCPKG_INSTALLATION_ROOT env var not specified")
+    vcpkg_platform_root = (Path(vcpkg_root) / "installed/x64-windows-release").resolve()
+
+    args = parse_cmdline()
+
+    if args.libdir:
+        if not (f := vcpkg_platform_root / "lib/libpq.lib").exists():
+            raise ScriptError(f"libpq library not found: {f}")
+        print(vcpkg_platform_root.joinpath("lib"))
+
+    elif args.includedir:
+        if not (d := vcpkg_platform_root / "include/libpq").is_dir():
+            raise ScriptError(f"libpq include directory not found: {d}")
+        print(vcpkg_platform_root.joinpath("include"))
+
+    else:
+        raise ScriptError("command not handled")
+
+
+def parse_cmdline() -> Namespace:
+    parser = ArgumentParser(
+        description=__doc__, formatter_class=RawDescriptionHelpFormatter
+    )
+    g = parser.add_mutually_exclusive_group(required=True)
+    g.add_argument(
+        "--libdir",
+        action="store_true",
+        help="show location of object code libraries",
+    )
+    g.add_argument(
+        "--includedir",
+        action="store_true",
+        help="show location of C header files of the client interfaces",
+    )
+    opt = parser.parse_args()
+    return opt
+
+
+def main() -> None:
+    try:
+        _main()
+    except ScriptError as e:
+        print(f"ERROR: {e}.", file=sys.stderr)
+        sys.exit(1)
+
+
+if __name__ == "__main__":
+    main()
diff --git a/tools/build/pg_config_vcpkg_stub/pyproject.toml b/tools/build/pg_config_vcpkg_stub/pyproject.toml
new file mode 100644 (file)
index 0000000..f776905
--- /dev/null
@@ -0,0 +1,11 @@
+[build-system]
+requires = ["setuptools"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = 'pg_config_vcpkg_stub'
+version = "0"
+description = "see docs string in pg_config_vcpkg_stub for more details"
+
+[project.scripts]
+pg_config = 'pg_config_vcpkg_stub:main'
index c016ceb2c5e022bcd7274d50fba063d5260ec6e8..5a22ab384856f510c911dc1e48e4bd31fc7c7ed7 100644 (file)
@@ -2,3 +2,8 @@
 
 pip install delvewheel wheel
 
+REM A specific version cannot be easily chosen.
+REM https://github.com/microsoft/vcpkg/discussions/25622
+vcpkg install libpq:x64-windows-release
+
+pipx install .\tools\build\pg_config_vcpkg_stub\