]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
build: add scripts to build macOS arm64 packages
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 16 Jul 2022 18:50:45 +0000 (19:50 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 28 Jul 2022 11:14:42 +0000 (13:14 +0200)
.github/workflows/packages.yml
.gitignore
tools/build/build_macos_arm64.sh [new file with mode: 0755]
tools/build/run_build_macos_arm64.sh [new file with mode: 0755]

index 5d28fc567c53dfd4dac98a8d247966ab73f1c8b7..eb3df97c8a83571f32e2bb94586339c1e52a769e 100644 (file)
@@ -175,7 +175,7 @@ jobs:
           package-dir: psycopg_binary
         env:
           CIBW_BUILD: ${{matrix.pyver}}-macosx_${{matrix.arch}}
-          CIBW_ARCHS_MACOS: x86_64 arm64 universal2
+          CIBW_ARCHS_MACOS: x86_64
           CIBW_BEFORE_ALL_MACOS: ./tools/build/wheel_macos_before_all.sh
           CIBW_TEST_REQUIRES: ./psycopg[test] ./psycopg_pool
           CIBW_TEST_COMMAND: pytest {project}/tests -m 'not slow' --color yes
index c16890583c670abe4a26c14b42fc1fe5fc31c21d..2d8c58c3a983293c3e160bd8b6cd9fe72ce18c04 100644 (file)
@@ -1,6 +1,7 @@
 *.egg-info/
 .tox
 *.pstats
+*.swp
 .mypy_cache
 __pycache__/
 /docs/_build/
@@ -13,6 +14,7 @@ htmlcov
 
 .eggs/
 dist/
+wheelhouse/
 # Spelling these explicitly because we have /scripts/build/ to not ignore
 # but I still want 'ag' to avoid looking here.
 /build/
diff --git a/tools/build/build_macos_arm64.sh b/tools/build/build_macos_arm64.sh
new file mode 100755 (executable)
index 0000000..724ab9b
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+# Build psycopg-binary wheel packages for Apple M1 (cpNNN-macosx_arm64)
+#
+# This script is designed to run on Scaleway Apple Silicon machines.
+#
+# The script cannot be run as sudo (installing brew fails), but requires sudo,
+# so it can pretty much only be executed by a sudo user as it is.
+
+set -euo pipefail
+set -x
+
+python_versions="3.8.10 3.9.13 3.10.5"
+postgres_version=14
+
+# Move to the root of the project
+dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+cd "${dir}/../../"
+
+# Add /usr/local/bin to the path. It seems it's not, in non-interactive sessions
+if ! (echo $PATH | grep -q '/usr/local/bin'); then
+    export PATH=/usr/local/bin:$PATH
+fi
+
+# Install brew, if necessary. Otherwise just make sure it's in the path
+if [[ -x /opt/homebrew/bin/brew ]]; then
+    eval "$(/opt/homebrew/bin/brew shellenv)"
+else
+    command -v brew > /dev/null || (
+        # Not necessary: already installed
+        # xcode-select --install
+        NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL \
+            https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
+    )
+    eval "$(/opt/homebrew/bin/brew shellenv)"
+fi
+
+# Install PostgreSQL, if necessary
+command -v pg_config > /dev/null || (
+    brew install postgresql@${postgres_version}
+    brew services start postgresql
+)
+
+# Install the Python versions we want to build
+for ver3 in $python_versions; do
+    ver2=$(echo $ver3 | sed 's/\([^\.]*\)\(\.[^\.]*\)\(.*\)/\1\2/')
+    command -v python${ver2} > /dev/null || (
+        (cd /tmp &&
+            curl -fsSl -O \
+                https://www.python.org/ftp/python/${ver3}/python-${ver3}-macos11.pkg)
+        sudo installer -pkg /tmp/python-${ver3}-macos11.pkg -target /
+    )
+done
+
+# Create a virtualenv where to work
+if [[ ! -x .venv/bin/python ]]; then
+    python3 -m venv .venv
+fi
+
+source .venv/bin/activate
+pip install cibuildwheel
+
+# Create the psycopg_binary source package
+rm -rf psycopg_binary
+python tools/build/copy_to_binary.py
+
+# Build the binary packages
+export CIBW_PLATFORM=macos
+export CIBW_ARCHS=arm64
+export CIBW_BUILD='cp{38,39,310}-*'
+export CIBW_TEST_REQUIRES="./psycopg[test] ./psycopg_pool"
+export CIBW_TEST_COMMAND="pytest {project}/tests -m 'not slow and not flakey' --color yes"
+
+export PSYCOPG_IMPL=binary
+export PSYCOPG_TEST_DSN="dbname=postgres"
+export PSYCOPG_TEST_WANT_LIBPQ_BUILD=">= ${postgres_version}"
+export PSYCOPG_TEST_WANT_LIBPQ_IMPORT=">= ${postgres_version}"
+
+cibuildwheel psycopg_binary
diff --git a/tools/build/run_build_macos_arm64.sh b/tools/build/run_build_macos_arm64.sh
new file mode 100755 (executable)
index 0000000..f5ae617
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+# Build psycopg-binary wheel packages for Apple M1 (cpNNN-macosx_arm64)
+#
+# This script is designed to run on a local machine: it will clone the repos
+# remotely and execute the `build_macos_arm64.sh` script remotely, then will
+# download the built packages. A tag to build must be specified.
+#
+# In order to run the script, the `m1` host must be specified in
+# `~/.ssh/config`; for instance:
+#
+#   Host m1
+#     User m1
+#     HostName 1.2.3.4
+
+set -euo pipefail
+# set -x
+
+tag=${1:-}
+
+if [[ ! "${tag}" ]]; then
+    echo "Usage: $0 TAG" >&2
+    exit 2
+fi
+
+rdir=psycobuild
+
+# Clone the repos
+ssh m1 rm -rf "${rdir}"
+ssh m1 git clone https://github.com/psycopg/psycopg.git --branch ${tag} "${rdir}"
+
+# Allow sudoing without password, to allow brew to install
+ssh -t m1 bash -c \
+    'test -f /etc/sudoers.d/m1 || echo "m1 ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/m1'
+
+# Build the wheel packages
+ssh m1 "${rdir}/tools/build/build_macos_arm64.sh"
+
+# Transfer the packages locally
+scp -r "m1:${rdir}/wheelhouse" .