Skip to content

Commit

Permalink
fix macox build
Browse files Browse the repository at this point in the history
  • Loading branch information
synodriver committed Aug 12, 2022
1 parent 8bde56c commit d351b35
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pyopenjtalk/htsengine.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ cdef class HTSEngine:
cdef size_t nsamples = HTS_Engine_get_nsamples(self.engine)
cdef np.ndarray[np.float64_t, ndim=1] speech = np.zeros([nsamples], dtype=np.float64)
cdef double[::1] speech_view = speech
cdef size_t index
cdef int index
for index in prange(nsamples, nogil=True):
speech_view[index] = HTS_Engine_get_generated_speech(self.engine, index)
speech_view[index] = HTS_Engine_get_generated_speech(self.engine, <size_t>index)
return speech

cpdef inline str get_fullcontext_label_format(self):
Expand Down
2 changes: 1 addition & 1 deletion pyopenjtalk/openjtalk.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8
# cython: language_level=3
# cython: boundscheck=False, wraparound=False
# cython: boundscheck=False, wraparound=True
# cython: c_string_type=unicode, c_string_encoding=ascii, cdivision=True

from libc.stdint cimport uint8_t
Expand Down
27 changes: 23 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
import platform
from distutils.errors import DistutilsExecError
from distutils.spawn import spawn
from distutils.version import LooseVersion
Expand Down Expand Up @@ -70,6 +71,24 @@ def build_extensions(self):
if not os.path.exists(join("pyopenjtalk", "openjtalk" + ext)):
raise RuntimeError("Cython is required to generate C++ code")

# make openmp available
system = platform.system()
if system == "Windows":
extra_compile_args = []
extra_link_args = ['/openmp']
elif system == "Linux":
extra_compile_args = ['-fopenmp']
extra_link_args = ['-fopenmp']
elif system == "Darwin":
os.system("brew install llvm libomp")
os.system("brew install clang-omp")
# os.environ["CPP"] = "/usr/local/opt/llvm/bin/clang"
extra_compile_args = ["-Xpreprocessor", "-fopenmp"]
extra_link_args = ["-Xpreprocessor", "-fopenmp"]
else:
extra_compile_args = ['-fopenmp']
extra_link_args = ['-fopenmp']


# Workaround for `distutils.spawn` problem on Windows python < 3.9
# See details: [bpo-39763: distutils.spawn now uses subprocess (GH-18743)]
Expand Down Expand Up @@ -180,8 +199,8 @@ def escape_macros(macros):
name="pyopenjtalk.openjtalk",
sources=[join("pyopenjtalk", "openjtalk" + ext)] + all_src,
include_dirs=[np.get_include()] + include_dirs,
extra_compile_args=['-fopenmp'],
extra_link_args=['-fopenmp'],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
language="c++",
define_macros=custom_define_macros(
[
Expand All @@ -204,8 +223,8 @@ def escape_macros(macros):
name="pyopenjtalk.htsengine",
sources=[join("pyopenjtalk", "htsengine" + ext)] + all_htsengine_src,
include_dirs=[np.get_include(), join(htsengine_src_top, "include")],
extra_compile_args=['-fopenmp'],
extra_link_args=['-fopenmp'],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
libraries=["winmm"] if platform_is_windows else [],
language="c++",
define_macros=custom_define_macros(
Expand Down

0 comments on commit d351b35

Please sign in to comment.