|  | 
|  | 1 | +name: Build and cache libpq | 
|  | 2 | + | 
|  | 3 | +# Build the libpq package and cache the artifacts. | 
|  | 4 | +# | 
|  | 5 | +# Every Python version on the same architecture will use the same libpq. | 
|  | 6 | +# Therefore building and caching the libpq together with the binary packages | 
|  | 7 | +# result in multiple concurrent builds, and the github artifacts manageer very | 
|  | 8 | +# confused. | 
|  | 9 | +# | 
|  | 10 | +# This job builds the libpq and then caches the artifacts so that the | 
|  | 11 | +# packages.yml workflow will find the library in the cache. | 
|  | 12 | +# | 
|  | 13 | +# You can see the caches at https://github.com/psycopg/psycopg2/actions/caches | 
|  | 14 | +# | 
|  | 15 | +# Or from the API: | 
|  | 16 | +# | 
|  | 17 | +#   curl -fsSL -X GET \ | 
|  | 18 | +#     -H "Accept: application/vnd.github+json" \ | 
|  | 19 | +#     -H "Authorization: Bearer $GITHUB_TOKEN" \ | 
|  | 20 | +#     -H "X-GitHub-Api-Version: 2022-11-28" \ | 
|  | 21 | +#     "https://api.github.com/repos/psycopg/psycopg/actions/caches" \ | 
|  | 22 | +#   | jq -r '.actions_caches[].key' | 
|  | 23 | +# | 
|  | 24 | +# You can delete a cache using: | 
|  | 25 | +# | 
|  | 26 | +#   curl -fsSL -X DELETE \ | 
|  | 27 | +#     -H "Accept: application/vnd.github+json" \ | 
|  | 28 | +#     -H "Authorization: Bearer $GITHUB_TOKEN" \ | 
|  | 29 | +#     -H "X-GitHub-Api-Version: 2022-11-28" \ | 
|  | 30 | +#     "https://api.github.com/repos/psycopg/psycopg/actions/caches?key=libpq-manylinux-ppc64le-17.2-3.4.0" | 
|  | 31 | +# | 
|  | 32 | +# ref: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-github-actions-caches-for-a-repository-using-a-cache-key | 
|  | 33 | + | 
|  | 34 | +on: | 
|  | 35 | +  workflow_dispatch: | 
|  | 36 | +  push: | 
|  | 37 | +    paths: | 
|  | 38 | +      - .github/workflows/build-and-cache-libpq.yml | 
|  | 39 | +      - scripts/build/build_libpq.sh | 
|  | 40 | + | 
|  | 41 | +# TODO: move these env vars in an external env file in order to share them | 
|  | 42 | +# across workflows. | 
|  | 43 | + | 
|  | 44 | +env: | 
|  | 45 | +  LIBPQ_VERSION: "17.6" | 
|  | 46 | +  OPENSSL_VERSION: "3.5.4" | 
|  | 47 | +  PQ_FLAGS: "" | 
|  | 48 | + | 
|  | 49 | +concurrency: | 
|  | 50 | +  # Cancel older requests of the same workflow in the same branch. | 
|  | 51 | +  group: ${{ github.workflow }}-${{ github.ref_name }} | 
|  | 52 | +  cancel-in-progress: true | 
|  | 53 | + | 
|  | 54 | +jobs: | 
|  | 55 | + | 
|  | 56 | +  linux:  # {{{ | 
|  | 57 | +    runs-on: ubuntu-latest | 
|  | 58 | +    if: true | 
|  | 59 | + | 
|  | 60 | +    strategy: | 
|  | 61 | +      fail-fast: false | 
|  | 62 | +      matrix: | 
|  | 63 | +        arch: [x86_64, ppc64le, aarch64, riscv64] | 
|  | 64 | +        platform: [manylinux, musllinux] | 
|  | 65 | + | 
|  | 66 | +    steps: | 
|  | 67 | +      - uses: actions/checkout@v5 | 
|  | 68 | + | 
|  | 69 | +      - name: Set up QEMU for multi-arch build | 
|  | 70 | +        # Check https://github.com/docker/setup-qemu-action for newer versions. | 
|  | 71 | +        uses: docker/setup-qemu-action@v3 | 
|  | 72 | +        with: | 
|  | 73 | +          # https://github.com/pypa/cibuildwheel/discussions/2256 | 
|  | 74 | +          image: tonistiigi/binfmt:qemu-v8.1.5 | 
|  | 75 | + | 
|  | 76 | +      - name: Cache libpq build | 
|  | 77 | +        uses: actions/cache@v4 | 
|  | 78 | +        with: | 
|  | 79 | +          path: /tmp/libpq.build | 
|  | 80 | +          key: libpq-${{ matrix.platform }}-${{ matrix.arch }}-${{ env.LIBPQ_VERSION }}-${{ env.OPENSSL_VERSION }}${{ env.PQ_FLAGS }} | 
|  | 81 | + | 
|  | 82 | +      - name: Build wheels | 
|  | 83 | + | 
|  | 84 | +        env: | 
|  | 85 | +          CIBW_SKIP: "cp31?t-*" | 
|  | 86 | +          CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014 | 
|  | 87 | +          CIBW_MANYLINUX_I686_IMAGE: manylinux2014 | 
|  | 88 | +          CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014 | 
|  | 89 | +          CIBW_MANYLINUX_PPC64LE_IMAGE: manylinux2014 | 
|  | 90 | +          CIBW_MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64 | 
|  | 91 | +          CIBW_BUILD: cp313-${{matrix.platform}}_${{matrix.arch}} | 
|  | 92 | +          CIBW_ARCHS_LINUX: auto aarch64 ppc64le riscv64 | 
|  | 93 | +          CIBW_BEFORE_ALL_LINUX: ./scripts/build/build_libpq.sh | 
|  | 94 | +          CIBW_REPAIR_WHEEL_COMMAND: >- | 
|  | 95 | +            ./scripts/build/strip_wheel.sh {wheel} | 
|  | 96 | +            && auditwheel repair -w {dest_dir} {wheel} | 
|  | 97 | +          CIBW_ENVIRONMENT_PASS_LINUX: LIBPQ_VERSION OPENSSL_VERSION | 
|  | 98 | +          CIBW_ENVIRONMENT: >- | 
|  | 99 | +            LIBPQ_BUILD_PREFIX=/host/tmp/libpq.build | 
|  | 100 | +            PATH="$LIBPQ_BUILD_PREFIX/bin:$PATH" | 
|  | 101 | +            LD_LIBRARY_PATH="$LIBPQ_BUILD_PREFIX/lib:$LIBPQ_BUILD_PREFIX/lib64" | 
|  | 102 | +
 | 
