Skip to content

Commit d0bc154

Browse files
bwoodsenddvarrazzo
authored andcommitted
build(macos): Enable cross compiling libpq across macOS architectures
The GitHub Actions runners look like they're only 1 year away from the last macOS x86_64 platform being removed. Get ahead of the game and build x86_64 on arm64.
1 parent 1eac4fd commit d0bc154

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

.github/workflows/packages.yml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,15 @@ jobs:
132132
# }}}
133133

134134
macos: # {{{
135-
runs-on: macos-${{ matrix.macver }}
135+
runs-on: macos-latest
136136
if: true
137137

138138
strategy:
139139
fail-fast: false
140140
matrix:
141141
# These archs require an Apple M1 runner: [arm64, universal2]
142-
arch: [x86_64]
142+
arch: [x86_64, arm64]
143143
pyver: [cp39, cp310, cp311, cp312, cp313]
144-
macver: ["13"]
145-
include:
146-
- arch: arm64
147-
pyver: cp310
148-
macver: "14"
149-
- arch: arm64
150-
pyver: cp311
151-
macver: "14"
152-
- arch: arm64
153-
pyver: cp312
154-
macver: "14"
155-
- arch: arm64
156-
pyver: cp313
157-
macver: "14"
158144

159145
steps:
160146
- name: Checkout repos
@@ -171,6 +157,7 @@ jobs:
171157
env:
172158
CIBW_BUILD: ${{matrix.pyver}}-macosx_${{matrix.arch}}
173159
CIBW_ARCHS_MACOS: ${{matrix.arch}}
160+
MACOSX_ARCHITECTURE: ${{matrix.arch}}
174161
CIBW_BEFORE_ALL_MACOS: ./scripts/build/wheel_macos_before_all.sh
175162
CIBW_TEST_COMMAND: >-
176163
export PYTHONPATH={project} &&
@@ -184,7 +171,7 @@ jobs:
184171
- name: Upload artifacts
185172
uses: actions/upload-artifact@v4
186173
with:
187-
name: macos-${{matrix.pyver}}-macos-${{matrix.macver}}_${{matrix.arch}}
174+
name: macos-${{matrix.pyver}}-macos-${{matrix.arch}}
188175
path: ./wheelhouse/*.whl
189176

190177
# }}}

scripts/build/build_libpq.sh

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ case "$ID" in
6868
# it, force use of system curl.
6969
brew uninstall --force --ignore-dependencies openssl gettext
7070
curl="/usr/bin/curl"
71-
# The deployment target should be <= to that of the oldest supported Python version.
71+
if [ -z "$MACOSX_ARCHITECTURE" ]; then
72+
MACOSX_ARCHITECTURE="$(uname -m)"
73+
fi
74+
# Set the deployment target to be <= to that of the oldest supported Python version.
7275
# e.g. https://www.python.org/downloads/release/python-380/
73-
if [ "$(uname -m)" == "x86_64" ]; then
76+
if [ "$MACOSX_ARCHITECTURE" == "x86_64" ]; then
7477
export MACOSX_DEPLOYMENT_TARGET=10.9
7578
else
7679
export MACOSX_DEPLOYMENT_TARGET=11.0
@@ -83,6 +86,22 @@ case "$ID" in
8386
;;
8487
esac
8588

89+
90+
if [ "$ID" == "macos" ]; then
91+
make_configure_standard_flags=( \
92+
--prefix=${LIBPQ_BUILD_PREFIX} \
93+
"CPPFLAGS=-I${LIBPQ_BUILD_PREFIX}/include/ -arch $MACOSX_ARCHITECTURE" \
94+
"LDFLAGS=-L${LIBPQ_BUILD_PREFIX}/lib -arch $MACOSX_ARCHITECTURE" \
95+
)
96+
else
97+
make_configure_standard_flags=( \
98+
--prefix=${LIBPQ_BUILD_PREFIX} \
99+
CPPFLAGS=-I${LIBPQ_BUILD_PREFIX}/include/ \
100+
LDFLAGS=-L${LIBPQ_BUILD_PREFIX}/lib \
101+
)
102+
fi
103+
104+
86105
if [ "$ID" == "centos" ] || [ "$ID" == "macos" ]; then
87106

88107
# Build openssl if needed
@@ -94,8 +113,14 @@ if [ "$ID" == "centos" ] || [ "$ID" == "macos" ]; then
94113

95114
cd "${openssl_dir}"
96115

97-
./config --prefix=${LIBPQ_BUILD_PREFIX} --openssldir=${LIBPQ_BUILD_PREFIX} \
98-
zlib -fPIC shared
116+
options=(--prefix=${LIBPQ_BUILD_PREFIX} --openssldir=${LIBPQ_BUILD_PREFIX} \
117+
zlib -fPIC shared)
118+
if [ -z "$MACOSX_ARCHITECTURE" ]; then
119+
./config $options
120+
else
121+
./configure "darwin64-$MACOSX_ARCHITECTURE-cc" $options
122+
fi
123+
99124
make depend
100125
make
101126
else
@@ -119,9 +144,7 @@ if [ "$ID" == "macos" ]; then
119144
| tar xzf -
120145

121146
cd "${krb5_dir}"
122-
123-
./configure --prefix=${LIBPQ_BUILD_PREFIX} \
124-
CPPFLAGS=-I${LIBPQ_BUILD_PREFIX}/include/ LDFLAGS=-L${LIBPQ_BUILD_PREFIX}/lib
147+
./configure "${make_configure_standard_flags[@]}"
125148
make
126149
else
127150
cd "${krb5_dir}"
@@ -143,9 +166,7 @@ if [ "$ID" == "macos" ]; then
143166
| tar xzf -
144167

145168
cd "${gettext_dir}"
146-
147-
./configure --prefix=${LIBPQ_BUILD_PREFIX} --disable-java \
148-
CPPFLAGS=-I${LIBPQ_BUILD_PREFIX}/include/ LDFLAGS=-L${LIBPQ_BUILD_PREFIX}/lib
169+
./configure --disable-java "${make_configure_standard_flags[@]}"
149170
make -C gettext-runtime all
150171
else
151172
cd "${gettext_dir}"
@@ -173,8 +194,7 @@ if [ "$ID" == "centos" ] || [ "$ID" == "macos" ]; then
173194
cd "${sasl_dir}"
174195

175196
autoreconf -i
176-
./configure --prefix=${LIBPQ_BUILD_PREFIX} --disable-macos-framework \
177-
CPPFLAGS=-I${LIBPQ_BUILD_PREFIX}/include/ LDFLAGS=-L${LIBPQ_BUILD_PREFIX}/lib
197+
./configure "${make_configure_standard_flags[@]}" --disable-macos-framework
178198
make
179199
else
180200
cd "${sasl_dir}"
@@ -201,8 +221,7 @@ if [ "$ID" == "centos" ] || [ "$ID" == "macos" ]; then
201221

202222
cd "${ldap_dir}"
203223

204-
./configure --prefix=${LIBPQ_BUILD_PREFIX} --enable-backends=no --enable-null \
205-
CPPFLAGS=-I${LIBPQ_BUILD_PREFIX}/include/ LDFLAGS=-L${LIBPQ_BUILD_PREFIX}/lib
224+
./configure "${make_configure_standard_flags[@]}" --enable-backends=no --enable-null
206225

207226
make depend
208227
make -C libraries/liblutil/
@@ -243,10 +262,9 @@ if [ ! -d "${postgres_dir}" ]; then
243262
# Often needed, but currently set by the workflow
244263
# export LD_LIBRARY_PATH="${LIBPQ_BUILD_PREFIX}/lib"
245264

246-
./configure --prefix=${LIBPQ_BUILD_PREFIX} --sysconfdir=/etc/postgresql-common \
265+
./configure "${make_configure_standard_flags[@]}" --sysconfdir=/etc/postgresql-common \
247266
--with-gssapi --with-openssl --with-pam --with-ldap \
248-
--without-readline --without-icu \
249-
CPPFLAGS=-I${LIBPQ_BUILD_PREFIX}/include/ LDFLAGS=-L${LIBPQ_BUILD_PREFIX}/lib
267+
--without-readline --without-icu
250268
make -C src/interfaces/libpq
251269
make -C src/bin/pg_config
252270
make -C src/include

0 commit comments

Comments
 (0)