Skip to content

Commit

Permalink
Find libsndfile.dylib on Apple M1
Browse files Browse the repository at this point in the history
Homebrew on Apple M1 uses a `/opt/homebrew/lib` instead of `/usr/local/lib`.
We are making sure we pick that up.
  • Loading branch information
panosl committed Sep 15, 2021
1 parent 744efb4 commit 008503e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions soundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import os as _os
import sys as _sys
from platform import machine as _machine
from os import SEEK_SET, SEEK_CUR, SEEK_END
from ctypes.util import find_library as _find_library
from _soundfile import ffi as _ffi
Expand Down Expand Up @@ -159,8 +160,16 @@
while not _os.path.isdir(_path):
_path = _os.path.abspath(_os.path.join(_path, '..'))

_snd = _ffi.dlopen(_os.path.join(
_path, '_soundfile_data', _libname))
# Homebrew on Apple M1 uses a `/opt/homebrew/lib` instead of
# `/usr/local/lib`. We are making sure we pick that up.
if _sys.platform == 'darwin' and _machine() == 'arm64':
_hbrew_path = '/opt/homebrew/lib/' if _os.path.isdir('/opt/homebrew/lib/') \
else '/usr/local/lib/'
_snd = _ffi.dlopen(_os.path.join(
_hbrew_path, _libname))
else:
_snd = _ffi.dlopen(_os.path.join(
_path, '_soundfile_data', _libname))

__libsndfile_version__ = _ffi.string(_snd.sf_version_string()).decode('utf-8', 'replace')
if __libsndfile_version__.startswith('libsndfile-'):
Expand Down

0 comments on commit 008503e

Please sign in to comment.