|  | 103 | +
 | 
|  | 104 | +  # }}} | 
|  | 105 | + | 
|  | 106 | +  macos:  # {{{ | 
|  | 107 | +    runs-on: macos-latest | 
|  | 108 | +    if: true | 
|  | 109 | + | 
|  | 110 | +    strategy: | 
|  | 111 | +      fail-fast: false | 
|  | 112 | +      matrix: | 
|  | 113 | +        arch: [x86_64, arm64] | 
|  | 114 | + | 
|  | 115 | +    steps: | 
|  | 116 | +      - name: Checkout repos | 
|  | 117 | +        uses: actions/checkout@v5 | 
|  | 118 | + | 
|  | 119 | +      - name: Cache libpq build | 
|  | 120 | +        uses: actions/cache@v4 | 
|  | 121 | +        with: | 
|  | 122 | +          path: /tmp/libpq.build | 
|  | 123 | +          key: libpq-macos-${{ env.LIBPQ_VERSION }}-${{ matrix.arch }}-${{ env.OPENSSL_VERSION }}${{ env.PQ_FLAGS }} | 
|  | 124 | + | 
|  | 125 | +      - name: Build wheels | 
|  | 126 | + | 
|  | 127 | +        env: | 
|  | 128 | +          CIBW_SKIP: "cp31?t-*" | 
|  | 129 | +          CIBW_BUILD: cp313-macosx_${{matrix.arch}} | 
|  | 130 | +          CIBW_ARCHS_MACOS: ${{matrix.arch}} | 
|  | 131 | +          MACOSX_ARCHITECTURE: ${{matrix.arch}} | 
|  | 132 | +          CIBW_BEFORE_ALL_MACOS: ./scripts/build/build_libpq.sh | 
|  | 133 | +          CIBW_ENVIRONMENT: >- | 
|  | 134 | +            PSYCOPG_IMPL=binary | 
|  | 135 | +            LIBPQ_BUILD_PREFIX=/tmp/libpq.build | 
|  | 136 | +            PATH="$LIBPQ_BUILD_PREFIX/bin:$PATH" | 
|  | 137 | +
 | 
|  | 138 | +  # }}} | 
0 commit comments