-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·246 lines (204 loc) · 6.7 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import os
import platform
import subprocess
from Cython.Build import cythonize
from setuptools import Extension, find_namespace_packages, setup
# ----------------------------------------------------------------------------
# helper funcs
def getenv(key: str, default: bool = False) -> bool:
"""convert '0','1' env values to bool {True, False}"""
return bool(int(os.getenv(key, default)))
def get_min_osx_ver(platform, arch):
min_osx_ver = os.getenv("MACOSX_DEPLOYMENT_TARGET")
if not min_osx_ver:
min_osx_ver = "10.9"
if platform == "Darwin" and arch == "arm64":
min_osx_ver = "11.0"
return min_osx_ver
# ----------------------------------------------------------------------------
# VARS
VERSION = "0.0.4"
# ----------------------------------------------------------------------------
# OPTIONS (to be set as environment variables)
# set cyfaust static or dynamic build here
STATIC = getenv("STATIC")
# sndfile (+ libsamplerate)
INCLUDE_SNDFILE = getenv("INCLUDE_SNDFILE", default=False)
# rtaudio apis
# linux
ALSA = getenv("ALSA", default=True)
PULSE = getenv("PULSE")
JACK = getenv("JACK")
# windows
ASIO = getenv("ASIO")
WASAPI = getenv("WASAPI", default=True)
DSOUND = getenv("DSOUND")
# ----------------------------------------------------------------------------
# COMMON
PLATFORM = platform.system()
ARCH = platform.machine()
CWD = os.getcwd()
# local directories
LIB = os.path.join(CWD, "lib")
INCLUDE = os.path.join(CWD, "include")
# common configuration
INCLUDE_DIRS = [INCLUDE]
LIBRARY_DIRS = [LIB]
EXTRA_OBJECTS = []
EXTRA_LINK_ARGS = []
LIBRARIES = []
DEFINE_MACROS = [("INTERP_DSP", 1)]
EXTRA_COMPILE_ARGS = []
RTAUDIO_SRC = [
"include/rtaudio/RtAudio.cpp",
"include/rtaudio/rtaudio_c.cpp",
]
# ----------------------------------------------------------------------------
# CONDITIONAL CONFIGURATION
if STATIC:
if PLATFORM == "Windows":
EXTRA_OBJECTS.append("lib/static/libfaust.lib")
EXTRA_OBJECTS.extend([
"Ws2_32.lib",
])
else:
EXTRA_OBJECTS.append("lib/static/libfaust.a")
else:
LIBRARIES.append("faust")
if PLATFORM in ["Linux", "Darwin"]:
EXTRA_LINK_ARGS.append("-Wl,-rpath," + LIB) # add local rpath
if INCLUDE_SNDFILE:
DEFINE_MACROS.append(("INCLUDE_SNDFILE", 1))
EXTRA_OBJECTS.extend(
[
"lib/static/libsndfile.a",
"lib/static/libsamplerate.a",
]
)
# platform specific configuration
if PLATFORM in ["Darwin", "Linux"]:
LIBRARIES.append("pthread")
if PLATFORM == "Darwin":
MIN_OSX_VER = get_min_osx_ver(PLATFORM, ARCH)
os.environ["MACOSX_DEPLOYMENT_TARGET"] = MIN_OSX_VER
EXTRA_COMPILE_ARGS.extend(["-std=c++11", "-stdlib=libc++"])
EXTRA_LINK_ARGS.append(f"-mmacosx-version-min={MIN_OSX_VER}")
DEFINE_MACROS.append(("__MACOSX_CORE__", None)) # rtaudio for macos
if JACK:
DEFINE_MACROS.append(("__UNIX_JACK__", None))
LIBRARIES.append("jack")
os.environ["LDFLAGS"] = " ".join(
["-framework CoreFoundation", "-framework CoreAudio"]
)
elif PLATFORM == "Linux":
os.environ["CPPFLAGS"] = "-include limits"
EXTRA_COMPILE_ARGS.append("-std=c++11")
if ALSA:
DEFINE_MACROS.append(("__LINUX_ALSA__", None))
LIBRARIES.append("asound")
if PULSE:
DEFINE_MACROS.append(("__LINUX_PULSE__", None))
LIBRARIES.append("pulse")
if JACK:
DEFINE_MACROS.append(("__UNIX_JACK__", None))
LIBRARIES.append("jack")
elif PLATFORM == "Windows":
LIBRARIES.extend([
"winmm",
"ole32",
])
if ASIO:
DEFINE_MACROS.append(("__WINDOWS_ASIO__", None))
RTAUDIO_SRC.extend([
"include/rtaudio/asio/asio.cpp",
"include/rtaudio/asio/asiodrivers.cpp",
"include/rtaudio/asio/asiolist.cpp",
"include/rtaudio/asio/iasiothiscallresolver.cpp",
])
if WASAPI:
DEFINE_MACROS.append(("__WINDOWS_WASAPI__", None))
LIBRARIES.extend([
"ksuser",
"mfplat",
"mfuuid",
"wmcodecdspuuid",
])
if DSOUND:
DEFINE_MACROS.append(("__WINDOWS_DS__", None))
LIBRARIES.append("dsound")
else:
raise SystemExit(f"platform '{PLATFORM}' not currently supported")
def mk_extension(name, sources, define_macros=None):
return Extension(
name=name,
sources=sources,
define_macros=define_macros if define_macros else [],
include_dirs=INCLUDE_DIRS,
libraries=LIBRARIES,
library_dirs=LIBRARY_DIRS,
extra_objects=EXTRA_OBJECTS,
extra_compile_args=EXTRA_COMPILE_ARGS,
extra_link_args=EXTRA_LINK_ARGS,
language="c++",
)
# ----------------------------------------------------------------------------
# COMMON SETUP CONFIG
common = {
"name": "cyfaust",
"version": VERSION,
"description": "A cython wrapper of the faust interpreter with rtaudio.",
"python_requires": ">=3.8",
"include_package_data": True,
}
# ----------------------------------------------------------------------------
# STATIC BUILD VARIANT
if STATIC:
# forces cythonize in this case
subprocess.call("cythonize cyfaust.pyx", cwd="src/static/cyfaust", shell=True)
with open("MANIFEST.in", "w") as f:
f.write("graft src/static/cyfaust/resources\n")
f.write("exclude src/static/cyfaust/*.cpp\n")
extensions = [
mk_extension(
"cyfaust.cyfaust",
sources=["src/static/cyfaust/cyfaust.pyx"] + RTAUDIO_SRC,
define_macros=DEFINE_MACROS,
),
]
setup(
**common,
ext_modules=cythonize(
extensions,
language_level="3str",
),
package_dir={"": "src/static"},
packages=find_namespace_packages(
where="src/static",
include=["cyfaust*"],
),
)
# ----------------------------------------------------------------------------
# DEFAULT DYNAMIC BUILD VARIANT
else:
with open("MANIFEST.in", "w") as f:
f.write("graft src/cyfaust/resources\n")
f.write("exclude src/cyfaust/*.cpp\n")
extensions = [
mk_extension(
"cyfaust.interp",
sources=["src/cyfaust/interp.pyx"] + RTAUDIO_SRC,
define_macros=DEFINE_MACROS,
),
mk_extension("cyfaust.common", ["src/cyfaust/common.pyx"]),
mk_extension("cyfaust.signal", ["src/cyfaust/signal.pyx"]),
mk_extension("cyfaust.box", ["src/cyfaust/box.pyx"]),
]
setup(
**common,
ext_modules=cythonize(
extensions,
language_level="3str",
),
package_dir={"": "src"},
packages=find_namespace_packages(where="src", include=["cyfaust*"]),
)