Skip to content

Commit

Permalink
Attempt to fix macOS-on-silicon wheel building
Browse files Browse the repository at this point in the history
The wheel produced for arm64 macs is b0rken, as if the shared object was
not properly linked against the static libpg_query.a library.

Try out suggestion found in
https://stackoverflow.com/questions/4597228/how-to-statically-link-a-library-when-compiling-a-python-module-extension,
where the static library if specified in extra_objects instead of a
normal library.
  • Loading branch information
lelit committed Jan 26, 2024
1 parent f152c99 commit 975d02a
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#

from pathlib import Path
import platform
import subprocess
import sys

Expand Down Expand Up @@ -38,6 +39,9 @@ def run(self):
super().run()


is_darwin_arm64 = sys.platform == 'darwin' and platform.mac_ver()[2] == 'arm64'


setup(
name="pglast",
version=VERSION,
Expand Down Expand Up @@ -74,17 +78,20 @@ def run(self):

cmdclass={'build_ext': BuildLibPgQueryFirst},
ext_modules=[
Extension('pglast.parser',
sources=['pglast/parser.c'],
libraries=['pg_query'],
include_dirs=list(
map(str, (LIBPG_QUERY_DIR, VENDOR_DIR, INCLUDE_DIR)
+
((INCLUDE_DIR / 'port' / 'win32',
INCLUDE_DIR / 'port' / 'win32_msvc')
if sys.platform == 'win32'
else ()))),
library_dirs=[str(LIBPG_QUERY_DIR)]),
Extension(
'pglast.parser',
sources=['pglast/parser.c'],
include_dirs=list(
map(str, (LIBPG_QUERY_DIR, VENDOR_DIR, INCLUDE_DIR)
+
((INCLUDE_DIR / 'port' / 'win32',
INCLUDE_DIR / 'port' / 'win32_msvc')
if sys.platform == 'win32'
else ()))),
extra_objects=[str(LIBPG_QUERY_DIR / 'libpg_query.a')] if is_darwin_arm64 else [],
libraries=['pg_query'],
library_dirs=[str(LIBPG_QUERY_DIR)]
),
],

install_requires=[
Expand Down

0 comments on commit 975d02a

Please sign in to comment.