Skip to content

Commit ff5444a

Browse files
committed
Use build_ext instead of install/develop, fix rpath for Linux
1 parent 04aa710 commit ff5444a

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

setup.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import os
22
import platform
33
from setuptools import setup
4-
from setuptools.command.develop import develop
5-
from setuptools.command.install import install
4+
from setuptools.command.build_ext import build_ext
65

76
# "import" __version__
87
__version__ = 'unknown'
@@ -38,6 +37,16 @@
3837
package_data = None
3938
zip_safe = True
4039

40+
41+
def post_install():
42+
if system == 'Darwin':
43+
# Bizarrely, on macOS, there doesn't seem to be another way to do this: you MUST use install_name_tool
44+
import subprocess
45+
# It could be either of these, so try both
46+
subprocess.run(["install_name_tool", "-change", "/usr/local/lib/libportaudio.dylib", "@rpath/libportaudio.dylib", "./_sounddevice.abi3.so"])
47+
subprocess.run(["install_name_tool", "-change", "/usr/local/lib/libportaudio.2.dylib", "@rpath/libportaudio.dylib", "./_sounddevice.abi3.so"])
48+
49+
4150
try:
4251
from wheel.bdist_wheel import bdist_wheel
4352
except ImportError:
@@ -60,32 +69,16 @@ def get_tag(self):
6069

6170
cmdclass = {'bdist_wheel': bdist_wheel_half_pure}
6271

63-
def post_install():
64-
if system == 'Darwin':
65-
# Bizarrely, on macOS, there doesn't seem to be another way to do this: you MUST use install_name_tool
66-
import subprocess
67-
# It could be either of these, so try both
68-
subprocess.run(["install_name_tool", "-change", "/usr/local/lib/libportaudio.dylib", "@rpath/libportaudio.dylib", "./_sounddevice.abi3.so"])
69-
subprocess.run(["install_name_tool", "-change", "/usr/local/lib/libportaudio.2.dylib", "@rpath/libportaudio.dylib", "./_sounddevice.abi3.so"])
7072

71-
class PostDevelopCommand(develop):
73+
class PostBuildCommand(build_ext):
7274
"""Post-installation for development mode."""
7375

7476
def run(self):
75-
develop.run(self)
76-
post_install()
77-
78-
79-
class PostInstallCommand(install):
80-
"""Post-installation for installation mode."""
81-
82-
def run(self):
83-
install.run(self)
77+
build_ext.run(self)
8478
post_install()
8579

8680

87-
cmdclass['develop'] = PostDevelopCommand
88-
cmdclass['install'] = PostInstallCommand
81+
cmdclass['build_ext'] = PostBuildCommand
8982

9083

9184
setup(

sounddevice_build.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,26 @@
33
import platform as _platform
44

55
extra_header_files = ""
6+
extra_link_args = []
67

78
if _platform.system() == 'Darwin':
89
extra_header_files = """
910
#include "pa_mac_core.h"
1011
"""
12+
extra_link_args = ["-Wl,-rpath,@loader_path/_sounddevice_data/portaudio-binaries"]
1113
elif _platform.system() == 'Windows':
1214
extra_header_files = """
1315
#include "pa_win_waveformat.h"
1416
#include "pa_asio.h"
1517
#include "pa_win_wasapi.h"
1618
"""
19+
# TODO: how to do RPATH on Windows?
20+
elif _platform.system() == 'Linux':
21+
extra_header_files = """
22+
#include "pa_linux_alsa.h"
23+
"""
24+
extra_link_args = ["-Wl,-rpath,$ORIGIN/_sounddevice_data/portaudio-binaries"]
25+
1726

1827
ffibuilder = FFI()
1928
ffibuilder.set_source(
@@ -26,7 +35,7 @@
2635
include_dirs=["./include"],
2736
libraries=["portaudio"],
2837
library_dirs=["./_sounddevice_data/portaudio-binaries"],
29-
extra_link_args=["-Wl,-rpath,@loader_path/_sounddevice_data/portaudio-binaries"]
38+
extra_link_args=extra_link_args
3039
)
3140

3241
ffibuilder.cdef("""

0 commit comments

Comments
 (0)